Richard Walter on Thu, 29 Jul 2010 09:22:48 -0700 (MST)

[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [game-lang] Language Syntax

--- On Wed, 7/28/10, Simon McGregor <londonien@xxxxxxxxx> wrote:

> > As Joel already said, meaningful whitespace is pure,
> > unadulterated evil.
> Right, so no '//'-style single-line comments. Understood!

'//'-style comments are ok, but only if they're not meaningful... :)

> No! They make newline whitespace meaningful, which is evil! :-P


> > The way that Python forces you to layout your code is
> > not always the best for readability; judicious use of
> > whitespace and delimiters, when properly formatted help
> > readability rather than hinder
> > it.
> Interesting. I can imagine this is true, but in the sorts
> of code I write, I've never come across it.

I can't speak to your poor coding skills... :) :) :)

> Did you have any examples in mind?


a) if (a==0 && b==1)
b) if (a == 0 && b == 1) 
c) if ((a == 0) && (b == 1))

I would rank in increasing order of better readability.

I expect that you think that option c is unnecessarily delimited with extra ()'s, but when scanning code, I don't want to have to worry about order of precidence between == and &&.  I find the extra ()'s to add clarity in this case.

And, when tests get really long, then this is better than c:

  if ( ((a_addr[31:0] == 32'h1234_5678) &&  write_enable && light_on) ||
       ((b_addr[ 7:0] ==  8'h       1c) && !write_eanble && light_on) ||
        (catastrophic_failure && doom && gloom && end_of_world) )

(those lines require 72 characters, so hopefully they don't get mangled and wrapped by email software.)

Note also that the later lines are indented further in to line up with the earlier lines in the comparison.

Similar blocks of code with variables of different lengths also can be better aligned with whitespace:

  num_players = 3;
  game_phase  = BIDDING;
  happy       = 0;
  sad         = 0;
  light_on    = 0;

The bottom line, for me, is that I can appreciate the logic and clarity that indention syntax can theoretically provide.  But the real world intrudes and, in practice, it can be more of a hinderance than a help, especially in the places where you are trying to add clarity by placing things in specific locations.

And, not to add fuel to the fire, but I'd hope that from a language standpoint:
   - tabs & spaces are indistinguishable.
   - no column width limitation.

There may be good style reasons for an individual to code in a certain way, but the language should not mandate their use.


game-lang mailing list