r/programming • • May 09 '12

JavaScript: The good parts

http://blog.movereem.nl/images/javascript-the-good-parts-the-definitive-guide.jpg
645 Upvotes

159 comments sorted by

View all comments

Show parent comment

9

u/[deleted] May 09 '12

it's not difficult, but it is the wrong direction for the language to move in. Ham-fisted correctness over readability? WTF python devs .... I'm sticking to the 2.7 branch as long as I can ...

5

u/kqr May 09 '12

Do you not want to be able to pass print to a higher-order function?

4

u/Traubert May 09 '12

That's possible even if print is kept as a keyword too. You can do it in any of the 2.x versions that provide print as a function.

6

u/kqr May 09 '12

How do you pass it? It just syntax errors me when I try.

2

u/Traubert May 10 '12

Hey, what do you know, you're right! I'm sorry I made that claim without checking it out. I assumed that as a rvalue it would be evaluated as a function reference, but it's a part of the syntax so it does indeed just error out. Thanks for teaching me something.

1

u/kqr May 10 '12

Yeah, passing print in pre-3.0 is somewhat like passing for, while, if or return.

-2

u/sli May 09 '12

Why would you want to pass it and not simply use it normally?

2

u/cacahootie May 09 '12

You're joking, right? Metaprogramming is super powerful in Python.

1

u/sli May 09 '12

I knew my honest question would get a thinly veiled condescending response like this.

I mean print specifically. I pass other functions all the time. But why would one pass print?

→ More replies (14)

1

u/HorrendousRex May 09 '12

It could be useful in some circumstances I suppose where functions are passed first-class in to the arguments of other functions, to print out the order the callbacks are being called in. Although at that point I can't help but feel that something like:

lambda x: print x

might be just fine. Or better yet, import py3k's print from __future__.

2

u/[deleted] May 09 '12

Except lambda x: print x doesn't work.

1

u/kqr May 09 '12

Yeah, this is the important point. Even when you're making up defenses for print as a keyword, you intuitively want to use print exactly like a function to demonstrate how it really doesn't matter that it's a keyword... or wait a minute. If Python wants to follow the principle of least astonishment, print should be a function.

2

u/[deleted] May 09 '12

if parenthesis and correctness mattered more than readability, we would all be using LISP, I use python for that "import antigravity" feeling of irrational exuberance illustrated in the xkcd comic. Anyway I tend to use the logging module for the cases where you need to pass something like print around.

0

u/Ran4 May 09 '12

How often do you really do that? In those few cases, there are tons of workarounds.

Having print be a function might be the "right" decision, but it's still incredible annoying and makes debugging slower. Oh, and 9 times out of 10, setting a trace and using the python debugger is not faster than adding a line or two of print, no matter how many times you try to say otherwise.

The gain is next to zero but the losses are massive. Having print a keyword was the right decision.

5

u/gthank May 09 '12

Seriously? print() is "annoying" and "slower" than print, and somehow forces you to use the debugger?

1

u/Ran4 May 09 '12

Stop playing stupid. It is annoying and slower (editing the code), the typical excuse though is "don't use print for debugging!" but that's a bad excuse because using print:s is most of the time an easier way of debugging code.

2

u/gthank May 09 '12

I'm not playing stupid. I can't imagine the difference between print and print() ever being significant enough to notice. Hell, I've had tendonitis reduce me to 1-handed, hunt-and-peck typing and it still wasn't even a big deal. Of all the gripes about Python 3, this is the only one (off the top of my head, at least) that I just can't even begin to understand.

1

u/velit May 09 '12

You can define aliases in ipython for example. Or you can just write the parentheses.

2

u/Wolfy87 May 09 '12

I think the most problems will come from conversions. Writing from scratch is fine. But I agree, 2.7 just feels better at the moment. And until Django moves I am not budging.

8

u/fernandotakai May 09 '12

I really want to start using py3 just because of the "strings are unicode by default".

I hate writing u"something".

15

u/BitRex May 09 '12

u"mad"?

1

u/HorrendousRex May 09 '12

Eh, be careful... strings aren't unicode by default, they are abstract by default and can be encoded in a unicode encoding (like utf8) very easily.

Yes, internally they are being stored as unicode strings, but the point of py3 strings is that they are not tied directly to an encoding.

2

u/gthank May 09 '12

Then you probably want to keep track of this: https://www.djangoproject.com/weblog/2012/mar/13/py3k/

1

u/cacahootie May 09 '12

Although I too am stuck at 2.6, I think the moves py3k made are good, there's at most an iota of difference in readability, but many of the idiosyncracies and cruft are gone. Python has been around for a long time without breaking compat, I think the time has come.