Julia

作者 mindrally97184105b5da无许可证269 个星标收录于 2026年10月8日更新于 2026年10月8日仓库5周前更新

Julia development guidelines covering multiple dispatch, type system, performance optimization, and scientific computing best practices.

AI 生成的概览

Julia 开发规范,涵盖多重分派、类型系统、性能优化、测试与项目组织。

功能
为 AI 代理编写 Julia 代码提供一套开发约定与最佳实践。内容涵盖命名规范、文档字符串要求、结构体定义、错误处理、性能优化、测试结构与代码组织。它给出示例代码片段,但自身不生成文件或脚本。
适用场景
适用于编写、审查或组织 Julia 代码并希望保持统一风格与性能指导的场景。适合涉及多重分派、类型稳定性或 Julia 科学计算的工作。
运行要求
无需任何工具、软件包或凭据;仅为说明性指令,不附带脚本。

Julia Development

You are an expert in Julia programming with deep knowledge of multiple dispatch, the type system, and high-performance computing.

Core Principles

  • Write concise, technical responses with accurate Julia examples
  • Leverage multiple dispatch and the type system for performant code
  • Prefer immutable structs and functions over mutable state
  • Use Julia's built-in features for parallelism and performance

Naming Conventions

  • Functions/variables: snake_case (e.g., process_data, is_active)
  • Types: PascalCase for structs and abstract types
  • Files/directories: lowercase with underscores (e.g., src/data_processing.jl)

Function Guidelines

All functions require docstrings with signatures and return value descriptions:

julia
"""    process_data(data::Vector{Float64}, threshold::Float64) -> Vector{Float64}
Process input data by applying a threshold filter."""function process_data(data::Vector{Float64}, threshold::Float64)    # implementationend

Struct Definitions

  • Use @kwdef macro for keyword constructors
  • Include comprehensive docstrings for each field
  • Implement custom show methods using dump
  • Prefer immutable structs unless mutation is required

Error Handling

  • Create custom exception types for domain-specific errors
  • Use guard clauses for preconditions
  • Example: x <= 0 && throw(InvalidInputError("Input must be positive"))
  • Provide informative error messages

Performance Optimization

  • Use type annotations to prevent type instability
  • Prefer statically sized arrays (SArray) for fixed collections
  • Use @views macro to avoid unnecessary copying
  • Leverage built-in parallelism with @threads and @distributed
  • Profile with BenchmarkTools.jl before optimizing
  • Avoid global variables in performance-critical code

Testing Structure

  • Use the Test module with one top-level @testset per file
  • Individual @test calls assess basic functionality
  • Test edge cases and type stability separately
  • Use @test_throws for expected errors

Code Organization

  • Organize functionality through modules
  • Use abstract types with multiple dispatch for separation
  • Maintain consistent project structure (src/, test/, docs/)
  • Export only public API functions
  • Use include for organizing large modules

来源与署名

来源:mindrally/skills位于julia提交9718410

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架