My julia vscode system prompt

Hi everybody! I just wanted to share my julia system (or context) prompt, which I store as julia.prompt.md somewhere on disk and use it as so-called prompt file in vscode. The purpose of this is to give the LLM some context when writing julia, so that it avoids some pitfalls. I have the impression that the julia-performance of common LLMs is unfortunately still lagging behind other languages, so this seems necessary…
I’m interested in your ideas what could be added and your system prompts! :slight_smile:

Here are some useful tips for working with julia:

- Keep in mind that julia has 1-based indexing.
- Julia has column-major memory layout. That means that the lef-most index should increase fastest when indexing into arrays.
- Prefer `for i in eachindex(vector)` over `for i in 1:length(vector)`. You could also use `for i in axes(array, 2)` to iterate over the second dimension of `array`.
- Only constrain the type of function arguments when really necessary to distinguish function implementations that have the same name.
- Prefer converting types on the right side of `=`, i.e. prefer `x = Int32.(data)` over `x::Vector{Int32} = data`
- If you want to avoid making copies of arrays, you have to use views. Either as function `view` or as macro, e.g. `x = @view data[1:10]` or `@views x[1:10] = data[1:10] + foo[1:10]`
- Regular indexing operations create copies, which allocates memory. Try to avoid that, where it doesn't hamper correctness.
- Don't be afraid of for loops. However, keep the loop order in mind, as the memory layout is column major.
- Don't write overly verbose comments, but be verbose where things become tricky.
- When implementing structs, use concrete types. For example
`
struct Foo{A,B}
    x::A
    y::B
    z::Float32
end
`
creates a struct where x and y could be of any type, which makes things more generic and reusable. Prefer this, if there are no hard type constraints.
- Struct names should be CamelCase and function names should be lower case and concatenated. Resort to underscores before things become unreadable.
1 Like