Hacker News new | comments | show | ask | jobs | submit login
Underscores are stupid (avdi.org)
95 points by raganwald 1709 days ago | hide | past | web | 127 comments | favorite



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 as a symbol, and he never needs to wonder whether it should actually have been “foo - bar” with spaces to separate the infix operator from the symbols representing variables.


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.


You are echoing Avdi’s point. I understand it, I just happen to disagree with it. If Lisp was an infix language, then yes foo-bar would mean something different to the parser than foo - bar because of the whitespace.

But what’s also at stake is whether that language would be readable to humans without mistakes. Part of what makes Lisp work, IMO, is that you never try to type foo - bar, so you never run into an accident by mistakenly typing foo-bar and having the parser think you meant a hitherto undefined symbol.

Whether that’s a worthy tradeoff is a matter of opinion, and I’ll take Avdi’s word for it that he believes the benefits of calling symbols foo-bar outweigh the odd time you might type the wrong thing. I’m just pointing out in addition to the “whitespace is the separator” argument you both make, there’s also the “foo - bar doesn’t mean foo subtract bar” argument.


Except that in Lisp "-number" is totally different than "- number" and I rarely have to worry about it when I code in Lisp. I code in both Lisp and Ruby on a regular basis, and I don't see the ability to write "x-y" as any real advantage. I already separate my tokens with white space by default because I see "x-y" as a single token.


"you never try to type foo - bar"

Unless you have a function called "foo", and you want to pass it the subtraction function as it's first parameter and the value "bar" as its second. In which case (foo - bar) is perfectly valid, reasonable, and completely different from (foo-bar).

Even though Lisp is not an infix language, foo-bar does mean something different to the parser than foo - bar because of whitespace.


I know that, but it’s highly incidental to my point, as I’m sure you’re aware. It’s obviously true that (foo - bar) is legal, as is (foo-bar), as is (foo - bar + bash), as is (foo-bar + bash) and so on, but they’re still much less likely to be mistaken for foo-bar in an infix language.

I’m sure you knew perfectly well that I meant you never type foo - bar meaning foo subtract bar :-)


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.


It is a special case in other languages, in lisp it is one of a very few highly consistent rules


I'd add that it also works because nobody ever says "foo-bar". What "foo" and "bar" actually are, plus context, lets the (human) reader know what's going on.

Even if I don't know what programming language you're talking about, if I see x2-x1 or margin-75 I know you probably mean subtraction, and if I see last-name or message-id you probably mean a single identifier. I've seen plenty of Lisp code that says things like x2-x1 in docstrings (because it is shorter) and I've never found it to be confusing.


Interesting that he calles dashes "ordinary, easy-to-type, recognizable, [and] visually unambiguous."

What he's referring to as a dash is actually a hyphen (-), which is pretty ambiguous when compared to the en dash (–) and em dash (—), both of which require modifier keys to type (and are frequently used in prose, to counter another of his claims). Fortunately, I've never seen em dashes or en dashes used in code.


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 were meant to be taken in that context. If he'd chosen to preempt the pedantic readers by making that context explicit, it would have only diluted the article with noise that most people would rightly assume is implied by the context.

I don't know what your keyboard looks like, but mine doesn't have en- or em-dashes on it, and I wouldn't even consider them for a programming language syntax.

[1] Even when using en-dashes and em-dashes in prose, they can often be typed with multiple consecutive hyphens, e.g., '--' and '---' in LaTeX.


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 silly. (Though I'll admit, the point of it being improperly handled with underlined fonts is certainly a valid complaint.)


I can see where that would be ambiguous. I think he mentioned using shift once or twice per sentence as a baseline for comparing how often we should have to use the shift key when coding. As for the underlining issue, the other reply already mentioned that many editors will underline code.


I don't even think my text editor [for code] supports underlined fonts.

Well, mine does, and I used to have a co-worker who actually used it for coding. So there you go. :-)


Come to think of it, I do know some editors that support HTML rendering inside comment blocks.

How would you use it for coding, though? Unless you stripped it before the compile phase I would think any formatting in a rich-text format would choke up almost any interpreter or compiler.


It doesn't need to be rich text. It can just be the way the editor does syntax highlighting. Say, for example, underline all function names. The compiler won't know anything about this style and will therefor not choke on it.


>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).


Just to clarify your clarification, that symbol is HYPHEN-MINUS, U+002D. It is in the "Punctuation, Dash" category.


That's actually not very interesting. He was talking about hyphens, but calling them dashes, because normal people do that unless they are talking about typography.


No. "normal people" call them hyphens. I think it is a mainly USian curiosity to call hyphens dashes. The Rest of the World calls hyphens, well, hyphens. It's only the US that call them dashes. I've no idea why that is.


people outside the US call them dashes as well, though perhaps not with the same frequency. ... --- ... is not 'dot dot dot hyphen hyphen hyphen dot dot dot', for example


Token English person here. I called them dashes until I moved to Japan where no-one understands what I mean if I call them dashes.


Semicolons. Underscores. Spaces. Tabs. Every couple weeks it's some new minutiae profiled as the cause of all the world's problems. Don't people have better things to focus on than this?


Some people are detail-oriented. How can you expect Mr. Grimm to obsess over corner cases in his code but shrug at what he perceives are problems with representing it?

The people who think only in terms of the “big picture” while glossing over the details are not programmers. They are “architects.”

EDIT: This second statement is probably not correct. I would use strikethrough if I could. But the first statement still rings true with me, many programmers are detail-oriented, which means that they care about lots of things other people would consider irrelevant. Whether this is, on the whole, a good thing or not is another matter. But I do not think it is surprising.


I feel that you're mostly right. However I think we all focus on different details, to an extent.

For example, I'm a great typist so the underscore key has never really bothered me.

But to call the author out on being detail oriented would be inane of me. I myself don't like keyboards that have small backspace keys. I also still hate OS X for having the window control cluster on the top-left corner.

I know I certainly get paid to think about the details. The only variable here is which details.


Specially if we take into consideration that this is country specific.

Many country specific keyboards also need modifier keys to access the hyphen.


Agreed! This really shouldn't be on HN front page.


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 code looks good, especially if I enable drop shadows and anisotropic filtering in my editor.


I like the arrow since it reminds me sometimes that I'm working with a pointer and not an object on the stack


Pointers aren't always to objects on the heap, they can be pointing to locations on the stack as well.


Right, but I don't know what you're disagreeing with since I never said that they only point to the heap.


"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.


The C type conversions I know of seem quite trivial. Can you give an example of something non-trivial? And I don't mean something like the float f = some_integer / some_other_integer trap, those should be obvious.


The automatic dereferencing in "pointerToStruct.foo" might have to loop until it arrives at a struct. I think such a loop would be unique in C, but I don't feel it'd make C any higher level.

Similar in concept: &function and function are the same. If you have a fixed-size array: ary, &ary and ary[0] are the same when passing them into a function.

Then there are all the other numeric conversions, where "unsigned" is a common trap, and truthiness.

Even if most conversions are trivial, I wouldn't call C a very explicit language. Compared to what?


pointerToStruct.foo would just be equivalent to pointerToStruct->foo. No loop required.

The main problem with this is that it hides memory accesses. The offset of x.y.z.w relative to &x can be determined at compile time, so if &x is available, accessing x.y.z.w requires roughly only one load instruction. (DISCLAIMER: ABI- and compiler-dependent. One instruction is an estimate. This estimate may not be precisely true for all possible programs across all CPUs and compilers.) But x->y->z->w requires 3 pointer dereferences, even if you have x to hand. 3 load instructions and therefore 3 memory accesses. (The same disclaimer applies.) People already complain enough about the inefficiency of C++ operator overloading, and the difficulty of spotting when it occurs just by examination of the source code...

Additionally, this change wouldn't play nicely with C++ operator overloading.

I just set up my text editors to insert -> when I press <Alt-,>.


I assumed that arbitrary levels of indirection would be flattened, hence a loop. I'm not asking for this feature, I'm only arguing that C was never explicit to begin with.

For example, you cannot tell how many indirections happen in a[5][2][8] either. Every game programmer must have seen a newbie try to cast a[4][4] into a :)


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.


Stars eaten by HN formatting:

It would be p^.foo instead of (^p).foo or p->foo. Less awkward when adding or removing one indirection level too.


Not to mention that it’s a poor approximation of the → character.


One of the most efficient everyday optimizations I've made in the past few years was to adopt the lisp-style naming convention for my local file system hierarchy. Removing all capitalization and special characters (other than the dash) makes navigating via CLI much easier. And having a predictable naming scheme means I rely on tab completion slightly less too, as I have more predictive capability regarding how I might have named things in the past. More generally, treating my home folder as, essentially, an exposed API for which I'm the primary consumer has paid dividends.


Only nerds know what underscores are? I think anybody who grew up in the early Napster/Limewire/Kazaa days knows what an underscore is because they probably downloaded a file like Michael_Jackson_-_Beat_It.mp3


And because in middle school, everyone had one in their email address and AIM screen name.


After writing a decent amount of Clojure recently, underscores do seem ugly, but I think I find commas even more annoying. I can accept underscores for the reasons raganwald mentioned, but having to write [1, 2, 3] instead of just [1 2 3] bothers me more than it probably should.


I noticed this too after using Coffeescript, going back to plain JS.

It's especially annoying when shuffling array elements or function parameter around: all items need to be separated by a colon, except for the last one, that must not have a trailing comma, making line swapping a nightmare. Drives me nuts.


> all items need to be separated by a colon, except for the last one, that must not have a trailing comma, making line swapping a nightmare

Then use a language which allows trailing commas in lists, param-lists, maps, e.g. grOOvy


I write code slower than my typing speed anyway. This sort of typing efficiency obsession leads people to use dvorak or crazy non-standard keyboards. No thanks, not worth caring about.


I don't understand why people wouldn't be obsessed with typing efficiency.

Granted you don't need to type all that fast for programming. However I do have to type full-speed when writing documentation, composing an e-mail, working on a presentation, etc.

Not to mention Dvorak and "crazy non-standard keyboards" demonstrably reduce RSI, which is a far greater benefit than typing speed. (Unless you like having disgusting chemical compounds injected into your wrists; or want your wrist cut open so that doctors can work on some of the most delicate tissues in the body.)


Yes I rather thing that the writer has a bit too much time on his hands


Maybe because he's eliminated all that time wasted by typing underscores.


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.


Yeah, you're right. I wrote without checking, I have this command in muscle memory.

:).


"the stretch"?

Properly typing an underscore should utilize two hands and shouldn't require a stretch at all.


It moves your pinky, your smallest and least mobile finger, to move up two rows, which requires a typical person to completely flatten that finger. Either that, or you end shifting your whole hand. Which means that you end up moving your hand a lot while typing because the underscore may easily be the most common keyboard character encountered in some programs.


Obviously everyone has different shaped hands - but for me, the pinky doesn't need to be entirely flat to reach the underscore. I also don't have to shift my whole wrist.

Either way, reaching the + key on QWERTY-102 is objectively more difficult than the underscore [uses the pinky, is farther away than the underscore from homerow], and also requires a shift-modifier. I use + far more than _ while I'm coding. (And I'm currently writing most of my code in Go, so I use _ quite a bit since it's a blank identifier.)

Maybe I just have big hands, but it honestly doesn't impede my typing at all to add an underscore to the text.


Writing almost exclusively in a underscore-encouraging language like Python has numbed me to these issues.


With me as well, though it is getting slightly annoying to the people I work with that it's been transferring over into some of the PHP code I have to write.


It's not as if underscores aren't used liberally in the standard library. Which is probably a hangover from C.


In Dvorak, the underscore key is where the apostrophe is in QWERTY, just to the right of your pinky. Nice little upgrade.


Yes, but it still requires SHIFT + - to get the underscore.


"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."

There are languages that survive in spite of the heavy use of uppercase letters, without useless complains like this.

Let me repeat, in German:

"Es gibt Sprachen die trotz starker Nutzung von Grossbuchstaben ueberleben, ohne ueberfluessige Beschwerden wie diese."

Damn, I just broke my pinky..


>> "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."

That passage sticks out to me as well. Especially the "Awkward. Inefficient" part.

Maybe the guy needs to learn how to type, because hitting shift for me is muscle memory that requires no thinking. That Grade 9 typing class in 1984 just continues to pay dividends for me.


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.


Hate to break it to him, but parentheses require hitting the Shift key as well. Twice.


Yeah and that's pretty horrible too...


Any time I have some feelings, I try to clean up the emotions and use my reason. Underscores solve a lot of problem and are useful in technology and programming and then suddenly i_love_underscores.


Really just a matter of convention, and dash is too heavily associated with minus. A single underscore is a permissible variable name in some languages; in Go it has a special meaning (blank identifier). Would a single dash be as well? For example, how would you interpret

    i - -
	
Is it i (minus) (variable named dash)? And is `i--` a legitimate variable name? Maybe Ruby doesn't have this construct, but then it would have a completely different naming contention from existing languages.


Favouring dash over underscore to break words in variable names doesn't preclude using underscores in variables names ever.

A sometimes used _ is okay. Its_using_it_almost_all_the_time_that_the_author_is_questioning.


> 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 that some things could be more efficient, but "hitting shift" hardly qualifies in my opinion...


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.


>> I understand that some things could be more efficient, but "hitting shift" hardly qualifies in my opinion...

I does qualify as something that probably contributes to Repeated Strain Injury which most programmers should worry about.


Actually I think there is a speed and comfort issue relating to any symbol that requires key chording. To test this try using sticky keys for a while - it's much more comfortable - it seems to free up the fingers more.

I use alternate hands when using the shift key, so that's not the issue. Perhaps it's just that I've got into a bad habit of depressing the shift key with a little more force and holding it for longer. With sticky keys I seem to dance off the keys better.

If you have a number pad, perhaps it might be better to switch the number row with the symbols (i.e. don't use SHIFT to get to the symbol.) I think that's the default for French layouts.


It’s odd that the author does not mention the truly ridiculous thing about underscores: they are a holdover from typewriters, where they were used to provide underlining by overstriking. The fact that we now have beautiful proportional-width screen fonts that support underlining—and do not generally support overstriking—makes underscores unnecessary.

And yet we insist that a programmer be able to write every modern programming language on a 50-year-old typewriter. You know, just in case.


Damian Conway provides some excellent insight/advice on underscores vs hyphens:

  Personally, I'd prefer to see the English conventions carried over to
  the use of general use of hyphen and underscore in identifiers in
  the core (and everywhere else).

  By that, I mean that, in English, the hyphen is notionally a
  "higher precedence" word-separator than the space
  (or than its intra-identifier stand-in: the underscore).

  For example: there's an important difference between:

      initiate_main-sequence_detonator_phase()

  and:

      initiate_main_sequence-detonator_phase()

  The former initiates the detonator phase for the main sequence;
  the latter initiates the main phase of the sequence detonator.

  More simply, there's a difference between:

       $obj1.set_difference($obj2);

  and:

       $obj1.set-difference($obj2);

  The first is setting a difference; the second is computing a difference-of-sets.

  The rule I intend to use and recommend when employing this new
  identifier character in multiword names is that you should place an
  underscore between "ordinary unrelated" words, and a hyphen only
  between a word and some modifier that applies specifically to that word.

  Which, if applied to Temporal, would lead to:

      my $now = DateTime.from_epoch(time);

      The C<day> method also has the synonym C<day-of-month>.

      (These are also available through the methods C<week-year> and
      C<week-number>, respectively.)

      There's a C<day-of-week> method,

      The C<weekday-of-month> method returns a number 1..5

      The C<day-of-quarter> method returns the day of the quarter.

      The C<day-of-year> method returns the day of the year,

      The method C<whole-second> returns the second truncated to an integer.

      The C<time-zone> method returns the C<DateTime::TimeZone> object

  (i.e. only C<.from_epoch()> actually uses underscore).

  Oh, and the optional C<:timezone> argument to C<.new()> should probably
  become C<:time-zone> for consistency with the C<.time-zone()> method
  (or, preferably, we should jut bite the bullet and go with C<timezone>
  throughout).

  Damian
From Perl6 mailing list: http://www.nntp.perl.org/group/perl.perl6.language/2010/04/m...


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) #<= the meaning of life
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.


I don't really like underscores either. Leading underscores to mark member variables? That looks weird. A trailing underscore? Ugh, even worse because you can't use code completion to find all the member variables.

With that said, who cares? Don't use them if you don't want to. It might be more inefficient, but typing speed has never been the thing that slows me down while I'm writing code.


As a daily python user at home and at work, I realized I'm typing a huge amount of underscores. My keyboard supports rebinding keys and programming macros (a feature I've never used until now) so I remapped an extra \ key on it so that it would type _ without me holding shift. Small change, but it's much less of a strain.

(I'm using a Kinesis Advantage keyboard.)


This may solve your problem:

    my.long.name = 1
    a.short.name = 2

    one.long.result = a.short.name - my.long.name

    one.string:trim:upper
Use dots for identifiers and colons for class props and methods.

Now we just need to design a whole new language :(


Using dot as a name separator is actually the convention the R programming language, so it's certainly not a new idea. Ironically, it used to be the case that R did not allow _ as a variable character.


At least on a US keyboard, colons require the shift key, too.


Cleanse those colons!


I've got a feeling that HN crowd is lately loosing it's focus by spending it's time on "hipster" topics too much.

Page long commenting on a fluffy article ( e.g "5 * 5 - 3" beats "5*5-3" ) may be good for your mind but imho, this thing should not be on the front page.


Maybe it's just me, but I never notice issues like this. Some people want to completely optimize their experience, like when Vim users tell me it's better than Emacs because they don't have to reach for the cursor keys.

I dunno. For some reason this super-optimisation of keystrokes doesn't bother me. Avoiding reaching for the mouse is good, but I don't particularly care if I have to hit shift.* Maybe I prefer to think more and type less, or something. I can't quite say.

* Admittedly the French keyboard where all numbers in the top row are shifted, and symbols are unshifted, drives me kind of crazy, but that could just be due to hard in-grained training on an American keyboard layout.


It's like the difference between wearing silk underwear and hessian underwear. Or being able to code while listening to an audio book vs needing peace and quiet. It's not a question of thinking less, or thinking more, or being more careful. Some people can put up with this stuff, and some people can't.


Underscores are silly! We only use them in code to separate words in tokens because the default natural word separator, whitespace, is already used to distinguish tokens.

At my old job, we had DSL that allowed and encouraged very descriptive variable and procedure names with space in them. To implement this unambiguously the language had to exclude all the operator characters from variable names and procedure calls with a sigil. A line of code may have appeared like this:

line slope estimate = @some function( x - step size ) / ( x - step size);

Feels a bit strange at first but quickly becomes natural, especially when dealing with wordy domains (math was a bad example).


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.


disagree. like_underscores. concerns about using shift key seem misplaced & for those who have some form of birth defect that prevents use of two fingers simultaneously, keyboard remapping is easy.


I like 'em, too. What terrible ordeal that we must push the shift bar while typing.

Honestly, I've always found them to be more human readable than CamelCase.


Modifier keys cause strain that can lead to RSI.


I think the interpunct should be revived and used as a character allowed in identifiers. (http://en.wikipedia.org/wiki/Interpunct)


Bravo!

Also underscores in uri strings look awful.

this_uri_is_ugly.html

vs

this-uri-is-pretty.html

I wish python allowed for dash in its script names... cannot import from module-test.py but I can from module_test.py

Thank you for posting this, I "laughed-out-loud".


The reason page uris aren't so good with underscores, is that you can loose them if they are displayed underlined as links.


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.


This would drive me bonkers. For some reason I've never been able to hit the spacebar on the left side.

(I mean, it's not like I'm physically incapable. I just instinctively hit SPACE with my right thumb.)

Getting used to using my left thumb would just be awkward.

I also have a nasty habit of using the LSHIFT exclusively. Even when it's not technically appropriate to do so.


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


The Kinesis Advantage keyboard effectively does this, except the left half is for backspace. Since it has very conveniently placed modifier keys like ctrl under my thumbs, I remapped capslock to shift so that it's on the home-row.


I think the left side is more suited for backspace. Which is how my Compaq keyboard is setup - the key is physically divided into two.

Perhaps the spacebar is just too big, and could be divided better into other modifiers. My left thumb is usually wasted (though not on a Mac, where the thumb can easily reach the Command key.)

Some people however - seem to alternate thumbs on the spacebar - or rather use the other hands thumb to the hand that just typed a character. I personally always use the right thumb to space.


I've been thinking about trying to find a reasonable way to map the underscore to shift+space, but I'm not sure if that would somehow break some application that expects otherwise. It also seems to be quite difficult to achieve on Windows without registry hacks (I presume it would be easier on Linux, but haven't tried it yet).


It's very easy on Windows with the strange and wonderful AutoHotkey [1]. I recommend the more advanced AutoHotkey_L fork [2], but this script should work in either version.

Install AutoHotkey and then create a file called Underspace.ahk with this content:

    ; Underspace for AutoHotkey
    ; Converts Shift+Spacebar to underscore

    #SingleInstance force

    +Space:: Send _
Now launch that file.

Try Shift+Space and it should type an underscore for you.

If you want to stop the script later, find a green "H" in your system tray and right-click it.

After you try it, I'll be curious how it works out for you. Myself, after trying it for just a minute or two, I'm not so sure if I like it. I'm finding a lot of spurious underscores before capitalized words, or after a word like "I" that ends with a capital letter. That's because I've been sloppy about the timing of when I press the Shift key before or after a space.

So I won't be using this script myself (not that I need it - I don't like to code using names_with_underscores) but maybe others will find it useful.

[1] AutoHotkey home page: http://www.autohotkey.com/

[2] AutoHotkey_L: http://l.autohotkey.net/

(minor edit for clarity)


This tool looks really cool. I see what you mean about the spurious underscores... think I'll try it out for a day and see whether or not I can live with it. Thanks!


> That’s a trade-off I’ll gladly make if it means using dashed identifiers instead of underscores.

Not me. I would gladly trade off having to expand all my equations for having to type underscores a few times. In fact, this is very subjective - and one could argue having to sacrifice compactness of expressions is stupid.


  All you have give up for this is tightly-packed arithmetic statements, like this:

    5*5-3

  Instead, you have to give your tokens some breathing room:

    5 * 5 - 3
I don't know, that seems pretty stupid too.


and gets even worse if you bring variables into the game.

a = 5

b = 3

everybody from nearly every programming language would expect that after

c = a-b

you will find c to be 2 not nil (or throwing an exception or whatever)


I never pack my code like that without whitespace, as doing so is only readable when you have single-letter variables, which is not very common.

I agree with the OP. CamelCase and underscores are both scourges.


I've always found code without spaces around these symbols to be very undreadable.


Yes, but in this case it's not about readability, but about extremely significant whitespace. Forgetting a space and your code has a totally different meaning.


Whitespace is already extremely significant in programming. "foo[1]" vs "foo [1]" for example.


Depends on language, in Ruby those statements would be identical. But anyway, that's no reason to make things even worse.


In Ruby those statements are the same when foo is bound to an array, but they are different when foo is bound to a function...


And I have found the opposite. Horses for courses.


I for one love it when someone types whole paragraphs about the desire to avoid keystrokes. Every language has it's irritating quirks, none of which do I care enough to write about.


Idiomatic REBOL code avoids the shift key for its commonest syntax. Code grouping (where necessary) uses '[', ']'; multi-word variables are separated by '-'; etc.


I use case instead of underscore. Doesn't help the shift-issue, but reduces the length of identifiers e.g. file_not_found becomes FileNotFound.


IThinkItIsObjectivelyMuchLessReadable

I_think_it_is_objectively_much_more_readable

The difference in length is pretty small anyway.


That's a bit contrived considering you're (a) writing a sentence and (b) you use some really short words (i.e., "I", "It", and "Is"). I think for things like FileNotFound or similar its not really that different in readability, and comes down to preference.


You get used to anything. For instance, I find your 1st example much more readable, but I've been doing it for years.

Names tend to be pretty small anyway. Here are some random ones from the code I'm working on (Sococo Teamspace)

CreateVariant - a method

soLogWriteInfo - a method (I didn't write)

clHeadSSt - a circular list head for a stream


So the problem is not the underscores but the many shift keystrokes which is a valid point. The solution is to refactor the keyboard layout.


A bit late in the wagon, but have a look at http://pogoscript.org/


I see them as the next best thing to having an actual non-breaking space, why all the hate?


Truly find-file is much more readable than findFile. IMHO. Also directory? vs isDirectory


Switch to a Japanese keyboard - none of the @ _ ; or : characters require the shift key.


Try binding shift-space to underscore. You'll start to feel much better about it.


Sorry, but when I read this article I was just thinking that some people seem to have just too much free time...


Don't worry about underscores being difficult to type, just use a more ergonomic keyboard layout: http://bitbucket.org/cheater/us_split/overview

It's just like qwerty, but with less pain.


I program in Underscore, you insensitive clod!




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: