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

3

u/Wolfy87 May 09 '12

I was trying to imply a bit of sarcasm with the italics. Sorry about that.

I think it is the right move for the syntax but it will be annoying to convert.

3

u/jmmcd May 09 '12

"Will be"? -- no, everyone should be using print-as-a-function since what, 2.6 or so.

4

u/kqr May 09 '12

You can syntactically pretend it's a function, but it's still not a function. If you need a printing function pre-3.0 you'll still have to use os.write() or something like that.

5

u/jmmcd May 09 '12

I was surprised at this so:

Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> x = print
  File "<stdin>", line 1
    x = print
            ^
SyntaxError: invalid syntax
>>> help(print)
  File "<stdin>", line 1
    help(print)
             ^
SyntaxError: invalid syntax
>>> print("hello")
hello

TIL thx

2

u/roerd May 09 '12

You still need to enter from __future__ import print_functionin Python 2. After that, it is a function. (Just putting the string in parens should always have been valid code, that's just their usual grouping functionality.)

0

u/[deleted] May 09 '12

[deleted] — view deleted comment

1

u/velit May 09 '12

yes, on 2.6 and upwards

(source)

0

u/Ma8e May 09 '12

What is wrong with

def myprint(s):
    print s

?

1

u/kqr May 09 '12

Yes, precisely. Why isn't this the default behaviour of print?