Hacker News new | ask | show | jobs
by premchai21 5553 days ago
I find keeping the semantics of puts in my working memory to be harmful. The problem is that whereas (for instance) printf(...) is essentially an abbreviation for fprintf(stdout, ...), puts adds a newline whereas fputs does _not_. This is a headache to keep track of.

The result of this is that I always use fputs to write a plain C string to a stdio handle, specifying stdout explicitly and adding newlines if needed, and I ignore puts entirely, much like I ignore gets. The convenience is not worth the subtle error-causing asymmetry and associated mnemonic pain, especially if that code may ever have to write somewhere other than stdout.

1 comments

An inconvenient convenience. An excellent point, and just the sort of feedback I'd been waiting for; thank you. I'll publish the revised “Best” example shortly with fputs in place, and update the page accordingly.