Scala strict type system vs C ++ type system

For fans of the Scala system of a strict type, but C ++ fans:

  • Is it possible to force myself to program C ++ with the same rigor ? (without using void* , without exposing much, a simple type of box value, ie struct Month {int value;}; ).
  • Or is C ++ by default even more strict , and then Scala (unless you are trying hard to do the throws)? Despite the duck printing of templates in C ++, it still will not allow you to compile if it does not fit, right?
  • Does C ++ 0x (wrt to C ++ 03) add something for those who want to obey completely typical programming?
+4
source share
2 answers

Short answer: yes, you can achieve the same level of type safety, but it will put a strain on the programmer. This is not just a matter of ensuring the same security, the type system must also be powerful enough and flexible enough to facilitate type programming, and in this respect, a Scalas type system is superior to C ++.

C ++ 0x will add lambda expressions that will facilitate the use of HOFs such as map, filter, flatMap, etc.

+6
source

A system like C ++ is more strict than Scala.

  • No type erasure (even in pattern).
  • Ideally, there is no foundry type in C ++ (if you use direct casting, for example dynamic_cast, static_cast, from a C style cast, you will be accused of poor design, which are considered the latest low-level tools.).
-4
source

Source: https://habr.com/ru/post/1346667/


All Articles