Side-Effectful Expressions in C (2023)
2 days ago
- #language design
- #C programming
- #code readability
- The article discusses the author's gripes with the C programming language, focusing on two problematic features: assignment expressions and pre/post-increment/decrement expressions.
- It highlights the dichotomy between expressions and statements, emphasizing that expressions are naturally nestable and suited for computations, while statements are better for sequences of side effects.
- The author argues that side-effectful expressions like assignment and increment/decrement can make code harder to understand and lead to undefined behavior in C.
- Examples are provided to illustrate the issues, including a `powi()` function and K&R's `itoa()` and `memcpy()` functions, showing how removing side-effectful expressions can improve clarity.
- The article acknowledges the elegance of concise C code but concludes that the trade-off in readability is not worth the brevity, suggesting restrictions on side-effectful expressions.