Strong Typing vs. Loose Typing

On January 14, 2012, in Programming, by LuCuS

Strong vs WeakA few days ago, I told you about a conversation I had with some co-workers about the future of programming. One of the questions that was brought up in that conversation was should the “next programming language” be strong typed or loose typed? One of the others in the conversation completely believes that strong typing is the only way to go. Being a student of all programming languages, I have mixed feelings about this. Before I get into that, let me explain the difference between strong typed and loose typed programming.

To begin with, programming is nothing more than writing a list of commands that the computer must follow. To do that efficiently, the program needs to know what data type each object is. For example, the application needs to know if an object is a string or if it’s an integer. If it’s a string, the computer doesn’t know that “one plus one equals two”. Instead, the application needs to know that you have 2 objects, both of which are integers and can be added together. That way, when you want to add them, it can simply process 1 + 1 = 2. So, any object that has its object type explicitly defined is known as being “strong typed”. Anything that isn’t explicitly defined is known as being “loose typed”.

So, what does it matter which I use? Well, depending on which programming language you use, you will typically be forced to use one or the other. For example, if you’re programming in languages like Java or C#, you are required to tell the application what the data type is for each object used in your app. If you’re programming in languages like Perl, PHP, or Python, you don’t need to define your object types as the interpreters can figure it out on its own.

Ok. Then why should a developer prefer one over the other? Well, depending on who you ask, you will get different answers.  For example, one of my co-workers will only work with languages that rely on strong typing because he feels like it’s easier to look at a chunk of code, even when taken out of context, and know explicitly what type of object he’s looking at. While that’s true, an experienced coder can also look at a loose typed chunk of code and identify what type of objects he is looking at. Does the object value have quotes around it? Is it being used in an arithmetic formula? Does it include a decimal? These are some of the checks that interpreters follow when auto-identifying object types for loosely typed languages.

Even though I like the ability to explicitly tell my application what my object types are, I sometimes feel it time consuming to be required to do this for every object in my application. Take the code snippet below for example.

String name = “”;

The object type declaration makes up 35% of that line. Over time, this can add up to a lot of time wasted declaring data types for every object in an app.

There are plenty of other reasons to prefer one method over the other, but I won’t get into those right now. The examples listed above are enough to raise the question to other developers out there. What method do you prefer? In the comments below, let me know if you prefer strong typing or loose typing and let me know why. In the dicussion I had with my co-workers, we were split down the middle. But, for me, my answer is always based on the language needed for the job at hand.

Thank you for your interest in my site. If you find the information provided on this site useful, please consider making a donation to help continue development!

PayPal will open in a new tab.

Related Posts

Tagged with:  

Leave a Reply