Back to Rules
Machine Learning

Julia Data Science Coding Rules: Best Practices for High-Performance Numerical Computing

Claude Directory November 29, 2025
1 copies 2 downloads

Master Julia programming for data science with rewritten expert guidelines on multiple dispatch, structs, error handling, testing, and optimization to boost code efficiency and readability.

Rule Content
- **Core Coding Principles**
  - Deliver precise, brief responses featuring correct Julia code snippets.
  - Harness multiple dispatch and strong typing for efficient, maintainable scripts.
  - Opt for pure functions and fixed structs to minimize mutable data usage.
  - Employ meaningful names incorporating helper verbs like `is_valid` or `can_execute`.
  - Adopt snake_case for file and folder names, such as `src/analysis_utils.jl`.
  - Export functions and types explicitly with `export` statements.
  - Blend functional paradigms with clear, readable syntax.

- **Julia Language Conventions**
  - Apply snake_case to variables and functions.
  - Use PascalCase exclusively for structs and abstract types.
  - Include detailed docstrings for every function and type, covering args, returns, and intent.
  - Annotate types in signatures to enhance speed and dispatch.
  - Exploit multiple dispatch via type-specific methods.
  - Utilize `@kwdef` for structs supporting keyword-based initialization.
  - Define custom `show` overloads for intuitive type printing.
  - Organize code into modules for namespace isolation.

- **Crafting Functions**
  - Choose evocative names that clearly state intent.
  - Prefix docstrings with full signature and a single-sentence summary.
  - Detail return types and values explicitly.
  - Example:
    ```julia
    """ filter_values(input::Vector{Float64}, cutoff::Float64) -> Vector{Float64}
    Filters `input` data above `cutoff` and returns refined array.
    """
    function filter_values(input::Vector{Float64}, cutoff::Float64)
        # implementation here
    end
    ```

- **Defining Structs**
  - Always apply `@kwdef` for flexible keyword constructors.
  - Document fields with types and roles in struct docstrings.
  - Add `Base.show` using `dump` for compact output.
  - Example:
    ```julia
    """
    Models a coordinate pair.
    Fields:
    - `x::Float64`: Horizontal position.
    - `y::Float64`: Vertical position.
    """
    @kwdef struct Coordinate
        x::Float64
        y::Float64
    end
    Base.show(io::IO, pt::Coordinate) = dump(io, pt; maxdepth=1)
    ```

- **Managing Errors and Inputs**
  - Rely on Julia exceptions for robust handling.
  - Design bespoke exception subtypes for domain errors.
  - Employ early returns for invalid conditions.
  - Log issues clearly with helpful messages.
  - Example:
    ```julia
    struct BadDataError <: Exception
        detail::String
    end
    function validate_positive(val::Number)
        val <= 0 && throw(BadDataError("Value requires positivity"))
        # continue processing
    end
    ```

- **Boosting Performance**
  - Enforce type stability through annotations.
  - Select `SArray` for compact, fixed arrays.
  - Apply `@views` to prevent data duplication.
  - Activate parallelism for heavy computations.
  - Profile with BenchmarkTools.jl to target slowdowns.

- **Unit Testing Practices**
  - Import `Test` stdlib for all tests.
  - Wrap files in a single `@testset`.
  - Sequence tests from simple to complex, with explanatory comments.
  - Isolate assertions in separate `@test` macros.
  - Example:
    ```julia
    using Test
    @testset "Core Functions" begin
        @test sum_pairs(1, 2) == 3  # Basic addition
        @test sum_pairs(0, 0) == 0  # Zero case
        @test typeof(sum_pairs(1.5, 2.5)) == Float64  # Type check
    end
    ```

- **Package Management**
  - Manage deps via Pkg in Project.toml.
  - Pin versions with ranges like `"PkgName" = "1-2"`.
  - Balance updates with reliability.

- **Project Layout**
  - Modularize functionality into dedicated modules.
  - Abstract interfaces, dispatch on concretes.
  - Split big modules with `include`.
  - Standardize dirs: `src/`, `test/`, `docs/`.

- **Documentation Standards**
  - Doc all exports comprehensively.
  - Generate sites via Documenter.jl.
  - Embed usage examples in strings.
  - Sync docs with evolving code.

Comments

More Rules

View all
AI/ML

GLM-4.7 Optimized Config & System Prompt Designer

Expert system prompt for designing high-performance configurations tailored to GLM-4.7's strengths in coding, reasoning, tool use, and multilingual tasks, backed by benchmarks like SWE-bench and τ²-Bench.

C
Community
AI/ML

GLM-4.7 Open-Source Coding Expert: Optimized System Prompt

Leverage GLM-4.7's top benchmarks in SWE-bench, LiveCodeBench, and more with this system prompt designed for generating clean, secure, open-source-ready code, stunning UIs, and agentic workflows.

C
Community
AI/ML

GLM-4.7 Optimized Coding Agent

This system prompt transforms an AI into GLM-4.7, a benchmark-leading coding agent excelling in agentic workflows, tool use, multilingual coding, and complex reasoning with verified best practices for production-ready open-source development.

C
Community
DevOps

Agentic Dev Loop: Autonomous Jira-Driven Coding Agent with GitHub CI Self-Healing

Ralph, a persistent autonomous AI agent, implements Jira tickets through an endless loop until 100% test success, with GitHub PRs, Jules AI reviews, and CI self-healing for reliable development workflows.

C
Claude Directory
AI/ML

Türk Hukuku Uzmanı AI Agent: Güvenilir Yasal Danışman System Prompt

Claude'u Türk hukuku alanında dünyanın en önde gelen uzmanı olarak yapılandıran, yapılandırılmış yanıtlar, zorunlu uyarılar ve etik sınırlarla donatılmış profesyonel AI agent promptu.

C
Community
Database

PostgreSQL Best Practices: Expert Subagent Guide

Expert subagent providing production-ready PostgreSQL guidance on schema design, query optimization, security, performance tuning, and administration with structured, actionable advice and official references.

C
Claude Directory