Re: missing out braces

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
news:MPG.1e657006cd19d78698ce84@xxxxxxxxxxxxxxxxxxxxxxx
Mike <vimakefile@xxxxxxxxx> wrote:

<snip>

Personally I'd be happy with the braces being compulsary.

To me something being compulsary syntactically is a prime pointer to its
lack of necessity - if it *has* to be there, the compiler should figure
it
out. (I will conveniently omit all cases to the contrary...)

That would be fine if the only thing which read code was the compiler.
However, it's not - there's the reader, too.

There's no *need* for the colon between the name of a class and the
interfaces it implements or its base classes, nor the commas between
those. For instance, you could have:

public class Foo BaseClass ISomeInterface

Similarly there's no need for commas between parameters:

public void Foo (int i long j string x)

I'm jolly glad both of those exist though - the above are both
nightmares to read.

For me, braces add to readability - they mean that things *can't* get
screwed up just because of indentation, and I can use indentation to
make things more readable, breaking up lines and lining things up in
places which look better to *me* rather than to the compiler.

Yes, but you can always indent such that the indentaion does not match the
true nesting. (Although that's harder to do these days.)

The braces thing is a personal issue, but I hope you see my point about
the counter-examples to your general suggestion :)

Sure I do - hence my comment:
I will conveniently omit all cases to the contrary...

I'm not sure about your slippery-slope argument about the colon and commas
above -- I certainly agree that these items shoud be there for readability.
That fact that I use mainly C# and not Python for most of my projects shows
I'm not religious about this issue, but in this case I think Python has the
edge on readability.

Consider:

if ( minute >= 0 && minute < 60 && second >=0 && second < 60)
{
foo(1);
for each ( int e in coll)
{
bar(e);
}
}

vs.

if 0 <= minute < 60 and 0 <= second < 60:
foo(1)
for e in coll:
bar(e)

Python, by not needing braces and statement seperators, not strickly
requiring outer parens, and handling the inequality nicely seems really easy
to read to me (in addition to taking up less room), and there's really no
mistaking what's going on with the indentation.
On the other hand, there's not quite enough sugar around its
object-orientated features, IMHO.

But luckily, the smart editor's have really rendered most of this moot...

m


--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


.



Relevant Pages

  • alternatives to making blocks like { } or other ??
    ... > But here if there were braces, ... If you were writing in Python the logic would be right also. ... > doesn't meet our coding standards, yet there's no way for the compiler ... > the indentation! ...
    (comp.lang.python)
  • Re: ANN: Dao Language v.0.9.6-beta is release!
    ... of the ACM on research into readability back in 1984 or so, that indicated 2-4 spaces has very similar readability and 8 spaces significantly less than that. ... I switched from using 2 to using 4 spaces for Python recently, and the big pain was to deal with lines that no longer fitted in 80 columns :-( ... smaller indentation allows you to use more indentation levels without using up all of your line width. ...
    (comp.lang.python)
  • Re: missing out braces
    ... screwed up just because of indentation, and I can use indentation to ... harmful whitespace can be to getting things right, ... I'm not religious about this issue, but in this case I think Python has ... edge on readability. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Allowing Arbitrary Indentation in Python
    ... Python's indentation rules (http://greatbiggary.livejournal.com/ ... level of readability). ... Python language being "more readable" ... The question that interests me more is how much power Python ...
    (comp.lang.python)
  • Re: missing out braces
    ... That would be fine if the only thing which read code was the compiler. ... braces add to readability - they mean that things *can't* get ... screwed up just because of indentation, and I can use indentation to ... The braces thing is a personal issue, but I hope you see my point about ...
    (microsoft.public.dotnet.languages.csharp)