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 從公開儲存庫中收錄這些內容。

檢舉或申請下架