News for hackers. Stuff that matters.
Re:Ask HN: Why Python over Ruby? by zach on Wednesday July 01, 2009 @05:36PM (#683423)
I should point out that capitalize(), of course, returns a new capitalized string, just as it does in Ruby. But in Ruby you also have String#capitalize!

And as for indentation, I think Guido should have followed through with making tabs a syntax error, because they are part of the syntax and are fiendish sources of error. Let's just say you have this code, properly indented with spaces:

    class X:
        def visible(self):
            pass
And you open it in a non-Python-aware editor, say for Windows, which has a four-space tab length and does not convert them to spaces. You add:

        def invisible(self):
            pass
at the end of the file using your tab key. Now you have a potentially crazy-hard-to-figure-out bug.
Re:Ask HN: Why Python over Ruby? by jmillikin on Wednesday July 01, 2009 @06:14PM (#683469)
I should point out that capitalize(), of course, returns a new capitalized string, just as it does in Ruby. But in Ruby you also have String#capitalize!

So the quote deals with mutability? I suppose that makes more sense, since Ruby tends to favor mutable objects. Of course, to my Python-based mind changing the definition of 'a' or 3 seems like a poor idea.

And as for indentation, I think Guido should have followed through with making tabs a syntax error

Surely you mean "making spaces a syntax error"? That would be much more sensible, since using spaces for indentation is absurd. Even better would be simply ignoring spaces, since that allows them to be used for pretty-printing and alignment without any potential ambiguity.

Also, the bug in your example will not be difficult to figure out, because Python will/should raise an exception when parsing the malformed file. Not everybody runs with -tt, but that ought to be the default behavior (and is anywhere I get to control the installation).

Re:Ask HN: Why Python over Ruby? by earthboundkid on Thursday July 02, 2009 @05:40AM (#684090)
PEP 8 specifies 4 spaces, not 1 tab. Python people generally prefer spaces to tabs, as do I, although I agree the semantically, it's a bit weird.
Re:Ask HN: Why Python over Ruby? by ketralnis on Wednesday July 01, 2009 @06:58PM (#683525)
> Even better would be simply ignoring spaces

Oh god no. Then you could have blocks that line up visually but execute in different scopes

Re:Ask HN: Why Python over Ruby? by Freaky on Wednesday July 01, 2009 @08:50PM (#683654)
Maybe you could consider a pre-commit hook which blocks /^\s* \t/ on * .py? Or if nothing else it's simple enough to grep/ack for.

I'd also recommend making indentation whitespace visible if your editor supports it - it is syntax after all. I have vim configured to colour leading spaces green, leading tabs as blue, and tabs following anything other than a tab highlighted red. Making inconsistent indentation ugly is quite effective, though sadly ineffective on other people.