[bitc-dev] Opinions wanted: Infix shift operators

Ian P. Cooke ipc at srand.net
Wed Jul 28 08:34:56 PDT 2010


On Jul 27, 2010, at 6:35 PM, Jonathan S. Shapiro wrote:
> There are three possible "fixes" for this:
> 
>   1. Adopt the convention used in C++ that you need to put spaces
>      between closing angle brackets when they occur doubled up in
>      this way. I have always hated this convention.
> 
>   2. Replace >> and << with some other, similar, lexical symbol.
>       Perhaps >=> and <=<.
> 
>   3. Introduce a parser hack, in which the *expression* parser
>      accepts "a" "<" "<" "b" as a shift operation, but warns
>      if the two "<" symbols are separated by white space.
> 

I can see there are a lot of replies already but I'm responding before reading those as I want to express my "gut reaction" on this.

I believe that answer '1.' is correct.  Whitespace is significant.  I know it's convenient to have "smart" parsers that resolve ambiguity in the absence of whitespace but I consider that approach to be a hack for lazy compiler users (and overzealous compiler creators).  The text of your program should be meaningful to another another person familiar with the syntax.  Therefore your answer should reflect that position and select the choice that most effectively communicates your meaning to another person, not to the compiler.  Idon'twritesentenceslikethisbecausewithoutwhitespaceyouhavetoworktoohardtogetmymeaning.  

Other kinds of authors use whitespace to increase the chance that a reader will comprehend their meaning,  why shouldn't programmers?

Carried to the extreme this would force us to write expressions like 'a = 1 + 2' instead of 'a=1+2' but is that truly a bad thing?  I'm undecided in that case but reasonably certain that in the presence of ambiguous text, whitespace is the right way to clarify meaning.

-ipc


More information about the bitc-dev mailing list