Type Looseness
The whole idea behind type loose languages is so that variables would be easier to use in comparison and other operations. You don’t have to declare how you intend to use variables. You just use them and they just work. Sounds great, right?
In fact it makes it much more difficult to use them. Type loose languages like PHP can be a nightmare in the evaluation of complex expressions because one not only has to look at what is apparent on the code at face value, one must also consider the complicated parsing rules when different types are banged up against each other. In type strict languages, we usually get a compile error when incompatible types are compared or misused, thus, allowing us to avoid embarrassing end-product behavior. In the type loose, interpreted PHP world, we get a runtime error (or somebody — not necessarily the coder during debugging — gets a runtime error) — maybe or maybe not, when operations are made on incompatible types. Mature programming languages, do not allow such problems to happen in runtime — or at least do everything they can to minimize such runtime problems.
It’s the difference between building a house of straw and a skyscraper of concrete and steel. Sure, you could build a huge building with bales of straw and it would be functional living or work space until the moisture problems and other problems set in. Then what happens if someone runs a truck into it? Or sets it on fire?
Have a gander at the PHP comparison operator page. Back in the old days we thought it was hard enough remembering the difference between = and == in C. Now there is a === and the way things are evaluated are TYPE BASED although there are loose restrictions on which types can go on which side. NOW not only do you have to understand what the type of the variable is, you have to understand when PHP is going to decide to convert your string into an integer or when it will convert it into some other type like a boolean.
Another problem with languages like Javascript and PHP is that they keep running even if serious runtime problems occur, often without even so much as a warning or any other kind of message to anyone anywhere. This is not a big deal with a high school or undergrad programming project where maybe you are trying to get the n-factorial or do your first shopping cart — but is it a good idea to build ANY business on top of that? Yet there are thousands…(maybe millions).
They say always use ‘===’ when comparing strings in PHP. I would say the best practice would be like the practice in C — use strcmp() and remember that 0 means TRUE if your question is “are these 2 strings the same?” (otherwise we get the mathematical difference of the ASCII characters between them.. For C this is a descendant of the assembler comparator, where the differences between the character values are subtracted from each other. 0 means they subtracted each other out exactly, meaning they are the same string of characters. I dunno where PHP thinks it’s going with that.
Or all hail the String.equals(string) comparison function in Java — where “true” means the strings are the same. With the “easier” type loose languages, you can be guessing and permuting code for hours, chasing down a bug.
In short, only coders who truly understand the consequences of type looseness should program in type loose languages. But type loose languages are ostensibly made to help people who don’t understand programming too well. It helps them alright — it helps them make mistakes that they can’t find.


