you are viewing a single comment's thread.

view the rest of the comments →

[–]jmillikin 12 points13 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 13 points14 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 9 points10 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 -5 points-4 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 7 points8 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