4 ms·
> However, Python doesn’t have the compile-time check, because it’s an interpreted language that is dynamically-typed, which means its only real place to check
by L3viathan 3y ago
> However, Python doesn’t have the compile-time check, because it’s an interpreted language that is dynamically-typed, which means its only real place to check is at runtime
Pet peeve: Python is compiled (into bytecode), so it could theoretically do checks at compile time. The "dynamically-typed" part is correct and is the real reason.
- remram 3y agoTypeScript is also interpreted, and does type checking without running code. Their argument is very weird.
- SlimTim10 3y agoThat's an odd thing to say. The distinction between compiled and interpreted languages is very fuzzy, but TypeScript is clearly on the compiled side.
- gpderetta 3y agoIt is not so much that it is fuzzy, it is that the two definitions are not exclusive. A compilation translates a language to another, whether it is native code, internal bytecode, portable bytecode, or another source language. Compilation might also type check and optimize depending on the language. Interpretation executes a language; normally bytecode is executed, but pure source level interpreters exist. Native code is "interpreted" by the cpu itself of course. For example JAVA is certainly a compiled language, but it is typically compiled to bytecode and then interpreted or JITed (which is a combined interpreter/compiler).
- remram 3y agoLikewise, the Python typing annotation language could very well be on the compiled side... Someone took the interpreted JavaScript language, added typing syntax on top, and typing can be checked statically. The Python team took the interpreted Python language, added typing syntax on top, and here we are reading a claim that it can't be checked statically because it's interpreted. You understand my puzzlement.
- kaoD 3y agoTS is not interpreted. It compiles to JS, which is interpreted, but TS itself is not. There are no TS interpreters, they all compile to JS behind the scenes. Or does Deno run TS natively? At a glance it looks like even its runtime is written in JS[0]. EDIT: looks like they have bindings for V8[1] so yeah, just a JS interpreter behind the scenes. [0] https://github.com/denoland/deno/tree/main/runtime/js https://github.com/denoland/deno/tree/main/runtime/js [1] https://github.com/denoland/rusty_v8 https://github.com/denoland/rusty_v8
- arnsholt 3y agoThe problem for Python with type checking is that the language has essentially no compile-time constructs at all, just a bunch of assignment operators with different syntax: `def` assigns a function object to a variable when it's executed, `import` assigns a module, `class` assigns a class object. This means that everything involving names in Python is just a variable lookup (incidentally, this is why a function call must follow the declaration in Python: the variable is unbound if you haven't executed the function definition yet). The reason `Sequence` fails in the example in the article is simply that the code is trying to read an unassigned variable, no different from writing `vairable` instead of `variable` in your code.