Strongly typed languages | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 10

Strongly typed languages

What are the main pros and cons of strongly typed programming languages?

1st Apr 2019, 6:08 PM
Ion Elberdin
Ion Elberdin - avatar
16 Answers
+ 11
Statically typed = type check happens at compile time Dynamically typed = type check happens at runtime Strongly typed = variables are bound to a specific type Weakly typed = type safety is handled more loosely It is not an either-or classification; languages could be placed on a scale of HOW statically and HOW strongly typed they are. This article has an excellent explanation and a nice graph showing some popular languages on both scales. Python, Ruby, C# and Java are more strongly typed. JS, PHP, C and C++ are more weakly typed. https://android.jlelse.eu/magic-lies-here-statically-typed-vs-dynamically-typed-languages-d151c7f95e2b As to the question, I think strong typing has an advantage that it enforces the developer to use proper conversions that will produce the desired result. In weak typing you can add integers to strings, but you may not get the result you actually want. Like, try in Javascript: console.log(1 + '2') Strongly typed languages will produce various errors during runtime if the variable types are not respected. In a weakly typed language the same code may run successfully but it is up to the programmer to predict if different types might be involved and to understand exactly how the implicit typecasting of the specific language works behind the scenes.
2nd Apr 2019, 8:05 AM
Tibor Santa
Tibor Santa - avatar
+ 12
HonFu I thought C#/C++, Java are strongly typed whereas PHP, JS etc. are weakly typed. I don't know much about Python to comment on it but what makes you say that C++ is weakly typed? I thought that declaring the type of a variable before using it is what makes a language strongly typed. Maybe it is the implicit type conversions allowed in C++ that make it weakly typed? Note: I'm no expert and still learning about all this stuff.
1st Apr 2019, 11:03 PM
Sonic
Sonic - avatar
+ 11
HonFu thanks. I think I get it now. So the lesson for me today is that static Vs. dynamic typing is not the same thing as strong Vs. weak typing.
2nd Apr 2019, 2:48 AM
Sonic
Sonic - avatar
+ 10
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 😁
2nd Apr 2019, 3:25 AM
Ipang
+ 9
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.
2nd Apr 2019, 1:46 AM
Ipang
+ 8
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 . :-)
1st Apr 2019, 7:07 PM
HonFu
HonFu - avatar
+ 8
(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.
2nd Apr 2019, 2:10 AM
HonFu
HonFu - avatar
+ 7
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.
2nd Apr 2019, 8:39 AM
Ion Elberdin
Ion Elberdin - avatar
+ 7
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.
2nd Apr 2019, 9:11 AM
Tibor Santa
Tibor Santa - avatar
+ 6
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).
2nd Apr 2019, 3:41 AM
Stefano Re
Stefano Re - avatar
+ 6
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.
3rd Apr 2019, 5:14 AM
Dan Rhamba
Dan Rhamba - avatar
+ 5
Tibor Santa I agree with you, nevertheless it's a factor that could be included in a trade-off analysis.
2nd Apr 2019, 9:15 AM
Ion Elberdin
Ion Elberdin - avatar
+ 5
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.
2nd Apr 2019, 10:23 PM
Mark Matchen
Mark Matchen - avatar
+ 5
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!)
3rd Apr 2019, 11:18 PM
HonFu
HonFu - avatar
+ 2
Then Python (dynamicly & strongly tipped) C/C++ (staticly & strongly tipped)
4th Apr 2019, 12:06 AM
BinaryEden
BinaryEden - avatar
0
bookmark
10th Jun 2021, 6:31 PM
loop
loop - avatar