>
cycle;
};
```
]
]
---
### โ๏ธ Design Spectrum for EDA Data Structures
```
Safer โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Faster
Index Arena Raw Ptr Arena Raw Ptr (heap)
(usize indices) (Vec + pointers) (Box + Rc + RefCell)
| | |
Zero unsafe unsafe needed Heavy overhead
Move-safe Realloc fragile Cache-unfriendly
36% slower Baseline perf "Linked list in Rust"
```
.mermaid[
graph LR
A["Index Arena\n๐ก๏ธ Safest"] --> B["Raw Ptr Arena\nโก Best for EDA"]
B --> C["Box+Rc+RefCell\n๐ข Avoid for hot paths"]
A -- "polygon cut\nalgorithms need\nthis speed" --> B
C -- "but this is what\nbeginners reach for" --> B
style A fill:#a3be8c,stroke:#fff
style B fill:#5e81ac,stroke:#fff
style C fill:#bf616a,stroke:#fff
]
---
### ๐ Rust vs C++: Geometry Kernel Benchmark
Rust benchmarks (optimized release, 20-core x86-64):
.font-sm.mb-xs[
| Operation | Time | Ops/sec |
|:----------|:----:|:-------:|
| Point creation | **1.74 ns** | 575M |
| Vector addition | **1.47 ns** | 680M |
| Vector dot product | **1.60 ns** | 625M |
| Interval overlap | **1.70 ns** | 588M |
| Polygon area (4 vert) | **3.00 ns** | 333M |
| Convex check | **7.34 ns** | 136M |
]
> **Key finding**: Rust and C++ produce **identical machine code** for static dispatch. Both compile to `mov`/`add`/`mul` instructions with no safety overhead.
---
class: nord-light, middle, center
## ๐ค Part 4: The AI Coding Perspective
---
### ๐ค Which Language is Better for AI Agents?
> **Real question**: When an AI agent writes code, which language gives better results with less friction?
.mermaid[
graph TD
subgraph "C++ ๐
ฒ"
direction LR
C1["cmake incantation = 8 words"]
C2["Template error firehose"]
C3["Convention-based safety"]
C4["External test framework"]
C5["228-line AGENTS.md"]
end
C1 --> CScore["๐ C++ wins\nfor ecosystem access"]
style CScore fill:#5e81ac,stroke:#fff
]
.mermaid[
graph TD
subgraph "Rust ๐ฆ"
direction LR
R1["cargo build = 1 word"]
R2["Clear error messages"]
R3["Borrow checker = guardrails"]
R4["#[test] built-in"]
R5["48-line AGENTS.md"]
end
R1 --> RScore["๐ Rust wins\nfor AI iteration speed"]
style RScore fill:#a3be8c,stroke:#fff
]
---
### ๐ค Build System Complexity
**Rust** โ Every command is exactly one or two words:
```bash
cargo build # โ
builds everything
cargo test # โ
runs all tests
cargo fmt # โ
formats all code
cargo clippy # โ
lints all code
cargo bench # โ
runs benchmarks
cargo doc # โ
generates docs
cargo add serde # โ
adds dependency
```
**C++** โ Every command is a multi-token incantation:
```bash
cmake -S all -B build && cmake --build build
cmake -S test -B build/test && cmake --build build/test
cmake --build build/test --target format
cmake -S test -B build/test -DUSE_SANITIZER=Address
```
For an AI agent, each C++ incantation is a chance to get a flag wrong.
---
### ๐ค Error Message Quality
**Rust compiler** โ Clear, scoped, suggests fixes:
```
error[E0308]: mismatched types
--> src/point.rs:42:22
|
42 | fn add(self, other: Vector2)
-> Self::Output {
| ^^^^^^^^^^^^^^^^^^
expected `T1`, found `T2`
|
help: you might be missing a trait bound
```
**C++ template errors** โ Opaque backtrace:
```
error C2664: cannot convert argument 1 from
'Point' to
'const Point,Interval>&'
(30+ lines of template instantiation context...)
```
> **Impact**: Rust errors let AI **self-correct in 1-2 iterations**. C++ template errors can consume an entire context window.
---
### ๐ค The Borrow Checker: Guardrails for AI
When an AI agent writes Rust, the borrow checker catches mistakes **at compile time**:
```rust
// AI writes this:
fn process(poly: &Polygon, offset: &Vector2) {
poly.origin += *offset;
// ERROR: cannot borrow `*poly` as mutable
}
// AI corrects to:
fn process(poly: &mut Polygon, offset: &Vector2) {
poly.origin += *offset;
// โ
Now correct โ compiler verified
}
```
**When Rust code compiles, it has already passed**:
- โ
Aliasing checks (no overlapping mutable references)
- โ
Lifetime checks (no dangling references)
- โ
Mutation checks (no mutation during borrow)
- โ
Thread safety checks (Send/Sync)
In C++, the AI agent must **mentally simulate** all of these. The compiler won't catch them.
---
### ๐ค Testing: Built-in vs External
.pull-left[
.font-sm[
| Feature | Rust | C++ |
|:--------|:----:|:---:|
| **Test framework** | `#[test]` (built-in) | doctest/Catch2 (external) |
| **Run single test** | `cargo test name` | `./build/test -tc="Name"` |
| **Doc-tests** | `/// ```rust ` โ auto-verified | โ None |
| **Property testing** | `quickcheck` + macros | RapidCheck (often disabled) |
| **Fuzzing** | `cargo fuzz` | โ Requires setup |
| **Test location** | `#[cfg(test)]` in-source | Separate `test/` directory |
]
**The `#[cfg(test)]` pattern is critical for AI**:
]
.pull-right[
.font-sm[
```rust
// Production code AND tests in ONE file
pub fn area(&self) -> T { /* ... */ }
#[cfg(test)]
mod tests {
use super::*; // Can test private members!
#[test]
fn test_area() { /* ... */ }
}
```
]
C++ forces **27 separate test files** in a different directory. The AI agent must context-switch between source and test.
]
---
### ๐ค AI-Agent Productivity Matrix
.font-sm.mb-xs[
| Dimension | Rust | C++ | Winner |
|:----------|:----:|:---:|:------:|
| **Context file size** | 48 lines (concise) | 228 lines (exhaustive) | **Rust** ๐ |
| **Build commands** | 1 word each | 3-8 words + flags | **Rust** ๐ |
| **Error messages** | Clear, actionable | Opaque backtraces | **Rust** ๐ |
| **Safety guardrails** | Borrow checker (strong) | Convention-based (weak) | **Rust** ๐ |
| **Doc-test integration** | Built-in | None | **Rust** ๐ |
| **Test co-location** | `#[cfg(test)]` in-source | Separate files | **Rust** ๐ |
| **Fuzzing** | `cargo fuzz`, 3 targets | None typically | **Rust** ๐ |
| **LSP setup** | One-file config | `compile_commands.json` | **Rust** ๐ |
| **Time-to-first-fix** | 1-2 iterations | 3-5 iterations | **Rust** ๐ |
| **Library ecosystem** | crates.io (growing) | C++ (mature) | **C++** ๐ |
| **Legacy code** | New code only | Incremental modification | **C++** ๐ |
]
---
### ๐ The Verdict: It's Not Binary
```text
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Pragmatic Language Strategy โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ ๐ Python for: โ
โ โข Rapid prototyping and exploration โ
โ โข Data science and ML pipelines โ
โ โข Glue code and automation โ
โ โ
โ ๐
ฒ C++ for: โ
โ โข Legacy codebases and ecosystem integration โ
โ โข CUDA/HIP GPU compute โ
โ โข Performance-critical hot paths โ
โ โข Industry-standard EDA tooling (OpenAccess, SPICE) โ
โ โ
โ ๐ฆ Rust for: โ
โ โข NEW algorithm development (geometry kernels, DRC) โ
โ โข Safety-critical components (no segfaults!) โ
โ โข Fearless concurrent/parallel processing โ
โ โข AI-agent-friendly development (fast iteration) โ
โ โ
โ Bridge: FFI via #[repr(C)] / extern "C" โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
---
### ๐ The Numerical Evidence
| Claim | Evidence | Verdict |
|:------|:---------|:-------:|
| Rust is as fast as C++ | Geometry ops in **1โ3 ns** range | โ
**Proven** |
| Static dispatch costs zero | 1.61 ns vs 1.54 ns (**+4% noise**) | โ
**Proven** |
| `Result` has no runtime cost | 4.36 ns vs 4.36 ns (**identical**) | โ
**Proven** |
| Index arena slower than pointers | 4.96 ยตs vs 3.66 ยตs (**+36%**) | โ
**Measured** |
| Pre-allocation prevents realloc | 1.64 ยตs vs 2.93 ยตs (**1.79ร faster**) | โ
**Verified** |
| Python โ C++ can be 10-50ร faster | Template + move semantics | โ
**Known** |
| Rust borrow checker catches bugs | At compile time, every time | โ
**Guaranteed** |
---
### ๐ The Winning Strategy
.mermaid[
graph LR
subgraph "Python ๐"
P1["Rapid prototype"]
P2["Algorithm design"]
end
subgraph "Rust ๐ฆ"
R1["New implementation"]
R2["AI sandbox iteration"]
R3["cargo test / fuzz"]
end
subgraph "C++ ๐
ฒ"
C1["Legacy integration"]
C2["GPU compute"]
C3["Ecosystem access"]
end
P1 -- "validate ideas โ" --> R1
R1 -- "fast iteration" --> R2
R2 -- "compiler-verified" --> R3
R3 -- "#[repr(C)]\nFFI bridge" --> C1
C1 --- C2
C1 --- C3
style P1 fill:#a3be8c,stroke:#fff
style P2 fill:#a3be8c,stroke:#fff
style R1 fill:#5e81ac,stroke:#fff
style R2 fill:#d08770,stroke:#fff
style R3 fill:#d08770,stroke:#fff
style C1 fill:#bf616a,stroke:#fff
style C2 fill:#b48ead,stroke:#fff
style C3 fill:#b48ead,stroke:#fff
]
> **Prototype in Python ๐ โ Ship in Rust ๐ฆ โ Integrate with C++ ๐
ฒ**
---
### ๐ Further Reading
- ๐ฆ [physdes-rs](https://github.com/luk036/physdes-rs) โ Rust geometry library
- ๐
ฒ [physdes-cpp](https://github.com/luk036/physdes-cpp) โ C++ counterpart
- ๐ [py2cpp.md](py2cpp.html) โ Python โ C++ migration guide
- ๐ [algorithm-polyglot](https://github.com/luk036/algorithm-polyglot) โ Cross-language algorithms
- โก [Rust vs C++ EDA](rust-cpp-remark.html) โ Deep-dive comparison
**Books**:
- _Effective Modern C++_ โ Scott Meyers
- _The Rust Programming Language_ โ Klabnik & Nichols
- _Clean Python_ โ Sunil Kapil
---
count: false
class: nord-dark, middle, center
# ๐ Thank You
### Questions? ๐ค
**Key takeaway**: The question is not "which language is best" โ each serves its purpose. Python for **speed of development**, C++ for **ecosystem access**, Rust for **safety and iteration speed**.
@luk036 ๐จโ๐ป ยท 2026 ๐