(fwd) Re: [R] the underscore ("_") in variable name

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Oct 3 15:00:31 CEST 2000

> From: dmurdoch at pair.com (Duncan Murdoch)
> Date: Tue, 03 Oct 2000 12:31:32 GMT
> On Tue, 03 Oct 2000 10:55:28 +0000, Alberto Murta <amurta at ipimar.pt>
> wrote:
> > And objectively, it's a fact that "<-"
> >makes the code easier to read than "_".
> I don't follow this argument.  Underscore isn't used anywhere else in
> the language, so when you see one, you know it's an assignment.  On

Only if you can see it!

1) The underscore character is designed for underlining, not to be
seen on its own.  So it is often feint, and it is below the natural
eye scan line of a line of text.  It's easy to miss.

2) People do insist on using no spaces, and underscore is widely used
as a word-separator in other languages (and some editors highlight
accordingly).  C programmers (but not the minority Pascal ones, I
guess) read word_another_word as a single name.  People can't readily
unlearn this for one language whilst still using it for another.

So I agree with Alberto: it is easier to *read*, that is easier for the
eye-brain pattern recognition system to tokenize.

> the other hand, both "<" and "-" have multiple other uses.  This leads
> to lots of possibilities for confusion:
>   x <--5 
>   x < -5
>   x <- 5
> are easily confused, whereas
>   x _-5
>   x < -5
>   x _ 5
> are not.

No problems if your space key is actually working and you know
how to use it and (I suppose) care about communicating to your audience.  

> (Of course, I actually prefer the Pascalian :=, but I realize that
> puts me in a double minority :-).

My main objection is to the use of _ without spaces.  Every week or
so I misread a post on R-help or S-news because the code is lacking
spaces and I parse it wrongly, and I know I am not alone from the 
frequent remarks from other readers.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list