4 ms·
Those people are also missing the point that not having types means you are inherently writing a slow program.
by giulianob 7y ago
Those people are also missing the point that not having types means you are inherently writing a slow program.
- diggan 7y agoThat's the first time I heard that any language that doesn't have types, is slower than a program with types. I'm unsure if that actually makes sense. You mean slower as in performance? I'm having a hard time understanding how types == performance, so you have to mean something else. I guess assembly would be the language you would use if you really need to squeeze out the maximum amount of performance of a single CPU, and as far as I know, it does not have types. Also languages built on top of LLVM could get by with trading compile times for run time performance. Maybe you meant compiling gets slower without types?
- Arnavion 7y agoStrong typing means that at runtime dynamic behaviors don't need to be accounted for. For a compiled language, the compiler could know that `foo` and `bar` are 32-bit integers, and thus compile `foo + bar` to call the addition function for 32-bit integers. In an interpreted language, the interpreter could do the same thing. Without that typing information, both would have to invoke a generic addition function that detects the types of its arguments at runtime, notices they're both 32-bit integers, and delegates to the corresponding addition function. Of course there are tricks that can be played in the weakly-typed case, like assuming the same call site will always have the same types, so that there can be a short path that assumes that and only branches rarely. That way the first or first few executions might be slow, but eventually they get almost as fast as the statically-typed case. JS engines in particular and JITted runtimes in general usually do this. >I guess assembly would be the language you would use if you really need to squeeze out the maximum amount of performance of a single CPU, and as far as I know, it does not have types. Assembly absolutely does have types. The addition function for 32-bit ints only operates on 32-bit ints, and is distinct from the addition function for 64-bit ints.
- mr_toad 7y ago> Assembly absolutely does have types. The addition function for 32-bit ints only operates on 32-bit ints You can add any bits that will fit in the relevant registers. Assembly cares not whether the programmer thinks they are ints.
- Arnavion 7y agoYou should read the part of the sentence you cut off in your quote.
- jbboehr 7y agoDynamically typed languages still have types internally, they just look like this [0] (imagine it all implemented in assembly, without C's types, if you prefer). [0]: https://github.com/php/php-src/blob/3709e74b5e495e210ada8039ed81fafa9cbadcdb/Zend/zend_types.h#L282-L328 https://github.com/php/php-src/blob/3709e74b5e495e210ada8039...
- giulianob 7y agoGreat example of how bad dynamic languages represent data in memory.
- dragonwriter 7y agoTypes are information about the code which enables compiler optimizations, so statically typed languages generally can be faster than dynamic languages. They aren't, always, of course, and other factors come into play.
- giulianob 7y agoYes, absolutely a language without types is slower. Performance nowadays is almost always due to memory access patterns and allocations. Dynamic languages not only do not often have enough information to properly allocate memory in an efficient layout but they also tend to allocate a lot overall. Assembly is generated by languages that are compiled natively or on the fly for JIT languages. The type info is used to generate more efficient assembly.
- dang 7y agoPlease don't post grand unsubstantive claims to flamewar topics. That's bomb-throwing and usually leads to silly explosions.
- giulianob 7y agoReally look at any significant benchmark or what types of projects use which languages. The evidence is extremely clear and makes sense due to how computers work.
- Roboprog 7y agoThat was certainly true in 1990. The use of JITs has changed that to a large extent, as frequently used code paths can be rewritten at runtime in many cases. Static types tend to push people towards copy-pasta code, as well, which can even work against performance.
- smt88 7y agoThe factors affecting program speed are numerous, and I would guess that types do not have nearly the greatest effect. Most of us are not optimizing for program speed. Machine time is cheap. Human time is expensive. The biggest cost-savers for most programmers will be the ergonomics of a language, not the optimizations available to the compiler.
- mr_toad 7y agoSo assembly code is slow?