Strong type vs. weak type

  • Strong is the tendency to treat undefined behavior as a fault (Java, Python), and weak is the tendency to make implicit conversions and ignore type-related errors (JavaScript).
  • Many poorly designed languages, while most of the time (or we usually encourage people to do so) are strongly typed, also have weakly typed parts (PHP)
  • In other languages, we have to use the weakly typed part (C) because the abstraction provided by the language is weak.
  • Duck typing is a compromise between strong and weak typing (common in dynamic typing, such as Python) that balances flexibility and rigor.
  • We think of weak typing as convenience, and strong typing as early detection of errors.

Dynamic typing vs. static typing

  • Statically typed variables are typed at compile time (C++, Java); Dynamically typed types are determined at run time (JavaScript, Python), for example you can assign different types to a variable in two branches of an if.
  • Some dynamically typed languages add compile-time type checking (TypeScript, Python), but because of the dynamic nature of the language, these checks only cover part of the story.
  • In dynamically typed languages, because the type is not so important, many times there is not even a syntax for specifying the type (implicit automatic derivation at runtime); Statically typed languages typically need to specify types for variables, which is why auto-type inference at compile time is a convenience that dynamically typed languages can’t do (because you can’t determine the type at compile time, let alone derive it).
  • We believe that static typing helps to find type-related errors at compile time, and that defining a type gives more room for optimization at compile time. Dynamic typing gives developers more flexibility.

Garbage collection vs. no garbage collection

  • GC free means that the code must manage the requested memory itself and free it when appropriate (Rust, C/C++); Languages with GC periodically look for unused memory to free through reference counting (PHP<5.3), tag copying (V8), and so on.
  • The process of marking the copied GC often causes the thread to pause and also costs extra CPU; But GC is also essential for building high-level abstractions: exceptions, closures, etc. (although C++ implements both features without GC, it also introduces very high levels of complexity).
  • We think that having GC simplifies memory management and creates complex abstractions; No GC gives you lower levels of memory control, resulting in better performance and less lag due to GC.

Virtual machine vs. native code

  • Virtual machines have a translation layer between the language and the CPU (JavaScript, Java); Virtual-free means that the compiler directly generates native code for the CPU to execute (C/C++, Golang).
  • Virtual machines also provide more complex runtime dynamic features, but these can sometimes be implemented without virtual machines (for example, runtime type recognition in C++, GC in Go).
  • Virtual machines can execute in interpreted mode (Python, where code is executed as a data instruction), just-in-time (JIT) mode (V8, where code is compiled to native code and then executed), or sometimes a mixture of the two (for faster startup).
  • We believe that a virtual-free language can interact with other programs at a lower level and also naturally have better performance; Languages with virtual machines can be easily cross-platform, compiling higher-performance code at run time for a particular architecture.

summary

language Strongly typed Dynamic type The garbage collection The virtual machine
C
C++ Y
Java Y Y Y
Python Y Y Y Y
JavaScript Y Y Y
PHP Y Y Y
Golang Y Y
Rust Y

Reference:

  • www.zhihu.com/question/19…
  • Eli.thegreenplace.net/2006/11/25/…