18 AnswersNew Answer
Now that this thread comes to life, I think I could use some more concrete clarification of what defines strong & weak typed languages, having found my understanding of the subject was a total mess : ) And despite how interesting the definitions be, let's not to forget what the main topic was, the pros & cons of strongly typed languages. I'm going to learn a lot from this 😁
Sonic That is also what I understand about strongly typed languages. In Python we can declare variables without a strict need to first define their types, and later on we can assign a different type of data into those variables and things will be just fine. In C, C++ or Java this is not possible AFAIK. But I'm no expert either and also still learning all this stuffs.
From the top of my head: Strongly typed languages (like Python) have more safety because violations will give you Errors. On the other hand they also need more overhead than weakly typed languages (like C++) and are less flexible when it comes to optimizations at compile time. And now I'm excited to read what answers the pros around here will give to this interesting question . :-)
(Also only reading to you from a book I'm reading now: ;-)) Sonic yes, the implicit conversions seem to be a reason for calling it weakly typed. To me it seems a bit 'unfair' since you could also just rely on safe tools... but you have the freedom to deal with it whichever way (the compiler has it too). Having to declare and stick to the types of variables or not makes the difference between 'dynamically and statically typed' which is another thing.
Thanks a million to all for your replies, you're very helpful! ;) Apart from the integer-string combination example, can anyone provide more scenarios in which the typing could be relevant in terms of chosing a programming language for a project? Thanks again.
Ion Elberdin Navarro I can't really imagine a situation when strong / weak typing should be a main decision factor for choosing a particular programming language. It is just a given characteristics of the language. There are ways to handle type issues in both worlds, you just need to be aware of the impact and possible solutions.
I have a little experience with C# which is by definition "strongly typed". It means that you have to explicit the type during variable declaration and that you must always make a proper conversion of type to do what you want to do. In the beginning this can be annoying, but in the end, it cause you to pay attention to "what is" and "what it will turn to be" (adding a "control layer" in the code writing). Plus, if there are type coherence mistakes, then compiler won't compile and you have to debug. Annoying in the beginning (also for the quantity of code that you have to write) but paying and satisfying in the long run (when the quality of code is higher).
They prevent you from shooting yourself in the leg. They bind variables to a specific type making it easier to follow along how your code works i.e. what is making what do what unlike weakly typed ones.
HonFu Pointer reassignment is also another reason C/C++ is weakly typed, though C++ is more strongly typed than C
Stefano Re Yes one advantage of weakly typed languages is you type less code as you can take advantage of implicit type conversions and function overloading (you can pass int, float, double to a function taking double as argument, don't have to explicitly write 3 version (if precision is not important))
Tibor Santa I agree with you, nevertheless it's a factor that could be included in a trade-off analysis.
strongly -typed languages generally appeal to me. I feel like they protect me from myself. More than that, they force me to think through what I'm doing. A lot off code works in spite of us. Java makes us stay aware of the nature of our objects. It compliments sophisticated OOP, using static classes and interfaces.
BinaryEden, it's the other way around. What you are talking about is the difference of dynamically and statically typed! (See the other comments as well, especially Tibor Santa detailed description!)
Then Python (dynamicly & strongly tipped) C/C++ (staticly & strongly tipped)