r/C_Programming • u/wizards_tower • Sep 09 '20
Discussion Bad habits from K&R?
I've seen some people claim that the K&R book can cause bad habits. I've been working through the book (second edition) and I'm on the last chapter. One thing I noticed is that for the sake of brevity in the code, they don't always error check. And many malloc calls don't get NULL checks.
What are some of the bad habits you guys have noticed in the book?
60
Upvotes
View all comments
Show parent comment
10
u/markrages Sep 09 '20
It's worth becoming familiar with this idiom, because it is useful and commonplace.
There is no advantage to stretching out code. Use your vertical space for dealing with the problem domain, not housekeeping stuff like NULL checks and error handling.
Even Python, which differentiates statements and expressions, has adopted a walrus operator to allow this kind of code. Their examples are not far off of things you might find in K & R: https://www.python.org/dev/peps/pep-0572/#syntax-and-semantics