Forced whitespace and tabulation

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

Whitespace control or no whitespace control

Control
10
26%
Partial control
4
10%
No control
25
64%
 
Total votes: 39

coppro
Posts: 117
Joined: Mon Feb 04, 2008 6:04 am UTC

Forced whitespace and tabulation

Postby coppro » Fri Feb 15, 2008 7:12 am UTC

Should programming languages force whitespace (tabs, newlines)? e.g. Python forces whitespace, C doesn't (exception: the preprocessor). Some languages fall into the middle (usually via a single-statement-line rule). A language that only uses whitespace as a means of disambiguation and not a syntactic element don't count.

Pros:
Enforces program readability
Removes a topic from this forum
Reduces syntax, as the indentation can be used to infer meaning

Cons:
Reduces flexibility
Makes one-liners next to impossible

Personally, I like the use of whitespace as a syntactic element. But it shouldn't be mandatory, IMHO; there should be a workaround, such as an 'indent'/'dedent' keyword for tricking the parser. And it means that you can use curly braces for better purposes (keywords to end definitions are dumb).

Rysto
Posts: 1460
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Forced whitespace and tabulation

Postby Rysto » Fri Feb 15, 2008 7:50 am UTC

Syntactic whitespace is the devil.

User avatar
Korandder
Posts: 161
Joined: Fri Sep 14, 2007 6:12 am UTC
Location: LoadingReadyRun Australian Astrophysical Observatory
Contact:

Re: Forced whitespace and tabulation

Postby Korandder » Fri Feb 15, 2008 8:22 am UTC

Whitespace more than anything is why Python is against my religious beliefs.

It is still a very useful language though. Pyraf is much easier to use the regular Iraf.
Image

ToLazyToThink
Posts: 83
Joined: Thu Jun 14, 2007 1:08 am UTC

Re: Forced whitespace and tabulation

Postby ToLazyToThink » Fri Feb 15, 2008 8:27 am UTC

I still have the emotional scars from a horrific makefile incident. Significant whitespace == worst idea ever.

User avatar
Dingbats
Posts: 921
Joined: Tue Mar 20, 2007 12:46 pm UTC
Location: Sweden
Contact:

Re: Forced whitespace and tabulation

Postby Dingbats » Fri Feb 15, 2008 10:46 am UTC

Where's the "either is fine" option?

zenten
Posts: 3799
Joined: Fri Jun 22, 2007 7:42 am UTC
Location: Ottawa, Canada

Re: Forced whitespace and tabulation

Postby zenten » Fri Feb 15, 2008 12:37 pm UTC

Either is fine, but mixing is just dumb and leads to confusion, headaches, and possibly incest.

User avatar
Gunfingers
Posts: 2401
Joined: Wed May 30, 2007 7:15 pm UTC

Re: Forced whitespace and tabulation

Postby Gunfingers » Fri Feb 15, 2008 7:20 pm UTC

I don't believe a language's syntax should enforce coding standards. It should allow for it, but it should also allow for whatever shitty standards you want to have.

User avatar
ash.gti
Posts: 404
Joined: Thu Feb 07, 2008 1:18 am UTC
Location: Probably a coffee shop.

Re: Forced whitespace and tabulation

Postby ash.gti » Fri Feb 15, 2008 8:34 pm UTC

My problem is when I have a simple thing to do and because of the way the program reads my code I can't write it in one line.

For instance, like this:

Code: Select all

3.times do
  puts "Hello World"
end


and

Code: Select all

3.times do; puts "Hello World"; end


Do the exact same thing. There are times when there really isn't a need to make something be long and drawn-out and take up multiple lines.
# drinks WAY to much espresso

++$_
Mo' Money
Posts: 2370
Joined: Thu Nov 01, 2007 4:06 am UTC

Re: Forced whitespace and tabulation

Postby ++$_ » Fri Feb 15, 2008 8:51 pm UTC

Significant whitespace is okay. It makes a language easier to parse, which is sometimes important, and 95% of the time you would have indented anyway. It's also nice for beginners, who find it very logical.

The downside is that it stops one-liners from working (sometimes). That's the tradeoff.

User avatar
tendays
Posts: 957
Joined: Sat Feb 17, 2007 6:21 pm UTC
Location: HCMC

Re: Forced whitespace and tabulation

Postby tendays » Sat Feb 16, 2008 7:30 pm UTC

Why the discrimination against white space? I personally support this action to restore the balance.
<Will> s/hate/love/
Hammer wrote:We are only mildly modly. :D
Beware of the shrolymerase!

User avatar
OmenPigeon
Peddler of Gossamer Lies
Posts: 673
Joined: Mon Sep 25, 2006 6:08 am UTC
Contact:

Re: Forced whitespace and tabulation

Postby OmenPigeon » Sun Feb 17, 2008 6:43 am UTC

ash.gti wrote:My problem is when I have a simple thing to do and because of the way the program reads my code I can't write it in one line.

For instance, like this:

Code: Select all

3.times do
  puts "Hello World"
end


and

Code: Select all

3.times do; puts "Hello World"; end


Do the exact same thing. There are times when there really isn't a need to make something be long and drawn-out and take up multiple lines.

But by having enforced whitespace, we can make that statement be both reasonably short and easy to read.

Code: Select all

for i in range(3):
    print "Hello, World!"

Since we don't need anything to mark the end of a loop it gets cut down to two lines instead of three. Granted, it's not as short as one, but it's also easier to read. In addition, if you need to have multiple nested loops, or loop inside a function inside a class or something crazy like that, not having to put braces on the ends of everything is going to save you space.
As long as I am alive and well I will continue to feel strongly about prose style, to love the surface of the earth, and to take pleasure in scraps of useless information.
~ George Orwell

User avatar
Eschatokyrios
Posts: 244
Joined: Fri Dec 22, 2006 6:49 pm UTC

Re: Forced whitespace and tabulation

Postby Eschatokyrios » Mon Feb 18, 2008 12:11 pm UTC

OmenPigeon wrote:
ash.gti wrote:My problem is when I have a simple thing to do and because of the way the program reads my code I can't write it in one line.

For instance, like this:

Code: Select all

3.times do
  puts "Hello World"
end


and

Code: Select all

3.times do; puts "Hello World"; end


Do the exact same thing. There are times when there really isn't a need to make something be long and drawn-out and take up multiple lines.

But by having enforced whitespace, we can make that statement be both reasonably short and easy to read.

Code: Select all

for i in range(3):
    print "Hello, World!"

Since we don't need anything to mark the end of a loop it gets cut down to two lines instead of three. Granted, it's not as short as one, but it's also easier to read. In addition, if you need to have multiple nested loops, or loop inside a function inside a class or something crazy like that, not having to put braces on the ends of everything is going to save you space.


Also, note that (in python anyway),

Code: Select all

for i in range(3): print "Hello, World"


is perfectly legal, and produces the same result as the two-line version. Python has a set of rules somewhere in its documentation that describe exactly where you can and cannot have one-line statements and ignore whitespace conventions. In any case, everything that I've ever coded that I thought should be just one simple line, python has let me do (the only exception is that I'm not sure that there's a way to write:

Code: Select all

from random import randint
print "DESU "*randint(1,1000)


in only one line. But the only reason to do that would be so that you could say "I wrote a one-line program that accurately replicates a good third of 4chan's content")
კაცი ბჭობდა, ღმერთი იცინოდაო
k'atsi bch'obda, ghmerti itsinodao
"Man was discussing, God was laughing"
-Georgian proverb

User avatar
pieaholicx
The cake is a lie!
Posts: 531
Joined: Mon Oct 22, 2007 12:51 pm UTC
Contact:

Re: Forced whitespace and tabulation

Postby pieaholicx » Mon Feb 18, 2008 5:21 pm UTC

tendays wrote:Why the discrimination against white space? I personally support this action to restore the balance.

I too support this movement to make whitespace more important.
It's okay, I'm Chaotic Neutral. I can kill him over the loot.
Overexposure to pieaholicx may, in semi-rare cases, emancipate dental fillings, crowns, tooth enamel, and teeth.

User avatar
xyzzy
Meta-Titled
Posts: 263
Joined: Sun Mar 18, 2007 10:02 pm UTC
Location: Colossal Cave
Contact:

Re: Forced whitespace and tabulation

Postby xyzzy » Tue Feb 19, 2008 12:04 am UTC

In short, never. I should be able to indent my code however I damn well like. To make this easier, the programming language should probably use some totally unambiguous way of collecting statements. For instance, the way scheme does it. Indentation can be ignored, added, subtracted, rearranged, to your hearts content. As far as the computer is concerned, all that matter are the parens, and there's only one type to make it easy.
"Wile E. Coyote was a theoretical mathematician." - Leliel
"Modern life can be so boring without elements of the bizarre or the fantastical. Hence, we have steampunk." - Me

User avatar
b.i.o
Green is the loneliest number
Posts: 2519
Joined: Fri Jul 27, 2007 4:38 pm UTC
Location: Hong Kong

Re: Forced whitespace and tabulation

Postby b.i.o » Tue Feb 19, 2008 12:13 am UTC

I personally support the use of Whitespace for all programming languages projects.

User avatar
enk
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark
Contact:

Re: Forced whitespace and tabulation

Postby enk » Tue Feb 19, 2008 12:43 am UTC

The dark fire will not avail you, whitespace of Udun. Go back to the Shadow!

Before the time of computers, whitespace was something you didn't write, and I think it should stay that way, that is, it shouln't bear any meaning in itself.
phlip wrote:Ha HA! Recycled emacs jokes.

zenten
Posts: 3799
Joined: Fri Jun 22, 2007 7:42 am UTC
Location: Ottawa, Canada

Re: Forced whitespace and tabulation

Postby zenten » Tue Feb 19, 2008 12:50 am UTC

xyzzy wrote:In short, never. I should be able to indent my code however I damn well like. To make this easier, the programming language should probably use some totally unambiguous way of collecting statements. For instance, the way scheme does it. Indentation can be ignored, added, subtracted, rearranged, to your hearts content. As far as the computer is concerned, all that matter are the parens, and there's only one type to make it easy.


It matters a lot to the poor bastards who have to debug and maintain your code though.

User avatar
xyzzy
Meta-Titled
Posts: 263
Joined: Sun Mar 18, 2007 10:02 pm UTC
Location: Colossal Cave
Contact:

Re: Forced whitespace and tabulation

Postby xyzzy » Tue Feb 19, 2008 1:16 pm UTC

zenten wrote:
xyzzy wrote:In short, never. I should be able to indent my code however I damn well like. To make this easier, the programming language should probably use some totally unambiguous way of collecting statements. For instance, the way scheme does it. Indentation can be ignored, added, subtracted, rearranged, to your hearts content. As far as the computer is concerned, all that matter are the parens, and there's only one type to make it easy.


It matters a lot to the poor bastards who have to debug and maintain your code though.


Well, if they're scheme programmers, they'll simply throw it into emacs and let that auto indent. As that's how I do it, no problems.

But it means that I can split statements across lines if they're growing too long, or compress them otherwise, without the computer complaining.

In short, indentation is for humans, parens are for computers. Indent your code sensibly, but the computer should never force it.
"Wile E. Coyote was a theoretical mathematician." - Leliel
"Modern life can be so boring without elements of the bizarre or the fantastical. Hence, we have steampunk." - Me

User avatar
OmenPigeon
Peddler of Gossamer Lies
Posts: 673
Joined: Mon Sep 25, 2006 6:08 am UTC
Contact:

Re: Forced whitespace and tabulation

Postby OmenPigeon » Wed Feb 20, 2008 12:40 am UTC

xyzzy wrote:But it means that I can split statements across lines if they're growing too long, or compress them otherwise, without the computer complaining.

... You can do that in Python (and, I assume, any reasonably sensible whitespace-enforcing language), too. Just throw a backslash in there and you're all set.

xyzzy wrote:In short, indentation is for humans, parens are for computers. Indent your code sensibly, but the computer should never force it.

All code, everywhere, ever is for humans. Unless you happen to be writing directly in machine language, it's your job to not only make code that works, but code that other people can use.

Think of programmers like users. If you're designing an application, and there's the possibility for a user to do something with it you don't want, you rewrite that part of the app. This is why we check the values of fields before we write them to a database, why we make sure there aren't any possibilities for buffer overflows and all that.

Similarly, I never want to read horrible, unindented code that some other programmer left for me. I could just trust everyone I know to use good style, but that's like trusting Mrs. Roberts. I'd much rather have good style enforced by the machine than by good will and puppydog dreams.
As long as I am alive and well I will continue to feel strongly about prose style, to love the surface of the earth, and to take pleasure in scraps of useless information.

~ George Orwell

Rysto
Posts: 1460
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Forced whitespace and tabulation

Postby Rysto » Wed Feb 20, 2008 3:34 am UTC

OmenPigeon wrote:... You can do that in Python (and, I assume, any reasonably sensible whitespace-enforcing language), too. Just throw a backslash in there and you're all set.

Ew. That's gross. You seriously have to escape newlines in Python? Ugh.

User avatar
OmenPigeon
Peddler of Gossamer Lies
Posts: 673
Joined: Mon Sep 25, 2006 6:08 am UTC
Contact:

Re: Forced whitespace and tabulation

Postby OmenPigeon » Wed Feb 20, 2008 4:04 am UTC

Rysto wrote:Ew. That's gross. You seriously have to escape newlines in Python? Ugh.

Ew. Thats gross. You seriously have to open and close scope with a brace in C++? You seriously have to end every line with a semicolon? Ugh.
As long as I am alive and well I will continue to feel strongly about prose style, to love the surface of the earth, and to take pleasure in scraps of useless information.

~ George Orwell

User avatar
xyzzy
Meta-Titled
Posts: 263
Joined: Sun Mar 18, 2007 10:02 pm UTC
Location: Colossal Cave
Contact:

Re: Forced whitespace and tabulation

Postby xyzzy » Wed Feb 20, 2008 3:36 pm UTC

OmenPigeon wrote:
xyzzy wrote:But it means that I can split statements across lines if they're growing too long, or compress them otherwise, without the computer complaining.

... You can do that in Python (and, I assume, any reasonably sensible whitespace-enforcing language), too. Just throw a backslash in there and you're all set.

xyzzy wrote:In short, indentation is for humans, parens are for computers. Indent your code sensibly, but the computer should never force it.

All code, everywhere, ever is for humans. Unless you happen to be writing directly in machine language, it's your job to not only make code that works, but code that other people can use.

Think of programmers like users. If you're designing an application, and there's the possibility for a user to do something with it you don't want, you rewrite that part of the app. This is why we check the values of fields before we write them to a database, why we make sure there aren't any possibilities for buffer overflows and all that.

Similarly, I never want to read horrible, unindented code that some other programmer left for me. I could just trust everyone I know to use good style, but that's like trusting Mrs. Roberts. I'd much rather have good style enforced by the machine than by good will and puppydog dreams.


No, what the machine enforces is a particular style. If I'm using scheme, for instance

Code: Select all

(define (func . args)
  (if (conditional)
      (cons (func (list (mod arg1) (mod arg2) etc))
            (func (cons (arg1) (list (mod arg2) etc)))
      (cons (+ 3 4) (list 6 5 4 3 2 1))))


Note how one of those cons statements is split across two lines, while the other isn't. No extra characters needed or anything of the sort. Any decent editor can sort out indentation for you in a moment (Just hit tab, C-n in emacs to sort out a line), and the benefits in flexibility make it worth it.

I can use whatever style I like, and you can change it to whatever style you like in about two seconds. That's the benefit of whitespace not being required. Whitespace is for humans, so it should be used, but must not be forced in a particular style. The computer shouldn't try to enforce conventions like that, a human must learn them xirself.
"Wile E. Coyote was a theoretical mathematician." - Leliel
"Modern life can be so boring without elements of the bizarre or the fantastical. Hence, we have steampunk." - Me

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

Re: Forced whitespace and tabulation

Postby EvanED » Fri Feb 22, 2008 8:22 pm UTC

This is an interesting blog post (apparently included in Joel's Best Software Writing) that argues that language standards should specify style and whitespace. I don't know if I agree with it or not, but it's an interesting read and makes a somewhat good argument...

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Forced whitespace and tabulation

Postby Berengal » Sat Feb 23, 2008 1:05 am UTC

My thoughts on whitespace: (Warning: You have been warned)
Spoiler:
Allwhitespaceshouldberemoved,notjustfromprogramminglanguages,butfromallwrittenlanguageseverwritten.Afterall,itiswhatwedon'twrite,assomeonesaid,andanygoodcomputerprogramwillbeabletoputwhitespaceinatextsoastomakeitmakesense.ForsomereasonIhaven'tfoundatexteditorthatdoesthiswithallwhitespaceyet,butI'msurethereisoneontheinternetsomewhere.Mosttexteditorscanalreadyadd/removenewlinesondemand,soit'sapuzzlewhyALLwhitespaceadding/removingisn'tstandardyet.

Seriously though, I find syntactically important whitespace to be a good thing. For example, whenever I'm writing a javaprogram, a statement is terminated by [semicolon][newline], while in python it's simply [enter]. Blocks are terminated by [semicolon][enter][backspace][closedbrace][enter] in java (using the java brace style), but in python it's simply [enter][backspace].
Slightly relevant: Braces are hard to type on my (norwegian) keyboard, having to go AltGr-7/AltGr-0 to open/close. This has made me hate braces more than I probably would on a standard keyboard, thus liking python even more.

Another arguement, I find, is that with enforced whitespace, everyone writes in the same style, but with insignificant whitespace there are several equally good styles, but mixing these styles (as in several programers on the same project using different styles) or simply reading someone else's code written in an unfamiliar style is a Bad Thing. I even almost lost a few marks on an assignement (in the first cs class, where code style was important) because I indented split lines, something the marker found weird. When I got the assignement back he commented that "Wtf? Code block at line soandso? I don't even see how this compiles, but it does. It's either correct, or you haxx0red my compiler. In either case you don't lose points anyway."
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

ez ezz
Posts: 1
Joined: Wed Dec 05, 2007 8:08 am UTC

Re: Forced whitespace and tabulation

Postby ez ezz » Mon Feb 25, 2008 7:16 am UTC

Honestly, I dig Python's whitespace for the same reason I like whitespace in a good essay: it just makes it easier to read. The beauty of Pythonic syntax is how easy it is on the eyes, literally. Everything is stark, contrasted, clearly visible.

User avatar
wr3cktangle
Posts: 75
Joined: Tue Aug 01, 2006 5:03 pm UTC

Re: Forced whitespace and tabulation

Postby wr3cktangle » Mon Feb 25, 2008 12:56 pm UTC

Berengal wrote:My thoughts on whitespace: (Warning: You have been warned)
Spoiler:
Allwhitespaceshouldberemoved,notjustfromprogramminglanguages,butfromallwrittenlanguageseverwritten.Afterall,itiswhatwedon'twrite,assomeonesaid,andanygoodcomputerprogramwillbeabletoputwhitespaceinatextsoastomakeitmakesense.ForsomereasonIhaven'tfoundatexteditorthatdoesthiswithallwhitespaceyet,butI'msurethereisoneontheinternetsomewhere.Mosttexteditorscanalreadyadd/removenewlinesondemand,soit'sapuzzlewhyALLwhitespaceadding/removingisn'tstandardyet.
reminds me of the gnomes in my favorite Dragonlance-based MUD.
good ol' Mount Nevermind.


as for the debate
It's really the language-creators decision as to whether or not to enforce a whitespace scheme, and it's my decision (except when made by work or school) whether or not to use the language. Personally, I like free indentation, but I'm not gonna die if it's taken away from me.
Maxim 33. When faced with the unusual, self-destruct.
My blog

User avatar
Xanthir
My HERO!!!
Posts: 5413
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Forced whitespace and tabulation

Postby Xanthir » Mon Feb 25, 2008 5:45 pm UTC

I'm with xyzzy. Whitespace should be optional, with an unambiguous indenting style that can be enforced by a computer. Let me write my code how I want, but establish a canonical style that I can impose on anyone's code without effort.

That is, every language should have a pretty-printer. ^_^
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Andrew
Posts: 619
Joined: Tue Jan 02, 2007 9:59 pm UTC
Location: Manchester, UK
Contact:

Re: Forced whitespace and tabulation

Postby Andrew » Sun Mar 02, 2008 6:01 pm UTC

I get annoyed by enforced whitespace. Sometimes I have a lot of similar-looking statements and it's more important to me that they line up with each other so that I can easily spot the differences than that they all line up with an arbitrary whitespace protocol devised by someone who's never seen my code.

I do like Visual Studio's system: by default it fixes your whitespace when you type a line, but it will let you go back and change it if you don't want it that way.

User avatar
rrwoods
Posts: 1509
Joined: Mon Sep 24, 2007 5:57 pm UTC
Location: US

Re: Forced whitespace and tabulation

Postby rrwoods » Mon Mar 03, 2008 8:56 pm UTC

Berengal wrote:Braces are hard to type on my (norwegian) keyboard, having to go AltGr-7/AltGr-0 to open/close.

I suppose it's because you don't use AltGr that much? On my keyboard I have to type Shift-[ or Shift-] to type a { or }, still a single singly-modified keystroke.
31/M/taken/US
age/gender/interest/country

Belial wrote:The sex card is tournament legal. And I am tapping it for, like, six mana.

User avatar
enk
Posts: 754
Joined: Mon Sep 10, 2007 12:20 am UTC
Location: Aalborg, Denmark
Contact:

Re: Forced whitespace and tabulation

Postby enk » Mon Mar 03, 2008 10:06 pm UTC

rrwoods wrote:
Berengal wrote:Braces are hard to type on my (norwegian) keyboard, having to go AltGr-7/AltGr-0 to open/close.

I suppose it's because you don't use AltGr that much? On my keyboard I have to type Shift-[ or Shift-] to type a { or }, still a single singly-modified keystroke.


I'm Danish, I had the AltGr-7/AltGr-0 too ( ()[] are 89 with shift and AltGr respectively). While it's still only one modifier, it's on the same side as 7 and 0, so it's very awkward to do with one hand.

Now I use my home made modifier with 89 so all parens/braces are on the same key and I can hit the modifier with the opposite, i.e. left, hand.
phlip wrote:Ha HA! Recycled emacs jokes.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Forced whitespace and tabulation

Postby Berengal » Tue Mar 04, 2008 7:43 am UTC

@rrwoods: Like enk said, try typing altGr+7. You either have to use the thumb, and turn your hand in an awkward way, or use your second hand on the wrong side of the keyboard.

I've fixed it now though. Made a new custom layout, where I removed all numbers from the top row, replacing them with their shift-companions, moved{} to the right of 'p', and put <> (Which were earlier on the same button, and I could never figure out which one required shift and which didn't) there as well, but with shift. A few other modifications, like moving ; and : to the middle row, left of 'L', and I've got a layout that's much easier to code with. Also, it was quite intuitive to learn, I found, requiring all of two minutes of coding before I got it.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
rrwoods
Posts: 1509
Joined: Mon Sep 24, 2007 5:57 pm UTC
Location: US

Re: Forced whitespace and tabulation

Postby rrwoods » Tue Mar 04, 2008 2:52 pm UTC

Yeah I suppose it could be awkward to slide your left hand across, but that seems like the most ergonomical way to do it. (Left hand for the number, and either thumb for AltGr)
31/M/taken/US
age/gender/interest/country

Belial wrote:The sex card is tournament legal. And I am tapping it for, like, six mana.

User avatar
r1chard
Posts: 281
Joined: Thu Dec 06, 2007 2:17 am UTC
Location: Melbourne, AU
Contact:

Temp. Python religious wars thread

Postby r1chard » Wed May 21, 2008 5:20 am UTC

The posts starting with this one and continuing through Torn Apart By Dingos's May 21, 4:12p post that is second on the second page (at least for me) are split from here.

biolution wrote:It also has significance if you use "\" for line continuation and have a trailing space after it.

I didn't know about that - I guess I've never accidentally left garbage after a continuation character. I wonder why the parser doesn't just ignore rather than raise the error.

And maybe calling that "significant" is like saying that whitespace between "int a;" in C is significant.

Which I guess it is.

I don't know what my point is either :)

User avatar
hotaru
Posts: 1045
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Python with braces?

Postby hotaru » Wed May 21, 2008 6:08 am UTC

r1chard wrote:And maybe calling that "significant" is like saying that whitespace between "int a;" in C is significant.

how is it significant there? "int a;", " int a;", "int a ;", "int a; ", etc. all do the exact same thing...

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

masher
Posts: 821
Joined: Tue Oct 23, 2007 11:07 pm UTC
Location: Melbourne, Australia

Re: Python with braces?

Postby masher » Wed May 21, 2008 6:36 am UTC

hotaru wrote:
r1chard wrote:And maybe calling that "significant" is like saying that whitespace between "int a;" in C is significant.

how is it significant there? "int a;", " int a;", "int a ;", "int a; ", etc. all do the exact same thing...


as opposed to "inta;"

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Python with braces?

Postby Berengal » Wed May 21, 2008 8:12 am UTC

I find there's very little difference between braces and indentation when programming. After all, you intend brace-family languages in just the same way as you indent python, except in python you omit the braces (or go #{ #} as long as the braces are on a separate line :P). Splitting a single statement over several lines is possible, and in most cases you don't even need the \, and having multiple statements on a single line is possible with ; just as in braced languages. The benefit of forcing a certain style is that there's only ever one style to parse, and you've got no "true style" religious wars. The only thing you lack is the ability to create scopes at will, but the only times I've needed that is in java with objects that have several iterators, so you have to go "{Element e; Iterator<Element> iter = object.myIterator(); while (iter.hasNext()) //etc..." to prevent the iterator and variable from leaking out into the surrounding scope. In python, going "for elem in obj:" is the same as going "for elem in obj.__iter__():", so you can just as easily go "for elem in obj.myIter():"
As long as you treat tabs like the devil, you should be fine writing python just as you would a properly indented braced language, except you omit braces. Anyway, this discussion probably belongs in Religious Wars now...
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

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

Re: Python with braces?

Postby EvanED » Wed May 21, 2008 8:38 am UTC

Berengal wrote:The only thing you lack is the ability to create scopes at will, but the only times I've needed that is in java with objects that have several iterators, so you have to go "{Element e; Iterator<Element> iter = object.myIterator(); while (iter.hasNext()) //etc..." to prevent the iterator and variable from leaking out into the surrounding scope. In python, going "for elem in obj:" is the same as going "for elem in obj.__iter__():", so you can just as easily go "for elem in obj.myIter():"

The other time they are extremely useful is in C++ or another language with automatic, deterministic destructors.

As long as you treat tabs like the devil, you should be fine writing python just as you would a properly indented braced language, except you omit braces. Anyway, this discussion probably belongs in Religious Wars now...

It's definitely tending in that direction... and I'm not helping. If it goes, it's getting merged with the other thread on the topic. (This might be what I'm remembering.) Or I might just lock this one.

User avatar
evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

Re: Python with braces?

Postby evilbeanfiend » Wed May 21, 2008 8:51 am UTC

EvanED wrote:
Berengal wrote:The only thing you lack is the ability to create scopes at will, but the only times I've needed that is in java with objects that have several iterators, so you have to go "{Element e; Iterator<Element> iter = object.myIterator(); while (iter.hasNext()) //etc..." to prevent the iterator and variable from leaking out into the surrounding scope. In python, going "for elem in obj:" is the same as going "for elem in obj.__iter__():", so you can just as easily go "for elem in obj.myIter():"

The other time they are extremely useful is in C++ or another language with automatic, deterministic destructors.


the main time i use braces that i don't, strictly speaking, need is to limit the scope of using directives/declarations. again in c++ but this should hold for a number of languages that allow importing from namespaces.
in ur beanz makin u eveel

User avatar
Yakk
Poster with most posts but no title.
Posts: 11128
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Python with braces?

Postby Yakk » Wed May 21, 2008 3:02 pm UTC

That is only because XKCD is the center of the internet. Things on the edge get updated slower.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

mrkite
Posts: 336
Joined: Tue Sep 04, 2007 8:48 pm UTC

Re: Python with braces?

Postby mrkite » Wed May 21, 2008 8:33 pm UTC

++$_ wrote:I have never once encountered a whitespace-related problem with Python.


and I have never once encountered a brace problem with any other language.

However, reddit broke a few months ago because someone uncommented code and didn't intent properly. The code looked like this (obviously paraphrasing)

Code: Select all

if blah:
    do some stuff
    if somethingelse:
       do other stuff
#    do stuff at a future date


they uncommented the last line but had no way of knowing where the code should go. Does it go in the first if? the second if? Impossible to tell.

You would never have that problem if there were braces.


Return to “Religious Wars”

Who is online

Users browsing this forum: No registered users and 7 guests