Types undeniably greatly reduce and perhaps even eliminate certain classes of bugs from occurring such as misinterpreting data stored in a variable/register/etc. so I see how type safety is important in this respect. Just compare C to Java - it is rather easy to accidentally create a segfault in the former if you're not careful enough but the most you'll get in the latter is a
NullPointerException if you're really unlucky. However, in my opinion, modern programming languages like Swift have taken it way too far.
What do I mean? In modern programming languages like Swift, Kotlin and Go where type safety is emphasized above everything, you can't even multiply an integer with a double without explicitly type-casting the integer into a double first. This makes code containing numerical calculations involving both integral and floating-point types unnecessarily verbose when it should be very simple and straightforward. I get why implicit type-casting from double to integer (for example) are prohibited in languages like Java (since it's a lossy conversion and the programmer may not have intended it to be so) but preventing implicit type-casting the other way round is just absurd. What bugs can you possibly make by "accidentally" multiplying an integer by a double?
Another thing that I find really annoying is how Swift/Kotlin (and possibly Go?) treats nullable and non-nullable types completely differently. At least in Swift, everything is non-nullable by default (even reference types!). This means that if you want to define a recursive data structure such as a linked list, you have to explicitly mark it as nullable or else the code won't compile. And when you try to dereference a nullable type, you can't even use the dot notation (e.g.
someObject.somePropertyOrMethod) plainly - you have to "safely" dereference it by prepending either a
? or a
! to the dot. All this means that the programmer has to remember an extra set of rules and do more typing just for the sake of "type safety". I get that this is intended to reduce the chances of a "null pointer exception" occurring but if an inexperienced programmer abuses the
! dereferencing just to get his/her code to compile then a null pointer exception will happen anyway!
My point is, adequate type safety is important especially for inexperienced programmers (hence they should learn a safer language such as Python/Java first before they learn C/C++) but the way it is done in modern "type-safe" languages like Swift is more akin to "helicopter parenting" - it tries to shield you from all possible sources of danger but does so in such a controlling manner that harms the developer in the long run. What do you think?