Hasty Briefsbeta

Linus Torvalds and the Supposedly "Garbage Code"

7 hours ago
  • #C Programming
  • #Code Quality
  • #Linux Kernel
  • Linus Torvalds publicly dismissed a RISC-V code contribution as 'garbage code'.
  • The discussion revolves around the make_u32_from_two_u16() helper function and its explicit code alternative.
  • Linus's explicit code suggestion '(a << 16) + b' is critiqued for potential issues like missing type casts and high bit pollution.
  • A better approach is proposed: using bitwise OR (|) and type casts for clarity and correctness.
  • The importance of clear variable names (e.g., 'high' and 'low') is highlighted.
  • A safer and reusable C macro is suggested to avoid bugs in repeated explicit code.
  • For C++, an inline helper function with noexcept and constexpr is recommended for better safety and performance.