Elements of C Style (1994)
Posted4 months agoActive4 months ago
teamten.comTechstory
calmmixed
Debate
60/100
C ProgrammingCoding StyleLegacy Code
Key topics
C Programming
Coding Style
Legacy Code
The 1994 article 'Elements of C Style' is discussed on HN, with commenters sharing their thoughts on its advice and relevance to modern C programming.
Snapshot generated from the HN discussion
Discussion Activity
Light discussionFirst comment
2d
Peak period
3
54-60h
Avg / period
2
Key moments
- 01Story posted
Sep 16, 2025 at 3:21 AM EDT
4 months ago
Step 01 - 02First comment
Sep 18, 2025 at 8:21 AM EDT
2d after posting
Step 02 - 03Peak activity
3 comments in 54-60h
Hottest window of the conversation
Step 03 - 04Latest activity
Sep 19, 2025 at 6:36 AM EDT
4 months ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
ID: 45259080Type: storyLast synced: 11/20/2025, 5:11:42 PM
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.
I really like the ones in the "Purity" section, and also appreciate the name, I sometimes struggle to express those ideas. To me it's a lot about using the language as if you knew it, not from some strange position of fear that you sometimes see.
My pet peeve in the context is comparing boolean values with boolean literals, i.e.
which is just horrible in my opinion since the result of an expression like `a == b` is in itself a boolean[*], so it just goes around and around, then! But nobody pretends that is true, since that would lead to which never happens, so for some reason in people's heads there is some significant difference between that and the first case ... which I find offensive. Always just write for the win.Also, since nobody actually uses `const` as much as possible, using the explicit comparison also opens your code to the fantastic typo of:
[*] In C it's more like "an int-type value equal to 0 or 1", I know, but logically that is a boolean in quite many ways.Edit: markup asterisk failure.
Hence the better way of comparing literals or consts to vars:
In C "false" is truthy, and so is "" but 0 is falsy
In a language where types aren't a gentle suggestion "false" is a string, so it can't be true or false, which are booleans. In such a language if (success) implies that success is a boolean, so the comparison is redundant. But C is not that language.
I stopped reading there.
edit: It uses CSS which was invented in 1996 (according to Wikipedia). That means it was updated at a later date.
I've seen enough "modern legacy" code with custom boolean macros defined to resent that on sight, so it stood out, even knowing this is advice from the time it was written.