What if clang says "did you forget a ';'"? It would have been better to just compile the code as if there was a semicolon?
I rather have something like this:
> Use exit() or Ctrl-D (i.e. EOF) to exit > >>>
Less pedantic, less passive agressive. Doesn't fake being nice to the user.
Back when Python 3 was first released, the error message was not so clear, either...
I have a pragmatic take on this if only because of Python's ease of throwing a script together and its non-technical userbase. Were it something that effects correctness I'd more fully support this break of backwards compat.
- It is a maintenance burden on the compiler/interpreter writers to allow both modes
- There may be unexpected behavior when you use code from two different sources; one that expects strict mode and the other expects non-strict mode
- There may be interpersonal conflict when developers working together prefer one mode over another
“Why don’t we just keep both?” probably has many answers. The overwhelming one for me is that if everyone’s doing the same thing two ways, then everyone has to learn all the esoterics about the print statement.
“Why don’t you just do it for me?” is a cardinal sin for a runtime. And already exists in migration tools.
see also: the recent addition of match semantics in python
Is `print >> obj` a print call with redirection to the file-like `obj`? Or is it a operator call between those objects? What does `f = print` do, assign the function object or the result of calling print with no arguments?
While the Python3 lexer is specifically hacked up to recognize the lexer-token for 'print' and to emit a token that triggers a special error-handling path in the parser if you then go on to make a syntax error per the newer uniform syntax, it doesn't actually know what you were trying to print. (That'd require a successful parse!) If the Python3 parser tried to do the compatible thing, that'd require ditching the uniform syntax altogether, and going back to the ambiguous parser.
It's a bit like Error Correcting Codes — the uniform Python3 parser knows enough to know that you did something wrong, and is provided by the lexer enough context to guess what kind of failure it was; but it doesn't have enough information to do the right thing, because that's a strictly-greater amount of information.
If you type `print "arg"`, the syntax error is a bit more informative, but I wouldn't say that the compiler "understands" what you mean. It's just making a guess based on the fact that the previous token was "print".
On the other hand, supporting a special call syntax just for print, which includes more than just parentheses, would be substantially more complex. And then Python code in the wild would be more inconsistent and there will be endless debates about `print <args>` versus `print(<args>)`.
This is perfectly exemplified by Python 3's insistence that you call print with parenthesis:
>>> print "hello"
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
I empathize with the lang devs in that having two forms of print is nonoptimal, but the fact it tells you to do something different while fully understanding what you said (as it were) is what really irritates me. It comes off feeling needlessly pedantic for the language.