Type Systems
This issue is going to deviate a tiny bit from the more theoretical format. Instead, we're going to dig into why I prefer static type checking and strongly typed languages. I've been asked about this a lot recently and figured that this would be a good one to fossilize as a Read Only Memory.
Typing in regards to a programming language is not the same thing as typing as in a keyboard. Typing is the idea of assigning a type from a logical type system to data in a program. There are lots of forms of typing and many different forms of type systems as well. Different type systems support different ideas and concepts.
Two of the biggest differences between type systems are whether they are loosely typed or strongly typed. A very clear example of the difference is JavaScript and it's (almost) superset language TypeScript. Indeed, the name TypeScript came from adding strong Typing to JavaScript. In JavaScript, we dont have to declare that our data is a number or a list, in fact, there's not really a good way to effectively do that outside of code comments. On the contrary, TypeScript allows us to specify the type that our data represents.
TypeScript is considered a flexible type system as you technically do not need to specify any types, although with those approach you're removing many of the benefits of the language by doing so. However, this allows you to gradually add types to existing JavaScript codebases, which eases with adoption.
Haskell is another language that is often complimented on it's rich type system. Every expression in Haskell has a type. Because of this, the compiler is able to be extremely helpful by ensuring that the code should works as written (you may still have logical bugs though!). This helps avoid an entire class of problems where code is shipped to a user down that exists behind an uncommonly accessed page or flow of logic and then months later when its accessed, the code breaks. With stricter classifications of languages, they can help eliminate entire classes and styles of bugs. Rust is another great example of a language that leverages a rich (and strict) type system to help heavily optimize and check code at the compilation layer.
There are also dynamically typed languages that can be either strongly typed or loosely typed. Dynamically typed languages have their types determined at runtime. A commonly used dynamically typed language is PHP, as an example. Because PHP implements this philosophy, you can still get some of the same benefits of strictly and statically typed languages even when not using a language that requires you to declare types.
You may have picked up on my bias at this point. I prefer stricter languages with strong types. You generally get better IDE support and avoid a large class of bugs simply by choosing to use a tool with that type system paradigm. However, these languages and tools can be difficult for people to use, too. If you're the type of person that likes to see gradual progression as you fix issues and likes to explore your running application in real-time, JavaScript is probably going to feel better to you than Rust. I've often joked that I'm "bartering with the compiler" when writing Rust for that very reason. However, once you get used to bartering with the compiler, it can actually provide just as great of an experience and ultimately help you produce safer code.
Ruby is another interesting example. Ruby is a dynamically typed language that, to me, feels extremely flexible. Flexibility is extremely nice when it works, but when something is wrong that flexibility manifests as a "This variable could be anything. I have no idea what it is in this path but it looks like its supposed to be a map." For me, this ruins my peace of mind about the code I ship, and for this reason, I generally try to spend less time coding in this class of languages.
领英推荐
Type Systems are way, way more in depth than I've covered here. If you're interested in learning more Types and Programming Languages is a really educational read. Additionally, a lot of the languages mentioned have type systems that fit into multiple categories -- Please don't come at me with a torch and pitchfork. I understand that a language's type system can fall into multiple categories ??
Learn you some new tech for great good!
Flutter is an open source framework by Google for building beautiful, natively compiled, multi-platform applications from a single codebase. Flutter uses the Dart programming language (remember 2013?) which was built for client-centric development. Flutter supports building for iOS, Android, Web, and native desktop applications. I really, really love this technology and hope that you will too!
Shoutouts
Thanks again for reading! Enjoy your week!