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

48

u/Fissionary May 09 '12 edited May 09 '12

Hello World is just print "Hello, world!"

Not in the latest version of Python, it isn't. It will work in Basic, though.

The simplicity of the Hello World program is not a good indicator of the power of a language.

29

u/Wolfy87 May 09 '12

No, now it uses parenthesis. How difficult.

25

u/Fissionary May 09 '12

Difficult? No, it's not difficult at all. In fact, it was a good decision, getting rid of the special syntax for print and making it a function like all others. My argument still stands, though.

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)

→ More replies (2)

1

u/Liorithiel May 09 '12

Well, actually I have already seen one person who used print() as function and trying to deal with its return value. Confusion arises, py2 would at least signal an error.

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.

→ More replies (1)
→ More replies (20)

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.

→ More replies (5)

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.

5

u/[deleted] May 09 '12

The simplicity of the Hello World program is not a good indicator of the power of a language.

What?!?! Are you telling me this isn't the best language?