Strongly-Typed Languages

How do you feel about working in strongly-typed languages?

I generally like working in a strongly-typed language, at least for bigger projects.
As I understand it, there's actually not a really firm definition for "strongly-typed", so I'll just define it as a language where the type of all variables is known at compile time, either explicitly by the variable being declared as such or implicitly by it being assigned a value from another variable which has an explicitly-declared type.
There are a few reasons I like strongly-typed languages:
1. You're less likely to get your variables mixed up and use the wrong value for something. For instance, if you have a function that takes two arguments of different types, and you try to pass two objects to it in the wrong order, the code won't compile, and it certainly won't run. In this way, you avoid the grief of getting bizarre behavior due to the runtime environment trying to interpret an integer as a character or whatnot.
2. You can tell that you've made a mistake like the one in (1) before runtime. I think typically you will know as you're writing the code that something is wrong, as usually an IDE compiles things to a certain extent and will let you know there's a mismatched type. And I would imagine most development-grade text editors have a plugin or tool to achieve parity with this functionality. This makes the coding process much more efficient. If you can notice and make a fix in under 3 seconds, it's a big time saver over having to spend a minute or more compiling, running, and getting to the piece of functionality you're trying to work on.
- for what it's worth, this also makes a decent case for non-case-sensitive languages.
3. A belt is restrictive, but it's a lot less restrictive than holding your pants up with your hand. That is, as in many other areas in life, there is freedom to be found in rigidity. When you know something cannot go wrong because you have rules that are always followed whether you want to or not, you are more free to charge ahead with an intended action plan. If you know your types are straight and can quickly tell what methods are available to that type, you don't have to frequently flip back through definitions to make sure things will behave as intended and you can get more done.
So that's all lovely.

For much smaller items, however, it can be nice not to use strong typing. Occasionally, I just want to run a microscopic algorithm within the context of some html and not go through the trouble of defining a class. Although, that may not actually be a function of something being strongly or weakly typed. It may just be that javascript is the only language I know I can do that with, and it just so happens to be weakly typed. I can't really think of a reason a strongly-typed language couldn't be used in this way.

So yeah, maybe weak typing is good for nothing.

Comments