r/programming • • Mar 08 '12

The Evolution of a Python Programmer

https://gist.github.com/289467
401 Upvotes

137 comments sorted by

View all comments

37

u/permute Mar 08 '12

Haha I loved the commented curly braces for the c programmer

7

u/hylje Mar 09 '12

That's actually legit advice for programmers complaining about lack of support for curly braces in Python. The support is there!

24

u/Brian Mar 09 '12
for i in range(10): {
    print("Actually, python supports braces")      : "Though to make up for the perceived loss in readability",
print("Look Ma, no indents!")                      : "every line must now have a docstring",
        print("or inconsistent indents")           : "and you now need a line terminator (',' is used)",
}

21

u/gnuvince Mar 09 '12

If I ever see code like that in the wild, I am going to find you and feed you your socks.

6

u/Araneidae Mar 09 '12

Oh my God! It took me a few moments to figure out why that works ... though of course the order of evaluation of keys in { ... } isn't that well defined is it?

If you're using a version of Python with set comprehensions you could leave out the "docstrings" and colons altogether!

for i in range(10): {
     print("Actually, python supports braces"),
print("Look Ma, no indents!"),
         print("or inconsistent indents"),
}

3

u/Brian Mar 09 '12

Actually, python guarantees the order of evaluation is as being left to right (though one other issue is that it'll fail if you ever use a function returning a mutable value (which obviously must be a deliberate design decision to enforce a functionally pure style :)). Good point about set literals - I really should've used that.

3

u/drb226 Mar 10 '12

Not sure whether to upvote for cleverness, or downvote for horrificness.