3 ms·
> I find "dynamic during runtime + static during development" to be a highly potent combination Except you miss out on massive performance gains and your softw
by brigadier132 3y ago
> I find "dynamic during runtime + static during development" to be a highly potent combination
Except you miss out on massive performance gains and your software runs 10x slower because of runtime type-checking. It's actually the worst of both worlds.
- baq 3y agoAnd yet machine code is basically untyped and fully dynamic. The world of computing is a strange place.
- civilitty 3y agoMachine code is type erased, not really untyped.
- nerdponx 3y agoIf you squint, you could say the same about Python code that's been checked with Mypy.
- shadowgovt 3y agoAt the machine layer, the machine is doing symbol manipulation on bit patterns. Whether those symbols ultimately mean anything is entirely up to the eventual observer of the end result. The concept of "types" breaks down at this level much like the concept of "a dog" breaks down at the atomic level.
- baq 3y agoIt's an implementation detail of popular architectures nowadays. It doesn't have to be like this. E.g. https://en.wikipedia.org/wiki/Tagged_architecture https://en.wikipedia.org/wiki/Tagged_architecture
- nerdponx 3y agoThe point is that you don't need runtime type checking if you can trust your type checker.
- frou_dh 3y agoI have seen people point out that this confusing discussion can be avoided by accepting that types are purely a static property of terms (not only identifiers and literals) in source code, and that what many insist on calling dynamic types are tags, not types.
- brigadier132 3y agoNo, dynamically typed languages literally have runtime type checking built in because the interpreter does not know the type of any individual object until runtime. Everything is stored on the heap, there is no cache locality for objects so every object property access has the performance of a linked list (or hash map, not good), and all method invocations require dynamic dispatch. What this means is your code will be slow as fuck for no reason. If your code is 100% typed and you managed to find a fully compatible compiler that actually took advantage of the type annotations you could see massive speedups and significantly lower memory usage (we are talking order of magnitude improvements).
- ska 3y agoThis was something nice about CL implementations like SBCL. When you needed fast you can fully type everything and unbox it effectivly, but it got out of your way when you didn't. Something approximating best of both worlds. Of course the fast code started to look like c, but that's not such a bad thing if you could localize it.
- shadowgovt 3y agoThere are few dynamic languages that go that far. Python isn't currently one of them; the runtime is still doing low-level type-compliance checks under the hood even if the static typing layer "knows" those checks are wasteful. At least in every compiler / runtime I'm familiar with for Python; maybe someone has built one that uses the types to generate faster code that's unsound if the static type assertions are violated. Other dynamic-typed-and-also-static-typed languages do allow for this. Many Common Lisp compiler implementations, for example, respect things like the (the) special form (https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node106.html https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node106.html), which acts as a static type assertion that allows the compiler to actually throw away the runtime sanity-checking (at the cost of producing actual unsafe code if the constraints of the form are violated).
- gaganyaan 3y agoHave you tried pypy? A 10x performance hit is very much an overstatement for lots of code.