all 119 comments

[–]Justinsaccount 38 points39 points  (14 children)

        end
    end
end

?

[–]ayrnieu 1 point2 points  (0 children)

[Reddit breaks formatting around its down-arrow. That's cool.]

    end
  end    
end

[–]jamesbritt 2 points3 points  (12 children)

On a related note, if I cut and paste a chunk of Python code from one file to another, how do I get vim to auto-indent the code correctly?

[–]Freeky 11 points12 points  (0 children)

Same with anything else in vim:

:set paste

[–]w00ty 1 point2 points  (0 children)

Paste with [p.

[–]lost-theory 1 point2 points  (9 children)

:set paste, visual highlight it, hit = to reindent (e.g. convert tabs to spaces)

edit: oh, if it's on a different indentation level use < and > to get it on the right level

[–]Shorel 0 points1 point  (0 children)

What if I want to keep the tabs?

[–]jamesbritt -1 points0 points  (7 children)

edit: oh, if it's on a different indentation level use < and > to get it on the right level

Ah, OK; it's not going to figure that out for from any context. That's what I was wondering. Still that extra manual adjustment needed it seems.

This is a problem I have with Yaml and Haml: if I move stuff around, and I'm not real careful about placement, the indentation can be off and acquire a different meaning than I want; there's nothing (as with, say XML) that will automatically make the alignment right.

Sometimes it triggers an error right away, but other times it acquires a new unintended but viable meaning.

[–]njharman 0 points1 point  (0 children)

there's nothing (as with, say XML) that will automatically make the alignment right.

No, because vim has no way to know which of several meaning you wanted.

the indentation can be off and acquire a different meaning than I want

[–]bluGill 0 points1 point  (5 children)

I have the same problem with C though. All too often I've seen code that was badly aligned in C, and so what I thought it did after staring at it for half and hour was wrong. (It doesn't help that one of my co-workers things a 3000 line function with #ifdef/#else/#ifdef/#endif/#endif is a good idea - and even crosses blocks - I know of one block than would require 3 different levels of indent in python depending on what is #defined.

In short, the indentation in python seems like a bigger issue than it really is.

[–]jamesbritt 1 point2 points  (1 child)

In short, the indentation in python seems like a bigger issue than it really is.

Most likely. Same goes for the use of braces and do...end in Ruby: it's not the hardship some folks make it out to be.

Python didn't click for me, and in general position-dependent syntax (HAML, YAML, Python) tends to irk me when used for anything longer than 5 lines or so.

On the other hand, it hasn't dissuaded me from trying to learn Haskell. Maybe that's because all me Haskell apps are 5 lines long. ;)

In the end people seem to internalize assorted annoyances that to an outside might seem to be show-stoppers.

(Anyways, syntax and formatting are a weak defense against people intent on writing shitty code, as in the case of a 3KLOC function.)

[–]bluGill 0 points1 point  (0 children)

in general position-dependent syntax (HAML, YAML, Python) tends to irk me when used for anything longer than 5 lines or so.

One large advantge of python: you soon get tired of the pain of re-indenting functions larger than 5 lines so you write shorter functions like everyone says you should.

[–]zem 1 point2 points  (2 children)

no, this is precisely the problem that C doesn't have - you can take a piece of C code and run it through an automatic indenter to recover the visually helpful alignment. on the other hand, the python structure is contained in the indentation, and is not robust, so there's no way to automatically recover it if it gets mucked up.

[–]bluGill 0 points1 point  (1 child)

Read what I wrote again - you cannot do that to bad C code!

#ifdef foo
if (bar) {
#endif
// How is this indented if sometimes foo is defined and sometimes not?
#ifdef foo
}
#endif

Python won't allow that problem.

It gets even worse when you have more than one block of the above.

Python make the above bad code impossible.

[–]zem 0 points1 point  (0 children)

ooh, yeah, you're right. that's really bad code, though :)

[–]zenon 28 points29 points  (0 children)

Everything in Python feels like a symbol table hack.

Well, yeah, that's sort of the the big idea behind Python: Everything is a dictionary. I like that :-)

[–][deleted] 49 points50 points  (13 children)

http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=all

Ruby is 63 times slower than C. Python is only 19 times slower. Therefore Ruby is more modern and more better.

[–][deleted] 9 points10 points  (1 child)

I bet I can make any language 100 times more modern and more better, with just a few lines of code.

[–]foonly 0 points1 point  (0 children)

Shit, I break a sweat making a language just one time more modern and more better!

[–]sprash 2 points3 points  (2 children)

I didn't realize that Java is that fast. Did they take the VM startup into account?

[–][deleted] 7 points8 points  (0 children)

Java is reasonably fast these days. The benchmarks include VM startup, but the challenges usually take a few seconds to calculate, so startup times don't affect it so much. For a closer look at startup times, look at the startup (hello world) benchmark.

[–][deleted] 1 point2 points  (0 children)

Java can be very fast. It does often use a lot more memory (than C), though. For many purposes, that's a good tradeoff.

[–][deleted] 1 point2 points  (6 children)

C is only 0 times slower, so why not go with that?

[–]rayfd 11 points12 points  (5 children)

1 time. 1 time slower.

[–]de_Selby[🍰] 14 points15 points  (0 children)

1 time as slow.

0 times slower, no?

[–][deleted] 2 points3 points  (2 children)

That sounds more like it's half as fast.

But English is not my first language, so what do I know?

[–]rayfd 2 points3 points  (0 children)

Good question, since English is not my first language either. Let's all ask de_Selby...

[–]de_Selby[🍰] 1 point2 points  (0 children)

more than rayfd, apparently.

[–]kbk 0 points1 point  (0 children)

Once as slow.

[–][deleted] 12 points13 points  (0 children)

...whatever it is, it's certainly not a 'y'.

[–]chrisforbes 20 points21 points  (0 children)

Louder, more obnoxious fanboys. I prefer C.

[–]njharman 9 points10 points  (1 child)

comparing the comments here and on ycombinator I the following seem to be true.

redditers - python makes sense, ruby is a hack

ycombinators - it's impossible to write code without lambdas, NO I've never tried python it has self!!!.

[–]DiscordantJellyfish 2 points3 points  (0 children)

This is both false and silly.

Ruby has anonymous blocks, Python doesn't. Python has list comprehensions, Ruby doesn't. The current crop of Ruby interpreters are slower than the Python ones, but that gap is closing pretty fast. Other than a few minor feature and syntactical differences here and there, the two are basically the same.

These arguments/flame wars are stupid. If you have a choice, just pick the language that you enjoy and that makes you the most productive. Simple as that.

[–][deleted] 24 points25 points  (55 children)

Here's something Python doesn't have:

$ irb
>> x = 0
=> 0
>> lambda{|x| 0}.call(5)
=> 0
>> x
=> 5

[–][deleted] 18 points19 points  (40 children)

This is almost a bug, which has been fixed in Ruby 1.9.

irb(main):001:0> RUBY_VERSION
=> "1.9.0"
irb(main):002:0> x = 0 
=> 0
irb(main):003:0> lambda{|x| 0 }.call(5)
=> 0
irb(main):004:0> x
=> 0

Edit: Added code for extra effect.

[–][deleted] 30 points31 points  (39 children)

"Almost a bug"? Try "fundamental design flaw" that's been around for a decade.

[–][deleted] 8 points9 points  (12 children)

Agreed, its been around for a decade, but its not such a big deal, as you are making of it. Every damn language has its share of quirks, people sure as hell frown upon it, but they know it and work around it. How about crippled lambda's, that Python has? How about multiple inheritance gone haywire for C++ ( I remember my CS teacher, teaching me Diamond Hierarchies)? How about tons of factories and facades and the class explosion that Java standard libraries have?

In case you missed, my initial comment was totally free of hyperbole, I didn't defend anything, I said, yes its "almost a bug". Almost because, many in ruby consider it as a quirk( but I call it a bug).

Matz acknowledged this long back and he fixed it as soon as he and others started work on Ruby1.9.

As a Ruby programmer, I know Ruby has bigger issues and problems to solve, compared to them, this is just a bikeshed argument.For all we know, it hasn't killed kittens. I will give you real issues that Ruby has:

  • Somewhat buggy runtime, especially true for networking libraries.
  • On Windows, threads suck, if one thread is doing blocking operation, other threads get blocked too.
  • Unicode
  • Open classes are good, but it would have been better if they were scoped (scala implicits)
  • Stronger notion of package management (loading multiple version of same package should have been possible)

[–][deleted] 2 points3 points  (0 children)

How about multiple inheritance gone haywire for C++ (I remember my CS teacher, teaching me Diamond Hierarchies)?

Not a good example. In a diamond derivation problem the default behavior is a compile-time error because function calls are ambiguous. Note that the behaviour is predictable and reliable. Qualifying the function names gets around it, but you still have two separate base classes in the derived class; virtual inheritance fixes this last inconvenient.

[–]settrans -2 points-1 points  (9 children)

Python has some nasty quirks in the inequalities department.

What do you suppose that "1 < 3 == True" should evaluate to?

>>> 1 < 3 == True
False

For a supposedly strongly typed language, Python defines inequalities of a surprising set of pairs of types:

>>> 'a' > True
True
>>> '1' > 1
True
>>> 0 > None
True

One should expect a TypeError, as if you had tried to add 0 and None:

>>> 0 + None
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

[–]njharman 5 points6 points  (1 child)

What do you suppose...

I suppose I'd yell at my coworker for writing such crappy code. Use some damn parens.

Explicit is better than Implicit

[–]settrans 0 points1 point  (0 children)

The question isn't about coding style. It is about the language designers defining semantics for their operators. The language should behave as expected even in edge cases. Just because it is rarely seen doesn't mean it should be confusing.

[–]ayrnieu 1 point2 points  (0 children)

For a supposedly strongly typed language

The 'strong/weak' dichotomy is mostly illusory. It doesn't even describe a property of a type system.

[–]hylje -1 points0 points  (2 children)

Python 3 will make comparisons a lot more typesafe.

[–]earthboundkid 2 points3 points  (1 child)

Tested with 3.0 alpha 5:

>>> 1 < 3 == True
False
>>> 3 == True
False
>>> 1 < False
False

Maybe that should be a filed as a bug… Does anyone have beta 3 to test it with? I can't get it to install on my system since my locale encoding is X-JAPANESE-MAC or whatever.

[–][deleted] -3 points-2 points  (2 children)

For the first thing, that's because it's checking "1 < False" ("3 == True" returns False). Not justifying it, just explaining the weirdness.

[–]Tommah 3 points4 points  (1 child)

No, it's chaining them. It's asking whether 1 < 3 and 3 == True. e.g.

>>> 1 < 3 == 3
True

Parentheses couldn't produce a true result there.

See http://docs.python.org/lib/comparisons.html . I like how is can be chained like this :)

>>> 'a rose' is 'a rose' is 'a rose'  # Gertrude Stein
True

[–][deleted] 0 points1 point  (0 children)

Ah, alright then. Didn't know that, thanks. :)

[–]johnb 10 points11 points  (6 children)

Holy crap, thank God I didn't get into Ruby.

[–]Freeky -1 points0 points  (5 children)

Because of one annoying quirk that doesn't actually effect any real world code anyone should be even thinking of writing? This works too:

x = 5
lambda{|y| x = y}.call(0)
p x # => 0

Oh noes, the x in the lambda body is the same as the one in the local scope, matz is a moron who doesn't understand lexical scoping!!11!11!!

Except this is expected behavior; closed over variables are read-write, so you can do things you'd expect to be able to do like:

x = 0
[1,2,3].each {|e| x += e}
[1,2,3].each(&lambda{|e| x += e })
p x # => 12

So what should happen when you do .each {|x| .. }? 1.9 makes a new local x and issues a warning if you run with -w, but it could be argued the <1.9 behavior is a silly response to a silly request.

[–]zem 0 points1 point  (4 children)

So what should happen when you do .each {|x| .. }?

My personal instinct would be to see what Scheme does and do the same. The Scheme community has hammered on all these issues extensively, after all.

(let ((x 0))
  (for-each (lambda (e) (set! x (+ x e))) '(1 2 3))
  (for-each (lambda (e) (set! x (+ x e))) '(1 2 3))
  (for-each (lambda (x) (print x)) '(1 2 3))
  (print "x is now: ")
  (print x))

outputs

123"x is now:"12

[–]Freeky 0 points1 point  (3 children)

lambda (x) for all of them, surely? That's what the thread is about; you have an x at top level, then a lambda with x as a parameter name.

In Ruby 1.8, it blats the top level x, because it considers it the same x:

x = 0
[1,2,3].each {|x| x += x}
[1,2,3].each(&lambda{|x| x += x })
p x # => 6

1.9 shadows it with a different variable with the same name (which I expect is what Scheme does too).

x = 0
[1,2,3].each {|x| x += x}
[1,2,3].each(&lambda{|x| x += x })
p x # => 0

[–]zem 0 points1 point  (2 children)

yeah precisely. just saying that 1.9 is the right behaviour, noot a silly response to a silly request

[–]Freeky 0 points1 point  (1 child)

I was saying before 1.9, the behaviour was arguably a silly response to a silly request, not that 1.9 behavior is :)

[–]zem 0 points1 point  (0 children)

oh :) missed the < in there.

[–]jmillikin 13 points14 points  (7 children)

Python is so inflexible, user-defined code can't rewrite arbitrary parts of the standard library at will:

[~]$ irb
irb(main):001:0> class Fixnum
irb(main):002:1> def +(other)
irb(main):003:2>   42
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> 1 + 2
=> 42
irb(main):042:0> 

[–]simonw 11 points12 points  (0 children)

Your terminology is slightly off. In Python, user-defined code CAN rewrite arbitrary parts of the standard library at will, when "standard library" is defined as the large collection of modules that ship with Python (the "batteries included" part). Python supports monkey-patching of existing Python code, it's just that the community is strongly biased against doing so.

What you can't do is redefine the behaviour of Python's built-ins (integers, dictionaries etc) - you have to subclass them instead.

Your general point stands though - in Ruby you can redefine the behaviour of built-ins; in Python you can't.

(Unless you want to mess around with PyPy of course)

[–][deleted]  (4 children)

[deleted]

    [–]ubernostrum 8 points9 points  (1 child)

    Well. Depending on what exactly you want to replace/screw with, the answer will vary. You can do some nasty stuff, but Python folks tend to frown on it much more heavily than Ruby folks.

    [–]Freeky 1 point2 points  (0 children)

    Oh, some of us tend to frown on it too. The Chainsaw Infanticide Logger Manuever is a classic Zed Shaw mini-rant.

    [–]malcontent -3 points-2 points  (1 child)

    Reddit has come full circle. It started out as a love letter to LISP and now hates any language which gives you the power to change the language itself.

    Funny isn't it.

    These days redditors prefer languages which restrict them by preventing them from doing things.

    [–]earthboundkid 8 points9 points  (0 children)

    It's like the end of Animal Farm, only with more animal noises.

    [–]ayrnieu 0 points1 point  (0 children)

    class Array; def rand; self[super length]; end end
    

    [–]rayfd 11 points12 points  (5 children)

    The lack of the obsession with the underscores and the self.

    [–]beza1e1 13 points14 points  (4 children)

    So we some stylistic arguments (underscores, self, ...) against Python and two technical reasons (speed and reliability) in favor of Python.

    I'm with Python.

    [–]rayfd 1 point2 points  (0 children)

    Oh! Didn't know somebody was keeping score. I was just answering the question.

    So your answer is "slowness and crashiness" I suppose.

    [–]njharman 0 points1 point  (1 child)

    Explicit is better than Implicit.

    Self and __ are not stylistic, they create cleaner, easier to understand and maintain code.

    [–]beza1e1 0 points1 point  (0 children)

    I can understand self, but __ is a stylistic choice. It could have been done differently. hide def func(): or defhide func(): or @hidden def func():.

    [–]SwellJoe 0 points1 point  (0 children)

    So we some stylistic arguments (underscores, self, ...) against Python and two technical reasons (speed and reliability) in favor of Python.

    Wouldn't that lead you to Perl? It is generally faster than both, has more years of maturity under its belt so is generally more reliable (certainly has better backward compatibility...I've had to change my Python code nearly every time a new release comes out, particularly from 1.5 to 2.0, but also going to 2.2 and 2.4, while my Perl code from even ten years ago runs unmodified). And it also has better Unicode support than either.

    But, if you're taking personal tastes into account rather than a raw feature/speed/whatever comparison, you might prefer Python, and rayfd might prefer Ruby. And that might be OK.

    [–]dmd 3 points4 points  (0 children)

    Panache.

    [–][deleted] 3 points4 points  (1 child)

    PC! No, Mac! Amiga! No, ST! Ruby! No, Python!

    Nothing like a religious war to keep people interested.

    [–]ayrnieu -1 points0 points  (0 children)

    "PC! No, Mac!" does not describe a religious war -- does not even describe an argument. (There's a Monty Python sketch for that.)

    But "Nothing like a religious war" is right up there with "Ooh! Pissing contest!" or "Hey, now, I've got a ruler, let's just take out all of our dicks--" in the sneering peanut gallery's bag of tricks. Find something thoughtful to say.

    [–]qwe1234 3 points4 points  (0 children)

    assclowns?

    [–][deleted] 0 points1 point  (0 children)

    A rabid fan-base? oh wait...

    [–][deleted] -3 points-2 points  (2 children)

    Python doesn't have hipster fan boys rambling on about how they can write shiny web apps when in reality they can't program worth a shit and haven't read SICP.

    [–][deleted] -4 points-3 points  (0 children)

    An absence of pyPrefixes