C Programming Tutorial 37 – Strongly Typed vs Loosely Typed Languages

This video is going to be an introduction to how programming languages consider data types. As we know, there are many data types in C programming. C is an example of a strongly typed programming language. Strongly typed means that every piece of data has a specific type.

Imagine if we stored everything in strings. This would become a problem because the computer would never know how to work with certain data. For example, let’s say we have “5” and “6” and we try to add them. Should the computer add the numbers to be “11”, or should it combine the strings to be “56” (The process of combining two strings like this is known as concatenation). Concatenation doesn’t work quite this way in C, but in general, these are the kinds of problems that come up when we do not have things strongly typed. The opposite of a strongly typed language is called a loosely typed language. Now, a loosely typed language is not quite this loose.

A loosely typed language will usually have a few general types such as numbers, characters, or strings, but they are not nearly as strict with the typing.

What is a good example of this?
 
In C, if we do something like this: 1/3, the result is going to be zero. That’s because the type of data being used are all integers. A loosely typed language is probably not going to be that obnoxious about types.
 
The benefit of using a strongly typed language is that it teaches you to be very discrete about what you want the computer to do. I think of a loosely typed language like water: it’s flowy and forgiving. I imagine a strongly typed language as very strict. Using a loosely typed language can be more simple starting out because you don’t have to worry about all of the different data types, but there is less protection as we will see soon.
 
For example, in a popular programming language known as JavaScript the type system is loosely typed. This means instead of having data types like integer, double, float, signed and unsigned, we just have numbers. Some people call the way JavaScript works with data types as duck typing…. Which is weird, but basically it says something like “if it looks like a duck, if it talks like a duck, it is a duck.”
 
Let’s say you write a function (which is just a section of code you can call multiple times) which expects a number. Whoever uses that function can pass in whatever they want, or pass in nothing at all.
 
Because JavaScript is not strongly typed, you have to do extra work inside of the function to make sure the function responds appropriately. What happens if somebody throws in an array? What happens if somebody throws in a string? What happens if somebody throws in a potato?

With a strongly typed language, you often have to pay extra attention to data types, but you have an extra layer of protection, too. Different people like different things.
 
In C, it is not easy to flow between data types. Because of this, we need something called type casting. That is what we will be discussing in the next video.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Support me! http://www.patreon.com/calebcurry

Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter

Donate!: http://bit.ly/DonateCTVM2.

~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~

More content: http://CalebCurry.com
Facebook: http://www.facebook.com/CalebTheVideoMaker
Google+: https://plus.google.com/+CalebTheVideoMaker2
Twitter: http://twitter.com/calebCurry

Amazing Web Hosting – http://bit.ly/ccbluehost (The best web hosting for a cheap price!)

Comments

Gerard Jagroo says:

You know that you are a natural teacher when you go out of your way to cut out paper ducks and print out alien pictures.
Thank you!
The internet needs more teachers like you, *the world needs more teachers like you!*

theasdazx says:

Well, im not an expert but i think you confused with statically typed and dynamically typed. Check out this question on quora and tell me if I am wrong. I might be mistaken. https://www.quora.com/Is-C-a-strongly-typed-language

nikoo malek says:

I love all of your videos, specially SignalR helped me a lot. You are not planning to do tutorial on C#, MVC and web api?

campbelljac131 says:

Very weird to see you grow up in these videos…. incredibly impressed with your knowledge and ability to convey it to many. Please keep up the great work I find your teaching to really help make the programming books make sense instead of just reading the same stuff many times confused. A Very Sincere thank you!!

faht fak carl says:

boi

Andis Aboltins says:

1:29 combinations of 2 strings or characters?

Digit Zero says:

Please do a series on laravel. I love your videos very much

AutoFirePad says:

My eyes hurt when I don’t see and ending semicolon.

TechAddict says:

Alien is a duck, mona lisa is a duck, duck is a duck, everything is a duck. “Quack Quack”

X says:

“So when it comes to finding your love, do not be loosely-typed.”

Dude. That’s some seriously sound advice… and a great learning analogy. 🙂

Tech Mech says:

such an underrated channel. good job bro.

 Write a comment

*

Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!