Braces vs indent vs "end ..." syntax preference

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

What's the best syntax

Braces
27
51%
Indent
19
36%
"end..."
7
13%
 
Total votes: 53

Nyktos
Posts: 138
Joined: Mon Mar 02, 2009 4:02 pm UTC

Re: Braces vs indent vs "end ..." syntax preference

Postby Nyktos » Sat Feb 28, 2015 7:23 pm UTC

ucim wrote:But in the meanwhile more code is visible in the window, which is a good thing.
I agree. It's annoying when less code fits on screen because a fifth of your lines are just "end" or "}".

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Braces vs indent vs "end ..." syntax preference

Postby EvanED » Sat Feb 28, 2015 8:19 pm UTC

ucim wrote:And if you copy tabs, sometimes you get spaces. And while you could work around it by going through extra trouble to prohibit tabs, or ambiguity, avoid certain text editors, or whatnot, that's extra trouble that invites more extra trouble.
I admit that this is, to some small extent, a drawback. But I do have done a fair amount of Python programming for the past few years, and the number of times that I have been confused between spaces and tabs is approximately zero. In my experience the bigger problem is forums or mailing list viewers that collapse whitespace, and even that is pretty rare.

ucim wrote:You replied to my indent example that you could do

Code: Select all

if condition: do this
if another condition: do that
if a third condition and a fourth condition: do something else
but this does not use indents. I suppose it relies on the start of a line to end the if statement, but if you need to reformat or reflow (to view in a narrow window) the visual information is lost.

It's not impossible. Just inferior.

... I was replying to this part:

ucim wrote:They also have the (slight) advantage that I can clearly code some simple things on one line, that would otherwise be less clear:

Code: Select all

if (condition) {do this}
if (another condition) {do that}
if (a third condition && a fourth condition) {do something else}


which is compact, clear, and unambiguous.

With indent (which I'm not sure how to show without an ugly code block), one is forced into:

Code: Select all

if (condition)
  do this
if (another condition)
  do that
if (a third condition && a fourth condition)
  do something else
Which demonstrably isn't true because, as I pointed out, you can write the same thing that you can in C in Python and you're not forced into a version with multiple lines.

Compare:
you wrote:if (condition) {do this}
if (another condition) {do that}
if (a third condition && a fourth condition) {do something else}

and
I wrote:if condition: do this
if another condition: do that
if a third condition and a fourth condition: do something else


Now, maybe I should have quoted all of that, but I also thought the context would have been clear.

User avatar
ucim
Posts: 5497
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Braces vs indent vs "end ..." syntax preference

Postby ucim » Sun Mar 01, 2015 2:12 pm UTC

Perhaps it's just my unfamiliarity with Python (which probably should get me banned from the forum :) ) but I thought that "indent required" required indent. But yes, under the looser "indent not required, but carries meaning" standard, what you did would be fine. If that's what it means to use syntax-containing indents, then I withdraw that objection.

The other (that spaces and tabs are both invisible, but carry different syntactical meanings) stands.

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

Derek
Posts: 2136
Joined: Wed Aug 18, 2010 4:15 am UTC

Re: Braces vs indent vs "end ..." syntax preference

Postby Derek » Sun Mar 01, 2015 10:21 pm UTC

ch*rp in the mustard

What is this supposed to be? The only word I know with this pattern is "chirp", which does not need to be censored, and "chirp in the mustard" is clearly not a thing based on Google results. I also can't see any word that could be misspelled into that form. In fact, the only result that appears relevant for "in the mustard" at all is an urban dictionary entry for "mouse in the mustard".

User avatar
Flumble
Yes Man
Posts: 1938
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Braces vs indent vs "end ..." syntax preference

Postby Flumble » Sun Mar 01, 2015 10:47 pm UTC

Derek wrote:
ch*rp in the mustard

What is this supposed to be? The only word I know with this pattern is "chirp", which does not need to be censored, and "chirp in the mustard" is clearly not a thing based on Google results. I also can't see any word that could be misspelled into that form. In fact, the only result that appears relevant for "in the mustard" at all is an urban dictionary entry for "mouse in the mustard".

It's a Time thing. You wouldn't understand. :roll:
For full demystification: "ch*rp" and "mustard" are frequently used character sequences in the Time subculture. The meaning of the strings is almost completely fluid and you'll have to guess based on context what is meant. In fact, you could say that chirp and mustard by themselves don't carry any information except for the space they fill (like "ch*rp in the mustard" in the context of annoyance is likely a transformation of "pain in the ass"). But we'll leave that for linguistics thread.


Anyway, I quite like indentation. I got to know it through learning Haskell (unlike Pythonists), but the debate in that language shifts to: when do you indent and when do you make a (same-level) new function?

User avatar
Quercus
Posts: 1548
Joined: Thu Sep 19, 2013 12:22 pm UTC
Location: London, UK
Contact:

Re: Braces vs indent vs "end ..." syntax preference

Postby Quercus » Sun Mar 01, 2015 11:39 pm UTC

Flumble wrote:
Derek wrote:
ch*rp in the mustard

What is this supposed to be? The only word I know with this pattern is "chirp", which does not need to be censored, and "chirp in the mustard" is clearly not a thing based on Google results. I also can't see any word that could be misspelled into that form. In fact, the only result that appears relevant for "in the mustard" at all is an urban dictionary entry for "mouse in the mustard".

It's a Time thing. You wouldn't understand. :roll:
For full demystification: "ch*rp" and "mustard" are frequently used character sequences in the Time subculture. The meaning of the strings is almost completely fluid and you'll have to guess based on context what is meant. In fact, you could say that chirp and mustard by themselves don't carry any information except for the space they fill (like "ch*rp in the mustard" in the context of annoyance is likely a transformation of "pain in the ass"). But we'll leave that for linguistics thread.


I'm somewhat surprised that no-one has written a sociology dissertation on that thread yet.


Oh, and as for syntax, I like indentation, but then I've well and truly drunk the Python kool-aid (it saved me from that god-awful monstrosity that is Perl).

User avatar
ucim
Posts: 5497
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Braces vs indent vs "end ..." syntax preference

Postby ucim » Wed Mar 04, 2015 12:56 am UTC

Chirp is one of the strongest curse words on the One True Thread; it means (both literally and as an epithet) "fuck". Mustard is anything gone wrong, usually horribly wrong. It is also used as an epithet, though a milder one, and is non-profane in its literal meaning of a screwup, so doesn't need to be censored.

Yes, words are overloaded in Time.

Quercus wrote:I'm somewhat surprised that no-one has written a sociology dissertation on that thread yet.
It was recently the subject of a scientific conference (on sustainability) in Germany. Although it also served as a meetup, it will probably spawn other serious investigations as time goes on. Wait for it.

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Braces vs indent vs "end ..." syntax preference

Postby ahammel » Thu Mar 05, 2015 7:13 am UTC

ucim wrote:Perhaps it's just my unfamiliarity with Python (which probably should get me banned from the forum :) ) but I thought that "indent required" required indent.
I have never heard of a language in which indentation is the only way to delimit statements.
He/Him/His/Alex
God damn these electric sex pants!

User avatar
WanderingLinguist
Posts: 230
Joined: Tue May 22, 2012 5:14 pm UTC
Location: Seoul
Contact:

Re: Braces vs indent vs "end ..." syntax preference

Postby WanderingLinguist » Fri Mar 06, 2015 12:07 am UTC

Since we're talking about indenting, see how TUTOR does it:

Code: Select all

if      n8<4
.       write   first branch
.       calc    n9⇐34
elseif  n8=4
.       write   second branch
.       do      someunit
else
.       write   default branch
.       if      n8>6
.       .       write   special branch
.       endif
endif


Loops are even more interesting; rather than break or continue, you have outloop and reloop, respectively. You determine which loop to break out of by the out-denting the outloop or reloop command to the appropriate level, matching the initial loop command.

Code: Select all

loop    n8<10
.       write   within loop
.       sub1    n8
reloop  n8≥5
.       write   still within loop
.       do      someunit
outloop n8<3
.       write   still within loop
endloop
write   outside of loop


And yes, the dots at each intent level are required syntax.

And yes, I used to code in this language professionally.

User avatar
Mishrak
Posts: 1045
Joined: Fri Feb 05, 2010 10:15 pm UTC
Location: Houston, Texas

Re: Braces vs indent vs "end ..." syntax preference

Postby Mishrak » Mon Apr 06, 2015 3:03 pm UTC

Maybe it's just because C and C++ were my first languages but I feel very odd if I'm using a language that doesn't have braces.


Return to “Religious Wars”

Who is online

Users browsing this forum: No registered users and 2 guests