Earlier quoted context omitted.
> No languages are inherently "compiled" or "interpreted", that's a property of the implementation. A language and it's implementation are usually designed at the same time. Compiled or interpreted will affect design choices that go into the language. While additional implementations may follow, it can be hard/impossible to design a compiler (machine code, not byte code) for a language that was designed to be interpr…
Not really - Javascript was designed to be interpreted, and yet V8/SpiderMonkey/Nitro all JIT-compile it down to machine code, sometimes very effectively.
Common Python Mistakes
51–60 of 146 posts
Re: Common Python Mistakes
#52 # mypackage/__init__.py
from .settings import settings
and when trying to import settings from mypackage from mypackage import settings
you get module instead of settings object.Re: Common Python Mistakes
#53This list is an excellent summary. If tasked with a #11 I'd probably add the slightly more obscure, but still super painful (when you do run into it) implicit string concatenation: >>> l = ["a", ... "b", ... "c" ... "d"] >>> l ['a', 'b', 'cd']
>>> l = ["A", "c""d"] >>> l ['A', 'cd']
Re: Common Python Mistakes
#54I have just been asked by a colleague about yet another gotcha when you have for example: # mypackage/__init__.py from .settings import settings and when trying to import settings from mypackage from mypackage import settings you get module instead of settings object.
Re: Common Python Mistakes
#55Earlier quoted context omitted.
Doing (x, y) = (5, 6) makes it clearer to "visually grep" that it's not a normal assignment though.
It's the comma that determines an expression as a tuple, not the parentheseis.
x = ,
causes a syntax error, while x = (,)
creates an empty tuple.Re: Common Python Mistakes
#56This is a pretty good list of gotchas, but it's important when writing something targeted at beginners to be as precise and clear as possible. Nearly every section here either uses terminology poorly, is slightly incorrect, or has difficult examples. Python supports optional function arguments and allows default values to be specified for any optional argument. No, specifying a default is what causes an argument to b…
Hey, thanks for the great feedback! We agreed with (almost :-) ) all of your comments and have made corresponding mods/corrections to the post. Thanks again! [Toptal blog editor]
Re: Common Python Mistakes
#57> "Python is an interpreted, object-oriented, high-level programming language with dynamic semantics." I have an issue with that statement. No languages are inherently "compiled" or "interpreted", that's a property of the implementation. If we are talking about CPython here, Python code is compiled to bytecode which is then interpreted. Not unlike Java - with the difference that the main implementation has a JIT and…
The compiled vs. interpreted thing is kind of a historical relic that people still cling on to. It's not dissimilar to where one draws the line for "scripting" or "nth generation" languages; it's all somewhat nebulously defined.
Re: Common Python Mistakes
#58numbers = [n for n in range(10)]
this should be: range(10)
Re: Common Python Mistakes
#59> "Python is an interpreted, object-oriented, high-level programming language with dynamic semantics." I have an issue with that statement. No languages are inherently "compiled" or "interpreted", that's a property of the implementation. If we are talking about CPython here, Python code is compiled to bytecode which is then interpreted. Not unlike Java - with the difference that the main implementation has a JIT and…
Re: Common Python Mistakes
#60There are more than a few interesting points in here but this is funny to me coming from someone who is seemingly well versed in python: Mistake #5 numbers = [n for n in range(10)] this should be: range(10)