Live data from Hacker News

Underscores are stupid

devblog.avdi.org

81–90 of 131 posts

Re: Underscores are stupid

#81
post #58

> Underscores require me to hit the Shift key. When writing prose, I only hit the shift once or twice per sentence. In Ruby, I have to hit the shift key every few letters. Awkward. Inefficient. Oh my, oh my, how do people ever cope with that vile "having to hit shift" that have regular capitalisation of all nouns etc. Surely such a thing is impossible, as is hitting shift when you need an underscore. I understand tha…

I wonder how the author types all the brackets in LISP without the shift key. I'll take an occasional underscore over that mess any day.

[deleted]

Re: Underscores are stupid

#82
My only problem with underscores is that when I read them aloud in my head, I hear a longer pause than for a hyphen, so code with lots of underscores takes longer to read, or at least feels like it does.

Re: Underscores are stupid

#83
post #51

What colour do you want your bikeshed painted today? I for one, don't like the "->" operator in C. It requires two characters and the use of the shift key. I would like that the next standard just used "." for all member access and let the compiler work its magic and guess what needs to be done. Of course that would break a sizeable amount of legacy code, but who cares about that anyway. The important is that the cod…

I know you're being sarcastic, but since you bring it up, I think the -> operator in C(++) is awkward as heck. If dereferencing were a suffix operation as in Pascal, you could simply write p.foo instead of (p).foo.

I guess it'd break because of (a* +b) but that's just all the more reason to disallow whitespace around infix operators.

Re: Underscores are stupid

#84
For what it's worth, Perl 6 allows dashes in identifiers, and many of us working with the language have gleefully taken to using them instead of underscores. I can't tell you why it makes a difference, but somehow underscores now feel clumsy/ugly to me, despite two decades of happily using them in my C++ code.

Re: Underscores are stupid

#85
post #68

This misses one point when comparing Lisp to languages like Ruby. Lisp does not have infix notation. Therefore, you never have to worry that "foo-bar" (the symbol) could ever be confused with "foo - bar” the operation subtracting bar from foo. That’s because in Lisp, foo-bar is written "(- foo bar).” Since a Lisp programmer spends all his time writing "(- foo bar),” when he sees “foo-bar,” his brain easily parses it…

I don't think this has anything to do with infix versus prefix. It works in Lisp because the reader knows (roughly speaking) that symbols are terminated by whitespace or parentheses. If you wrote a version of Ruby that was still infix but where you needed to put spaces around all symbols, then "foo-bar" would work fine there, too.

Such rules ("all operators must be space-hugged") are special cases, and I think raganwald's point is that such special cases make at-a-glance mental parsing more difficult. Lexing and parsing in Lisp is much more straightforward than in, say, Python. Hence, mental lexing and parsing has fewer barriers. This is a direct result of using s-expressions, which implies no in-fix operators.

Re: Underscores are stupid

#86
post #5

I think they should make keyboards with the spacebar divided, and make the left half (or I guess the right if you're left-handed) into a shift key.

Some Japanese keyboards do this. Tiny spacebars and extra modifier keys. I've always wanted to buy one and put keys like backspace and delete on my thumbs.

Japanese ThinkPad USB keyboard (with TrackPoint!): http://i.imgur.com/4dWVJ.jpg

Re: Underscores are stupid

#87

There's an easy fix for part of the problem: bind shift-space to underscore. Yes, you still require shift, but IMO it's the stretch not the shift that makes typing an underscore jarring. xmodmap -e 'keycode 65 = space underscore'

Unless you use Emacs (as the author seems to), in which case you have S-Space bound to starting/ending selection. But in general yes, one can rebind underscore to something that doesn't require pressing Shift.

That's C-SPC.

Re: Underscores are stupid

#88
post #78
post #51

What colour do you want your bikeshed painted today? I for one, don't like the "->" operator in C. It requires two characters and the use of the shift key. I would like that the next standard just used "." for all member access and let the compiler work its magic and guess what needs to be done. Of course that would break a sizeable amount of legacy code, but who cares about that anyway. The important is that the cod…

"let the compiler work its magic." if you want that, use a higher level language. One of the foundations of C is that there is as little implicit behavior as possible. I'd hate to be left in the dark whether my . will now result in a pointer or a dereferenced value and I doubt it would even work for the compiler to figure this out in all edge cases.

C is full of implicit type conversions. I think the key is that C is based on value semantics and not references, and that makes pointers full-blown values with their own address, conversions, … - something closer to C's integer types than to other languages' references, and equally picky about operators.

Re: Underscores are stupid

#89
While I agree with the sentiment, I have two points:

1) The goal of a programming language is to be as unambiguous as possible. This is why we have syntax, and do not program in english. As soon as you use the same token identifier for two purposes, you introduce ambiguity.

Take markdown, for example:

    * Hello *world*
In this line of code, which asterisk should be considered a bullet, and which an indication of emphasis? It seems obvious to a human, but codifying it in a set of rules for a computer is another matter, which introduces complexity and future bugs. (Eg., what do you do in this situation: `* Hello* world`. As somebody who is writing a full formal lexer for markdown, I can tell you first hand that it's an extremely annoying part of the specification.)

Lisp does not have this problem, because it is governed by an extremely simple and effective set of rules:

- An identifier can contain most unambiguous special characters, including - ! ? / + = etc.

- There are no operators, only functions.

- A hyphen by itself is a perfectly valid identifier.

- The standard library includes a function named hyphen which performs a subtraction operation.

Taking that into consideration, it makes the entire situation completely ambiguous. `a-b` is one identifier. `a - b` and `- a b` are both a string of meaningless identifiers. `(a - b)` performs function `a` with arguments `-` and `b`, and `(- a b)` performs function `-` with `a` and `b`.

Ruby is actually interesting in that it is one of the few languages which, like lisp, does not have operators. You could remove ambiguity by doing `a.-(b)`. However, readability immediately goes out of the window. Much more so than in lisp's case. Consider this:

    (4.*(5)).+((7.*(9))./(3)).+(1) #
It's semantically a perfectly valid expression, but how long did it take you to mentally evaluate it to 42? Compare with:

    4*5 + 7*9/3 + 1
2) If you're going to be writing an article about it, please learn the right terminology. - is a hyphen. Dashes are – (en-dash) and — (em-dash). Hyphens separate contracted words. En-dashes indicate a range. Em-dashes indicate a aside, much like a parenthesis.

Re: Underscores are stupid

#90
post #65

Earlier quoted context omitted.

He's discussing this in the context of writing code, not typography. I think it's fair to assume we're starting with the premise that we would only choose characters that are easily typed on common keyboards. Choosing uncommon characters in programming languages, such as en-dashes and em-dashes, is choosing to deliberately make our lives more difficult [1]. I think it's pretty clear from the article that his comments…

Well, the author himself is pretty ambiguous. While most of the article talks about code, the author mentions underscores being ambiguous in the context of underlined fonts. (I don't even think my text editor [for code] supports underlined fonts.) He also mentions only using shift once or twice per sentence when writing prose. So it would seem that the author is just hating on _ in all contexts. Which is kind of sill…

>While most of the article talks about code, the author mentions underscores being ambiguous in the context of underlined fonts. (I don't even think my text editor [for code] supports underlined fonts.)

Lot's of editors do. In Eclipse, for one, it's common to see function names and such shown as hyperlinks when you click on them (with underlines), which makes their definition open (like a function call is "linked" to the function definition).

Post reply on HN