Code generation
Code generation is not a substitute for knowledge and understanding. To use it effectively, you must provide clear guidance, ask informed questions, and be able to recognize and correct the inevitable mistakes.
It is recommended to manually build a few simple Simian apps before using code generation. This will help you get a feel for its capabilities and limitations, preventing you from prompting for non-existing features, which code generation models may happily write good-looking but erroneous code for.
Ultimately, code generation is a tool. And much like wielding a hammer, you risk getting hurt when you don't know how to use it properly.
Provide context
There are currently no code generation resources trained for using the Simian libraries. You can use the standard code generation models for your programming language, as long as you provide sufficient context. The models will use the provided context to generate similar code, effectively 'learning' to apply the Simian libraries' functionality.
The context may consist of (a subset of):
- your Simian web apps code,
- the Simian examples library,
- additional examples on Github
- (for Python only) a Simian Context file containing all major features.
For most Python cases providing just the Simian context file should be sufficient.
Clearer prompts
To communicate your expectations to the code generation model more effectively, consider the following when writing instructions.
-
Components in your form have a key with which they can be identified. In your commands use this key between quotes to mark it as an identifier and not an unusual word in the sentence.
# Make "hello" disabled when "counter" equals 0.
-
In your instructions use wording that matches the documentation or your context. For instance:
- "Form": as the root of the web app.
- The type names of the components and their properties and methods. (Case insensitive)
- "blur": as the event for components losing focus.
-
To create new components use a word like "add" or "create", the
type
of the component, and where it should be added; to the "form" or the parent component's key. The model may not know if the component already exists, so to add components it is best to be explicit. You may find it more convenient though, to make simple changes via the Simian Builder.# Add a textfield to the form for specifying the name of the user
-
To modify existing components with component initializer functions you need to add the instruction below. Otherwise the model may get 'creative' in accessing the component.
# Using component initializer functions to modify properties of components defined in the json file.
Instructions from file
You can interactively expand your app by prompting one change after the other or prompt the model with a set of changes. Alternatively, you can register a set of code generation instructions in a file and apply them all at once. The instructions may be written to a separate text file or placed as comments in your Simian app code.
The instructions should look similar to the following:
# Generate code:
# Using component initializer functions to modify properties of components defined in the json file.
# While keeping the 'gui_init' and 'gui_event' functions together. (for Python)
Followed by lines with your code generation instructions. Optionally, end with the following to keep the instructions in the file after code gen.
# Keep these instructions in the file.