julia
Use when writing Julia programs — command-line tools with ArgParse, HTTP API clients with HTTP.jl and JSON3, numerical scripts, package environments with Project.toml and Manifest.toml, and Pkg.test i
SKILL.mdskills/languages/julia/SKILL.md
GitHubJulia
Default: current stable Julia from the official tarball or juliaup, a project environment per tool (Project.toml + committed Manifest.toml), Test stdlib, Pkg.test() as the single test entry point.
Setup
julia --project=. -e 'using Pkg; Pkg.generate("Tool")', thenPkg.add(["HTTP", "JSON3", "ArgParse"]).- Always run with
--project=.(or setJULIA_PROJECT), otherwise the global environment is used and versions drift. - Commit
Manifest.tomlfor applications so the exact dependency set is reproducible; omit it for libraries.
API client tools
- Read tokens from environment variables only; refuse to start if missing, and never print them.
- Default to a dry run. List what would be changed; require an explicit
--applyto perform writes or deletions. - Respect rate limits: read
Retry-Afteron HTTP 429 and sleep; cap retries. - Paginate until the cursor is empty; never assume one page is everything.
- Before deleting anything, show how the targets were identified (e.g. inspect one example first, then list all matches) so a human can confirm the selector.
using HTTP, JSON3
function get_json(url; token)
r = HTTP.get(url, ["Authorization" => "Bearer $token"]; status_exception=false, retry=false)
r.status == 429 && (sleep(parse(Int, HTTP.header(r, "Retry-After", "1"))); return get_json(url; token))
r.status == 200 || error("HTTP $(r.status)")
JSON3.read(r.body)
end
Numerical work
- Write type-stable functions (check with
@code_warntype); avoid global variables in hot loops or wrap them inconst. - Preallocate arrays and use in-place functions (
mul!,.=) for loops. - Benchmark with
BenchmarkTools.@btime, not@timeon the first call (which includes compilation).
Testing
test/runtests.jlwith@testsets;julia --project -e 'using Pkg; Pkg.test()'.- Mock HTTP by passing the request function as an argument, so tests run offline.
Verification loop
Pkg.instantiate()from a clean checkout succeeds.Pkg.test()passes (also insidedocker buildfor a clean environment).- Run the tool in dry-run mode against the real API before any
--apply.
Pitfalls
- Time to first execution: the first call of each function compiles; a short CLI may spend most of its time compiling. Accept it for occasional tools, or use precompilation (
PrecompileTools) / a system image for frequent ones. - 1-based indexing and column-major arrays: iterate the first index in the inner loop.
- Integer overflow wraps silently for
Int; useBigIntor checked arithmetic where values can grow. - Strings are UTF-8 with byte indices:
s[2]may error on multibyte text; useeachindex,nextindorcollect(s). usinginside functions is not allowed; load packages at top level.