Bugs in Hello World
March 9, 2022 2:40 PM   Subscribe

Hello World might be the most frequently written computer program. For decades, it's been the first program many people write, when getting started in a new programming language. Surely, this humble starting-point program should be bug free, right? A 650-word blog post from sunfishcode via lobste.rs
posted by cgc373 (36 comments total) 13 users marked this as a favorite
 
Nobody is good at programming.
posted by fnerg at 3:02 PM on March 9, 2022 [7 favorites]


They're not wrong. But generating a hardened, fully-OS-compliant program isn't the point.
posted by tommasz at 3:02 PM on March 9, 2022 [8 favorites]


I gotta say, "doesn't report error condition if output file descriptor is full" is a little nitpicky. Or if you're going to go that route there's an awful lot of other failure conditions; maybe the output is redirected to a network socket that fails. Maybe the output hangs and never times out. I don't think the C version can run out of memory or other allocated resources in a way the program itself needs to handle but I'm not 100% positive. Other languages certainly could.

That's why we just run everything from systemd. /s
posted by Nelson at 3:14 PM on March 9, 2022 [4 favorites]


I agree: the "error" of "output not written because device full" is unreasonably picky. If that's a bug, then so is failure to handle a signal sent to the process (for example, if the system is shutting down and the process is killed during the write).

If you're writing a program that is intended to be long-lived, then you have to check for things like that, or have some sort of reliable crash-and-restart system. But Hello World is not that program.
posted by spacewrench at 3:26 PM on March 9, 2022 [6 favorites]


My read on this is that the bug is in gcc, not hello.c.
posted by microscone at 3:29 PM on March 9, 2022 [5 favorites]


WONT_FIX
posted by ryanrs at 3:44 PM on March 9, 2022 [14 favorites]


If Hello World is the quintessential program then it seems appropriate for it to have a deeply obscure edge case which nobody is likely to fix.
posted by solarion at 4:10 PM on March 9, 2022 [23 favorites]


++?????++ Out of Cheese Error. Redo From Start.
posted by RonButNotStupid at 4:47 PM on March 9, 2022 [6 favorites]


I've created a special device /dev/selfdestruct and it's surprising how many programs don't properly handle having the computer catch fire during execution.
posted by Pyry at 4:57 PM on March 9, 2022 [19 favorites]


Heh - I was looking at my old 2nd Edition C book ("ANSI EDITION!" 1989, 20th printing) last night, I was curious if it's been updated, but apparently this is the most current edition. I get that in the modern era everything is online, but that book is such a great example of a book for language documentation with cool tips/tricks etc... It's a real shame it hasn't been updated. I got rid of tons of books, I don't program in C really, but it's such a great book I made sure to keep it.
posted by symbioid at 5:20 PM on March 9, 2022 [3 favorites]


If you're writing a program that is intended to be long-lived, then you have to check for things like that, or have some sort of reliable crash-and-restart system. But Hello World is not that program.

Even then, you only handle error conditions that are likely to arise in actual operating conditions. If your cloud-based web app can't handle a container restarting without warning, you've written shitty code. If the same app can't handle the simultaneous combustion of three separate cloud providers, you're probably OK. In fact, if you've spent the time it would take to harden your application against that second scenario, you're probably going to be out looking for work, because it will have taken you a year and a half to write a completely bug-free Hello World.
posted by Mayor West at 7:05 PM on March 9, 2022


he's clever sure but maybe not too smart
posted by pingu at 8:52 PM on March 9, 2022 [2 favorites]


Meh, it's not 'Perl 6' anymore, it's 'Raku'. Most of my systems program sort of code relied on the Klingon Programming paradigm "Better to try and die than to return failure." Most things caught unexpected things and made a last ditch effort to send out a final message buoy by dropping a message via local sendmail, root usually has a bit of extra oomph to at least eventually send the message.
posted by zengargoyle at 10:05 PM on March 9, 2022 [2 favorites]


I see that AWK is the oldest language tested to not have the bug.

Is it just me, or is AWK low-key one of the great languages? It kind of invented the genre of modern scripting languages.
posted by clawsoon at 10:13 PM on March 9, 2022 [10 favorites]


Is it just me, or is AWK low-key one of the great languages?

It totally is. AWK got me out of so many jams.
posted by Dr. Twist at 10:35 PM on March 9, 2022 [4 favorites]


The bug isn't in C, the bug is in YAML for not including proper closing markup.
posted by They sucked his brains out! at 10:39 PM on March 9, 2022 [2 favorites]


If the world doesn't want you to say hello, you can't say hello. But that's the world's problem, not yours.
posted by away for regrooving at 11:59 PM on March 9, 2022 [3 favorites]


He is correct in a "isn't this interesting" kind of way. But reliability (security, resilience...) engineering always comes down to how much you can afford. So you tend to spend more hardening the inflight control systems for an aircraft than the innards of a dvd player.

It is the classic tradeoff triangle, cost/time/quality, you get to minimise 2. And another vote for awk.
posted by epo at 1:33 AM on March 10, 2022 [1 favorite]


WRT C, printf has a return value, it's not the compiler's fault if you don't check it.
posted by jordemort at 6:21 AM on March 10, 2022 [2 favorites]


way to overthink the "does the beginner's toolchain work at all?" problem
posted by scruss at 7:50 AM on March 10, 2022 [2 favorites]


So you tend to spend more hardening the inflight control systems for an aircraft than the innards of a dvd player.

OTOH, if the code in an airliner crashes, at worst, <300 people die, a statistically insignificant blip next to all the other deaths naturally occurring that day. If the code in a DVD player has a bug, trillions of dollars of Hollywood intellectual property become vulnerable to piracy, possibly undermining the very foundations of capitalism itself.
posted by acb at 8:00 AM on March 10, 2022 [9 favorites]


Also:
- No unit tests
- No documentation
- No internationalization (and a literal string inline in the code!)

How on earth did this make it past PR review?
posted by CaseyB at 9:30 AM on March 10, 2022 [9 favorites]


Favouriting multiple comments for prime Grade-A sarcasm.
posted by clawsoon at 9:34 AM on March 10, 2022 [2 favorites]


I've never used Awk for anything serious, but I picked it up recreationally a few years ago. It really is an impressive language.
posted by biogeo at 9:42 AM on March 10, 2022


Writing an article about bugs in code surely should include at least a working definition of what constitutes a bug in code.

This omission is, I declare, a bug in the blog post.

Also, yes, AWK is golden.
posted by Ayn Marx at 9:45 AM on March 10, 2022 [4 favorites]


From the title, I thought this would be about the discovery of a long lost Merrie Melodies short. So disappointing.
posted by dchase at 11:09 AM on March 10, 2022


WRT C, printf has a return value, it's not the compiler's fault if you don't check it.

Speaking of bugs, what bugs me is that the writer could have compiled with all warnings enabled and checked errno. I am irked.
posted by They sucked his brains out! at 12:40 PM on March 10, 2022


It wasn't my impression that the writer's intention was to determine if a particular language had a shortcoming in regards to this 'bug', only that the most common Hello World programs implemented in each language had it. On the other hand, writing the shortest-possible "Hello World" implementation in each language that handles this edge-case might be an interesting 18 hole round of code golf.
posted by WaylandSmith at 1:40 PM on March 10, 2022


This behavior is by design.

NOTABUG_WONTFIX
posted by flabdablet at 7:22 PM on March 10, 2022


It raises an interesting question, though. How many programmers do you know that are aware puts and printf even have a return value?

This may not be much of a bug, but C (and, apparently, other languages) helpfully hide the fact that there is an error that you might even consider checking for, assuming that you know this and have actively chosen not to. That is... not what is happening here.

There have been languages in the past where all return codes must be checked or ignored and all exceptions must be caught. This is not a terrible thing, in the right circumstances.
posted by How much is that froggie in the window at 10:30 AM on March 11, 2022


How many programmers do you know that are aware puts and printf even have a return value?

I know a lot of C programmers, and I can't think of one I know who wouldn't. There'd be no point in having <stdio> declare those functions as returning int unless they did.

Also, if you're compiling with all warnings enabled as everybody always should, the compiler will complain if you call either one without doing something with its return code.
posted by flabdablet at 11:25 AM on March 11, 2022


In fact, it's completely arguable that a perfectly good reason for leaving this "bug" unfixed in hello.c is that the entire purpose of that code is to serve as a check that the compilation toolchain is working as intended, so it should provoke that very warning when compiled as a quick check that warnings are in fact turned on.
posted by flabdablet at 11:32 AM on March 11, 2022 [2 favorites]


I told you guys to write the tests first!
posted by bendy at 1:41 PM on March 11, 2022 [1 favorite]


There'd be no point in having declare those functions as returning int unless they did.

Well actually in the old K&R C dialect that printf and puts were defined for, functions returning void was not a thing. Int was the default return type if undeclared. So they sort of returned int by default. I do think these methods always returned the number of characters emitted, but I'd have to read some V7 docs to be sure.

The reality is there are very few circumstances where these functions will print less than the stated characters and yet keep running. Or that you'd care if it happened. Also most C programs in that era don't really handle exceptions in all sorts of circumstances. malloc failing being a very popular return value to ignore (quickly leading to a NULL pointer error). It's perfectly reasonable in quotidian code to not check the printf return value in almost all circumstances.
posted by Nelson at 2:20 PM on March 11, 2022


Nobody is good at programming.

Am a professional programmer; can confirm.
posted by Mr. Bad Example at 11:40 AM on March 12, 2022 [3 favorites]


Am a professional programmer; can confirm.

I saw a quadrant the other day explaining why cryptocurrency smart contracts aren't a good idea: If you get one wrong the first time, you can lose all your money. Wise, experienced programmers know that getting everything right the first time is unlikely, so they don't write smart contracts. As a result, the developers who write smart contracts all end up being some combination of inexperienced or unwise.
posted by clawsoon at 7:07 PM on March 14, 2022 [2 favorites]


« Older Eric Idle interviewed by Bob Saget   |   A final message from the Alpha Dog Newer »


This thread has been archived and is closed to new comments