r/programming • • Aug 30 '08

Tour De Babel -- Rant about programming languages (at Amazon)

http://steve.yegge.googlepages.com/tour-de-babel
13 Upvotes

122 comments sorted by

View all comments

Show parent comment

1

u/mikkele Aug 31 '08

Whitespace and indent complaints are just stupid. Python merely forces you to do what you ought to do anyway, namely to keep your use of indent space/tab consistent.

8

u/akdas Aug 31 '08

To be fair, there are times when I indenting isn't so easy. Let's say someone posted a snippet of Python code online, but due it not being properly formatted, all continuous blocks of whitespace are rendered as a single space (this happens all the time in blog comments). I want to copy and paste the code, just try it out, and mess around with it a bit, but I can't because the formatting is messed up.

However, for almost all cases, I agree that Python's enforced whitespacing is not something to get worked up over.

0

u/[deleted] Aug 31 '08

[deleted] — view deleted comment

2

u/13ren Aug 31 '08 edited Aug 31 '08

Minor irritation: I've had Python code that looks indented but isn't. This is probably because I have tabstop=2. I think semantics that depend on the invisible is problem-prone! :-) Whitespace in make has a similar issue. However, once I realized what was happening, it hasn't happened again, so I think it's a minor irritation. The same problem also occurs in C-style code, in that when I cut-and-paste code written with different tabstops (and vice-versa), the places where spaces were used instead of tabs are revealed.

The other issue is that you can't inline function definitions etc - which in some cases would be clearer. (I like Haskell's \ for this - tho I've only seen it, not used it)

On ruby: why can't it use C-style } instead of end? Are { and } already used for something else?

0

u/[deleted] Aug 31 '08

[deleted] — view deleted comment

2

u/13ren Aug 31 '08 edited Aug 31 '08

I know you can do that, but they're not on one line. i.e. due to Python's need for indentation, you can't say this:

def myfunc(): def myfunc2(): pass

erruum, maybe "inline" doesn't strictly mean "on one line". Please take my comment as having the latter meaning :-)

0

u/[deleted] Aug 31 '08

[deleted] — view deleted comment

3

u/13ren Aug 31 '08 edited Aug 31 '08

curious: why don't they use def for that as well? That would seem more consistent (to me).

Here's code using lambda:

s = 'hello to all da people in da house'
s = s.split()
print map( lambda word: len(word), s )

[5, 2, 3, 2, 6, 2, 2, 5]

Instead of the keyword "lambda", why not have:

print map( def(word): len(word), s)

then you could name it too, if you wanted (I have a feeling this is an old, old controversy that doesn't really matter - I'm just wondering if there is a satisfying reason for it, apart from parser-convenience in distinguishing them).

0

u/[deleted] Aug 31 '08

[deleted] — view deleted comment

3

u/13ren Aug 31 '08

I don't know anything about this, so I'm not trying to argue, but... the change seems only in syntax, not semantics. How is it changed semantics?

→ More replies

1

u/13ren Aug 31 '08 edited Aug 31 '08

ah, thanks, it's seeming that lambdas are what I want. That's really cool, now I feel happy. :-)

I'm new to python, and all the examples where I thought a lambda would be appropriate have used separate functions.

2

u/Old_Cartographer_938 Aug 31 '08

Lambdas are exactly where the whitespace issue bites you. You can't have multi-line lambdas in Python.

There is, however, an argument that you shouldn't have multi-line lambdas. But people positing that argument are wrong. :-)

0

u/[deleted] Aug 31 '08

[deleted] — view deleted comment

1

u/13ren Aug 31 '08

thanks, bookmarked

1

u/Leonidas_from_XIV Aug 31 '08

There are some tools like functools.partial or operator.itemgetter that in fact, make lambda obsolete.

2

u/mernen Aug 31 '08

On ruby: why can't it use C-style } instead of end? Are { and } already used for something else?

Just because Matz didn't want it, basically. I guess he did it that way because using } would require an opening brace, making it in the end not really shorter, just distributing weight around. For almost all purposes, Ruby makes block-opening keywords completely optional (the only exception is the block-passing do, but these are also exactly the situation where you are also allowed to use {})

2

u/Leonidas_from_XIV Aug 31 '08

why can't it use C-style } instead of end? Are { and } already used for something else?

Because they are used for blocks and dictionaries/maps. But I suspect they could be used, because Ruby's grammar is (from lexer/parser viewpoint) quite complex.

0

u/Leonidas_from_XIV Aug 31 '08

I had seen both problems, but they somehow never outweighted the advantage of indentation.

If I paste some block, I often have to change other stuff as well, so the indentation is the tiniest problem whcih can trivially be solved automatically.

As to blog posts or forum posts without indentation: these are often people who don't care enough and I plainly refuse to give them any help besides "edit your post and fix the formatting". And people who care and whose code is valuable find ways to include code in comments (be it in a pastebin which can highlight code or be using formatting directives).

4

u/[deleted] Aug 31 '08

typing 16 spaces in Reddit posts is a royal pain

Also I indent using tabs not spaces, you can't press tab in a textarea.

0

u/Leonidas_from_XIV Aug 31 '08

typing 16 spaces in Reddit posts is a royal pain

So when you post C code, it is completely unindented and without previous editing also completely unreadable?

3

u/[deleted] Aug 31 '08

C code doesn't rely on line breaks and indenting.

it is unambiguous like that by design.

→ More replies (2)

5

u/twotime Aug 31 '08

Life is more complicated than that.

Whitespace reqs in python do cause problems at several levels. Basically both humans and a lot of tools are sloppy with whitespace.

mailclients, webbrowsers/wikis may wrap your code.

diff -w is pretty much useless with python.

Cut'n'paste is complicated if different levels of indentation is involved..

etc

The only legit question: do advantages outweigh disadvantages (in most cases at least)?

IMHO the answer is yes, but disadvantages are still there all the same and you cann't just pretend that they don't exist..

0

u/malcontent Aug 31 '08

When using ruby I frequently move bits of code around in the same module or even the same function. I use netbeans and I love being able to type alt-shift-f to automatically format my code.

Even when using Jedit the ruby plug in is smart enough to keep track of the brackets and end statements and to keep track of indenting.