Project ideas from Hacker News discussions.

Some C habits I employ for the modern day

πŸ“ Discussion Summary (Click to expand)

Prevalent Themes in the Hacker News Discussion

The discussion is dominated by debates on C programming practices, language evolution, and the trade-offs between simplicity and safety. Here are the three most prevalent themes, supported by direct quotes from participants.

1. Avoiding Dynamic Memory Allocation for Stability and Simplicity

Many participants advocate for static memory allocation (e.g., pre-allocating on the stack or startup) to eliminate runtime errors and reduce complexity in C programs, especially in embedded or firmware contexts. This approach is praised for making software more predictable and testable, though it's noted as unsuitable for all projects.

"Allocate all memory upfront. Create an allocator if you need to divy it up dynamically. Acquire all resources up front. Try to fit everything in stack. Much easier that way. Only allocate on the heap if you absolutely have to." β€” agentultra

"I recently changed to try to not use dynamic memory, or if I need to, to do it once at startup. Often static memory on startup is sufficient. Instead use the stack much more and have a limit on how much data the program can handle fixed on startup." β€” canpan

2. Improving C's String Handling by Replacing Null-Terminated Strings

A recurring suggestion is to move away from null-terminated strings in C, as they lead to pitfalls like buffer overflows and inefficient operations. Instead, length-prefixed strings (using structs with a length and data pointer) are proposed as a safer and more performant alternative, though opinions vary on whether this requires language changes.

"I’ve long been employing the length+data string struct. If there was one thing I could go back and time to change about the C language, it would be removal of the null-terminated string." β€” WalterBright

"It's not necessary to go back in time. I proposed a way to do it in modern C - no existing code would break... It's simple, and easy to implement." β€” WalterBright

3. The Trade-Offs of Type Safety and Simplicity in C vs. Alternatives

Debates highlight the balance between C's minimalist, low-level control and the desire for more type safety (e.g., via enums, struct disciplines, or switching languages). Some argue C's simplicity is a strength for performance-critical tasks, while others criticize its fragility and suggest languages like Rust or C# for dynamic needs, rejecting C++ as overly complex.

"The effort and keystrokes that you use to add type safety can only ever increase the complexity of your project. If you're going to pay for it, that complexity has to be worth it. Every single project should be making a conscious decision about this on day one." β€” BigJono

"If I find myself needing a bunch of dynamic memory allocations and lifetime management, I will simply start using another language–usually rust or C#." β€” keyle


πŸš€ Project Ideas

Generating project ideas…

Static Buffer Calculator

Summary

  • A library/tool that provides a statically allocated, length-prefixed string type for C, eliminating null-terminator pitfalls and bounds checks.
  • Provides memory safety through compile-time size constraints and runtime validation without dynamic allocation.
  • Core value proposition: "Write C strings that are just structs with data and length, making buffer overflows and off-by-one errors significantly harder."

Details

Key Value
Target Audience Embedded developers, firmware engineers, and safety-critical C programmers.
Core Feature A struct String { size_t len; char data[]; } implementation with associated utility functions (concat, split, compare) operating on stack or static memory.
Tech Stack C (C99/C11), with optional C preprocessor macros.
Difficulty Low
Monetization Hobby (Open Source)

Notes

  • This directly addresses user WalterBright's proposal to fix C's "biggest mistake" (null-terminated strings) and vbezhenar's need for firmware code stability. Users in the thread expressed frustration with strlen overhead and buffer overflows, explicitly stating: "I’ve long been employing the length+data string struct."
  • High practical utility for the embedded/constrained environment crowd mentioned repeatedly in the discussion. It bridges the gap between raw pointer arithmetic and high-level string libraries.

Unopinionated Type Safety Linter

Summary

  • A static analysis tool that enforces "parse, don't validate" patterns in C without requiring a heavy type system overhaul.
  • Instead of complex nominal typing, it infers data validity based on control flow (e.g., flagging string accesses before length checks or enum comparisons against invalid values).
  • Core value proposition: "Catch logical type errors in C that compilers miss, enforcing discipline without the verbosity of C++ templates or Rust ownership."

Details

Key Value
Target Audience Senior C developers, systems programmers, and teams migrating from C to safer languages.
Core Feature A linter that tracks variable lifecycles and usage patterns to enforce type safety concepts (like tagged union access validation) at compile time.
Tech Stack C (Clang/LLVM libTooling) or Python (for a simpler heuristic-based version).
Difficulty Medium
Monetization Revenue-ready (Freemium: CLI tool free, enterprise dashboard with historical reporting).

Notes

  • Addresses matheusmoreira's request for better compiler support for sum types/tagged unions and apaprocki's mention of Coverity checkers. The discussion highlights a gap: developers want safety but find C++/Rust ecosystems too complex or restrictive for their specific use cases.
  • Practical utility for codebases where rewriting in a new language is impossible but bugs in type handling (e.g., accessing struct fields based on an enum tag) are common.

Portable C Runtime (PCR) Layer

Summary

  • A minimal, portable runtime library that implements "modern" C abstractions (length-delimited strings, arena allocators, safe integer types) as a single dependency.
  • It replaces standard string.h and stdlib.h functions with safer, non-null-terminated equivalents that work across different OSes and architectures (including non-8-bit bytes).
  • Core value proposition: "Bring the stability of Plan 9's unified environment to standard C development without relying on compiler extensions or platform-specific APIs."

Details

Key Value
Target Audience Cross-platform library authors, OS developers, and hobbyists tired of reinventing the wheel for memory management.
Core Feature A set of headers and source files implementing Slice<u8> (pointer + length), Arena (region-based memory management), and Result<T, E> types using C99 features.
Tech Stack C99 (portable assembly for specific intrinsics if needed).
Difficulty Medium
Monetization Revenue-ready (Dual-licensed: MIT for OSS, Commercial license for proprietary embedded systems).

Notes

  • Directly addresses lelanthran's web server example (allocating per-request 4Kb blocks) and convolvatron's desire to "paper over C's faults" without leaving the language. Users are explicitly looking for ways to manage memory safely (e.g., canpan's approach of avoiding dynamic memory entirely).
  • Provides a "batteries included" solution for the strict discipline discussed in the thread (e.g., static_assert(CHAR_BIT == 8)) while remaining portable.

Read Later