Hacker News new | ask | show | jobs
by _qib3 485 days ago
But why was _name the naming syntax for reserved keywords, specifically?
4 comments

I suspect, when the specification was created, "_" was already popular for private/reserved members in many programming languages. In C++, for instance, you can only start an identifier with a letter or an underscore. So it seems like a natural, intuitive choice. Whether anyone can find any corroborating evidence would be interesting.
Probably inspired by C and C++ which reserve names starting with an underscore for the implementation (more precisely, they reserve names starting with `_[_A-Z]` everywhere, and all other names starting with `_` in the global scope only).
I nice factoid: in Erlang, `_` if functional. It means "I don't care about this variable". When pattern matching you can put `_` to not bind value in function or pattern to anything or prepend a variable with `_` to tell compiler that you won't be using it, but it's there for "documentation" purposes. For example `[A|_]=List` will extract first element of list into A and ignore rest of list. Underscore has some other uses too.
Yes, many languages use `_` as a placeholder name, and at least in Rust any name starting with `_` is considered intentionally unused.
Aside: many IRC clients would auto-append _ when registering a nick if the desired nick was already registered. Why _? Who knows.
Probably because it has no specific meaning and being almost whitespace is the easiest to mentally ignore out of the set of valid nickname characters. `-` is another candidate but a programmer used to C-like languages will likely intuitively pick `_` just because it’s valid in identifiers unlike `-`.
>But why was _name the naming syntax for reserved keywords, specifically?

As with so many things in software engineering, the answer comes down to "some programmer in the 70s working on a UNIX system had to make an arbitrary decision about something, and no one ever had a good reason to change it again."

Most other characters you would use aren’t valid HTML, and originally you could say things like target=foo (no quotes) and it would work.