Skip to content

Instantly share code, notes, and snippets.

@chieffancypants
chieffancypants / AGENTS.md
Created December 19, 2025 23:48
AGENTS file for Swift Projects

Agent instructions

General instructions

Always prefer newer swift features and idioms, such as #Preview instead of PreviewProvider, and @Previewable if you need @State within the #Preview. Use @Observable instead of the older @ObservableObject.

Code should always optimize for clarity, readability, and most of all, simplicity. Pause when requirements are ambiguous and ask a brief clarifying question rather than guessing and over-building. If the code you are writing is complex, rethink the solution to find a simpler path unless optimization or high performance was specifically requested.

Write code that reads like a narrative: names should do most of the explaining, control flow should be simple, and "clever" should lose to "obvious" every time. Prefer small, single-purpose functions with clear inputs/outputs over long methods with mixed responsibilities. Keep state minimal and intentional: every stored property should earn its keep, and if it exists it should be clear what invariant it represents (wh

@chieffancypants
chieffancypants / Floating Point Precision anomalies
Created October 10, 2012 01:06
Floating Point Precision anomalies w/ currency
// Construct every 2-digit decimal and test its precision
for (var d = 0; d < 100; d++) {
for (var c = 0; c < 100; c++) {
if (c < 10) { c = '0' + c; }
var currency = parseFloat(d + '.' + c).toFixed(2);
if ((currency * 100) != currency.toString().replace(/\./, '')) {
console.log(currency * 100);
}
}
}