ams-julia-pro
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 0
- Forks
- 1
03 SKILL.md 正文
Julia Pro
Overview
Julia's promise — high-level expressiveness with C-like speed — is delivered through multiple dispatch and JIT compilation, but only when code is type-stable. Professional Julia means designing with dispatch in mind, writing type-stable functions, preallocating where it counts, and using the ecosystem (DataFrames, JuMP, DifferentialEquations) instead of reinventing numerics.
The through-line: generic functions, concrete types, stable inference — then the compiler makes it fast.
When to use
- Writing or reviewing Julia for correctness or performance.
- Designing APIs around multiple dispatch.
- Debugging type instability or slow code.
- Structuring Julia packages (modules, environments, testing).
- Scientific computing, optimization, or data workflows.
Core concepts
- Multiple dispatch as the design tool. Functions specialized on argument types —
process(x::Float64)vsprocess(x::AbstractArray)— replace class hierarchies and conditionals-on-type. Design functions around data, not methods inside classes. - Type stability is performance. A function whose return type depends only on input types
(inferable by the compiler) compiles to fast code; type-unstable functions (returning
Intsometimes,Float64others) force dynamic dispatch and kill speed.@code_warntypeshows instability in red (Any,Unionwhere you didn't expect them). - Concrete field types.
struct Point { x::Float64; y::Float64 }— abstractly-typed fields (x::Real) make every access dynamic. Parametric types (Point{T<:Real}) give genericity with concreteness. - Avoid globals in hot code. Global variables defeat inference (their type can change).
Pass parameters explicitly, or declare
constglobals (type-fixed after definition). - Allocation awareness. Profile allocations (
@allocated,--track-allocation); preallocate outputs in hot loops; prefer views (@views) over copies for slices; mutate with!-suffixed functions where the API supports it. Most Julia slowness is accidental allocation. - The ecosystem is the point. DataFrames.jl, CSV.jl, JuMP, DifferentialEquations.jl, Plots/Makie — world-class and composable via dispatch. Don't hand-roll solvers or data frames.
Practical workflow
- Scaffold a package.
] generate MyPkg(or PkgTemplates);Project.toml+Manifest.toml(commit the manifest for apps, not for libraries);test/runtests.jlwith Test stdlib. - Write generic, stable functions. Small functions, concrete-typed structs, dispatch on
abstract types in signatures (
f(x::AbstractVector)) while keeping fields concrete. - Check stability early.
@code_warntype f(args...)on hot functions — redAny/Unionmeans fix the types before optimizing anything else. - Benchmark properly. BenchmarkTools.jl
@btime/@benchmark(with$interpolation of globals!); compare before/after; profile with@profview(ProfileView) or PProf. - Reduce allocations deliberately. Views, in-place ops, preallocation — but only in measured hotspots. Readable allocating code beats clever in-place code everywhere else.
- Test and document. Unit tests for logic, regression tests for numerical results (with
tolerances —
isapprox, never==on floats), Documenter.jl for package docs.
Idiomatic snippets:
# Parametric struct: generic AND concrete
struct Measurement{T<:Real}
value::T
uncertainty::T
end
# Dispatch replaces conditionals-on-type
area(s::Circle) = π * s.r^2
area(s::Rectangle) = s.w * s.h
# Type-stable: return type follows input type
function mysum(xs::AbstractVector{T}) where T<:Number
s = zero(T)
for x in xs
s += x
end
return s
end
Common pitfalls
- Type-unstable functions. The #1 Julia performance bug.
if cond; return 1; else; return 1.5; endpoisons inference. Make branches return consistent types. - Abstractly-typed struct fields.
struct Foo; x::Real; end— every field access is dynamic dispatch. Always concrete or parametric. - Globals in hot loops. Non-const globals force dynamic lookup per iteration. Pass as arguments
or mark
const. - Benchmarking wrong.
@timeincludes compilation; forgetting$interpolation measures global access. Use BenchmarkTools correctly or your "optimizations" are noise. - Float equality.
0.1 + 0.2 == 0.3is false.isapproxwith tolerances; never exact equality on computed floats. - Over-vectorizing. Dot-broadcasting everything into giant temporary arrays instead of writing
a fused loop. Dots fuse (
@. a = b*c + dis one pass) — but sometimes a plain loop is clearest. - Ignoring the manifest. "It worked yesterday" because an unpinned dep updated. Environments per project; manifests committed for reproducibility.
04 同仓库更多 Skills
web-scrape
Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open/fetch fails on JS-heavy pages, or when you need clean markdown/structured extraction from a site. Requires FIRECRAWL_API_KEY.
design-taste-frontend
tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML/CSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, "AI-made", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.
test-driven-development
Use when implementing any feature or bugfix, before writing implementation code
systematic-debugging
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
requesting-code-review
Use when completing tasks, implementing major features, or before merging to verify work meets requirements
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).