Prompt as code is a programming paradigm based on multiple input modalities, which provides richer contextual information by combining text, images, voice, and other input methods to help programmers better express their intentions and generate corresponding code implementations.
Prompt as code incorporates prompts as part of the code and defines the generated code as a standard interface while providing comments and documentation to support readability and maintainability. By using prompt as code, programmers can improve coding efficiency while generating more accurate and reliable code implementations.
In the previous two AI programming articles, “Incremental AI Programming Model: Design Ideas and Exploration of Unit Mesh Architecture” and “The Promising Future of AI Programming: Ultimate Liberation for Programmers or the Beginning of Unemployment?” we have discussed the impact of AI programming in the coming years.
Without considering adopting new architectures like Unit Mesh, we need to integrate AI programming into existing architectures and engineering systems. Therefore, in this article, we will return to the present—how should we coexist with AI programming and let AI be our Copilot?
Intro 1: A Year Using GitHub Copilot: 20% Efficiency Boost
Relevant examples can be found at: https://www.clickprompt.org/zh-CN/github-copilot-samples/
Since GitHub Copilot was officially released, as a well-known open-source project creator, I got the free version but could only use it secretly. The company explicitly prohibits us from using it in company projects, so I can only use it in personal projects and open-source projects.
From my personal experience, AI has probably improved my coding efficiency by about 20%—mostly because the code I write tends to be niche. But how should I put it, the quality of the code generated by copying, forking, and generating is just terrible (I might be a fan of Clean Code), so I often complain that you can’t train a good model in a garbage repository.
In short, the efficiency boost is significant, especially for CRUD operations, but the quality is lacking. Anyway, rewriting is faster than refactoring, and code quality doesn’t matter (manual dog head).
Additionally, from my personal experience, writing the prompts required for Copilot has a learning curve.
Intro 2: The Threshold of AI Programming
Back to the real world, what should we consider to effectively use AI coding?
Question 1: Can AI Programming Replace Human Programming?
Whether it’s the demo from the GPT-4 launch or the impressive Cursor.so development tool, it’s too early to talk about the disappearance of programming given the current capabilities of GPT. GPT is just a parrot that cannot solve any complex programming problems. In complex scenarios, GPT easily loses some conditions, requiring humans to handle the tasking process.
In conditions that are insufficient, you can easily let AI generate a page or a function, but it cannot achieve the results you want. Therefore, under the Unit Mesh architecture, some programmers have become AI code verifiers + AI code repairers, and this will continue for a long time.
Question 2: Is Programming Just Coding?
Current AI programming only replaces your translation process: breaking down requirements, converting requirements into code, etc. You can look at your commit history: how many lines of code did you submit in a day, and at what time? You might find that you were in meetings all day, only coding at night. I remember a related question on Zhihu, where most people’s answers were an average of dozens or hundreds of lines. Of course, counting lines is unscientific; the line count of a growing project is much greater than that of a maintenance phase.
So, if your coding time is long while the time spent on architectural design and requirement discussions is short, you might need to reconsider your career and strengthen your design and decomposition skills. After all, once efficiency increases, some programmers will inevitably face unemployment.
Question 3: Can Everyone Write Good Prompts?
Being part of various WeChat groups accessible to ChatGPT, I often throw out the phrase, “Ask ChatGPT.” Many people do not truly realize that ChatGPT is a tool; the only fun might be: “Please help me generate a story for KFC v50.”
This is also the original intention behind creating projects like ClickPrompt, ChatFlow, and PromptPatterns; most people need to first realize what AI can do. Then, it’s about how to write good prompts, getting to know our Copilot’s temperament, and then working together, such as:
-
Generating code directly from function names.
-
Generating code from function names + processing steps.
Each mode behind this is quite interesting.
Prompt as Code: A New Specification—Prompt Writing Standards
Before further elaborating on prompt as code, we need to understand how to write good prompts. Below is a part of the GitHub Copilot examples I previously posted on ClickPrompt.
-
Function Definition: Define the required functionality and provide the model with sufficient context and information. This can help the model better understand its intentions and generate corresponding code. Example 1: With the function name, inputs, and outputs, it can auto-fill.
-
Task Decomposition: Break tasks into smaller sub-tasks and ensure that the requirements and expected outputs of each sub-task are very clear. Example 2: As shown in the step-by-step design example above, each step needs to be well thought out.
-
Determine Input and Output Formats: The prompt standard should clearly specify the input and output formats and data types so that the model can correctly process the input. Example 3: We added i18n json to let Copilot automatically map.
-
Testing and Debugging: After generating code, it should be tested and debugged to ensure its correctness and reliability. At the same time, feedback should be provided to the model to help it improve its generated code. Example: Letting Copilot write corresponding unit tests, we check the test cases.
-
Avoid Ambiguity: The prompt standard should avoid using ambiguous language and terms, ensuring that the generated code is consistent across various contexts. We only realize this principle’s usefulness when errors occur.
-
Coding Standards: Define coding standards and ensure that the generated code complies with these standards. This can ensure that the generated code is easy to read and maintain and aligns with the team’s coding practices. This needs to be done by our team.
Doesn’t it look a lot like the pseudocode you usually write? As a pseudocode engineer, don’t you find that productivity might explode?
Prompt as Code: AI Programming in Different Forms
To reiterate the definition:
Prompt as code is a programming paradigm based on multiple input modalities, which provides richer contextual information by combining text, images, voice, and other input methods to help programmers better express their intentions and generate corresponding code implementations. Prompt as code incorporates prompts as part of the code and defines the generated code as a standard interface while providing comments and documentation to support readability and maintainability. By using prompt as code, programmers can improve coding efficiency while generating more accurate and reliable code implementations.
When talking about prompt as code, we typically define it as a programming paradigm that uses natural language or other forms of input as the starting point for code generation. Prompt as code allows programmers to describe the functionality they want through a highly abstract natural language description or other forms of input, with the AI system automatically generating the code.
Thus, we can divide it into two approaches: standard prompt as code and multimodal prompt as code.
Standard Prompt as Code: Text Form
Text prompt as code refers to using natural language or other means to describe requirements or problems, allowing the AI model to automatically generate corresponding code. The prompt serves as part or the core of the code by describing the expected inputs and outputs, as well as the operations to be performed to generate code.
Although existing AI tools are multimodal, natural language exists as an intermediate language. Therefore, I would like to refer to the text form of the prompt as standard prompt as code, which can be conveniently integrated into existing programming systems.
-
Prompt as Comments. The prompt coexists with the code; in this case, the prompt and code reside in the same file. Typically, prompts appear in the code as comments, providing necessary contextual information and instructions for code generation. This method is suitable for scenarios where the generated code needs frequent manual modifications.
-
Prompt as Interface. In this case, the prompt serves as a standard interface, and the code is the generated implementation of this interface. This method is suitable for scenarios that require automated testing and deployment of the generated code, as the consistency of interface definitions can better ensure the correctness of the code.
-
Prompt as Code. In this case, the version control system no longer stores the code but stores the prompt instead. The generated code can be created based on the prompt, with the prompt as part of the code. This method is suitable for scenarios that require frequent updates to the code and version control of the code.
In fact, when I first incorporated comments into ClickPrompt, I hesitated for a long time. Our past programming habits did not allow us to include the thought process as comments.
Multimodal Prompt as Code
PS: Thanks to ChatGPT for helping me consider this part.
Multimodal prompt as code refers to the simultaneous use of various input modes (such as text, images, and speech) during the training of AI models to provide richer context, helping the model better understand the programmer’s intentions and generate corresponding code. By using multimodal prompts, AI models can obtain more information and more accurately reflect the programmer’s intentions when generating code.
For instance, an AI model trained with multimodal prompts can simultaneously consider code snippets input by the programmer in textual context, project information, data structure information, and image information provided by the programmer, such as diagrams and flowcharts, thereby generating more accurate and complete code.
PS: However, this technology requires a large amount of data and computational resources, and it also needs to process and integrate different input modes. Therefore, further research and optimization are needed for practical applications.
Prompt as Code: Changes in Interaction Methods
In recent months, the continuous emergence of new AI tools has made us feel the upper limit of human IQ and the lower limit of AI. Compared to current programming methods, new or already existing interaction methods will inevitably appear in the coming months.
Such as:
-
Interactive Prompts: During the coding process, the model can prompt the programmer for input, helping the model better understand the programmer’s intentions and generate more accurate code. For example, the architecture model used by Unit Mesh is completed collaboratively by humans and AI, and automatically deployed by Unit Server.
-
Scenario-based Prompts: By providing information and context relevant to specific scenarios, the model can better understand the programmer’s intentions and generate corresponding code. For example, prompts for web development may include information and context related to HTML, CSS, and JavaScript.
-
And so on.
The interaction methods of prompt as code will become increasingly diverse and intelligent to better meet programmers’ needs in different fields and scenarios.
Conclusion
PS: Finally, let ChatGPT 3.5 summarize the latter part of this article (after all, 4K Unit).
This article introduces the writing methods of prompt as code, the utilization of multimodal inputs, and the ways AI models generate code. Good prompt standards include function definitions, task breakdowns, input and output formats, testing and debugging, avoiding ambiguity, and coding standards. Text-based prompts can use natural language or other means to describe requirements or problems, allowing AI models to automatically generate corresponding code. Finally, choose different combinations of prompts and code based on specific application scenarios.
PS: My Copilot is not writing well.