DEV Community

Cover image for What is the difference between Statically and Dynamically Typed Languages
Nibodh Daware
Nibodh Daware

Posted on • Updated on • Originally published at nibodhdaware.me

What is the difference between Statically and Dynamically Typed Languages

There are 2 types of programming languages Statically or Strictly typed and Dynamically typed, but what is the difference between the two, why do programming languages have types anyways?

If you are wondering about that question, I got you covered, in this post we will be discussing what are the Differences between Dynamically typed and Statically typed programming languages.

Overview

gif

Dynamically typed languages are languages that go through an interpreter and the types are automatically assigned so you don’t have to worry about what type a particular variable is or what is the return type of a function or a method, it is automatically understood by the interpreter. Some languages in this category are Python and Javascript, they are really easy and fast to write even complex applications.

On the other hand, Statically or strictly typed languages are where you have to explicitly tell the program what type of a particular variable or a function is so the compiler doesn’t have too much work, and hence the program is faster to compile and run but slow to write. Languages like C, C++, and Java come in this category.

Nitty Gritty Details

gif

Dynamically Typed:

As said earlier these languages are easy to write and fast to develop apps in like I can build Pong in Python in 1 day whereas it will take quite some time to do it in Rust which is also a typed language like C++. As these languages will be easier to write, the market will be a lot more saturated as everybody is learning the same tech, also as apps are made faster in these languages, the business and startup market is in need of developers in such languages, as a good MVP is needed and fast.

Also, most people who learn languages like Javascript are more likely to start a business or their own thing as the entire stack is theirs and they can move from front end to back end to database in just one language.

Statically Typed:

These languages are helpful in getting you a job in Big tech giants like FANG (or MANG now), as these companies care about speed as they have grown so much they need to get faster to keep all the users up to date and for that statically typed languages are way to go, like Google’s servers are written in C++.

Just don’t get confused by what I say (or write) but these Big Tech companies also use Dynamically Typed languages as the languages might be their original stack or the stack might benefit the company. Like Instagram uses Python for their servers (the Django framework to be exact).

Conclusion

The main point I want you to take away from this post is, that the language you learn at the start does not matter, what matters is you stick to one language and learn it inside out. And once you do that you can start applying to roles in that particular language.

Top comments (3)

Collapse
 
cappe987 profile image
Casper

There also exists type inference in some statically typed languages (Haskell, for example) where you don't have to write out the types at all (like a dynamically typed language). The compiler is able to infer the types anyways.

Interpreted vs compiled is not a strict indication of the typing. You can compile dynamically typed and you can interpret statically typed. Though, dynamically typed may not benefit as much from compiling since the types are not known until runtime. And statically typed benefit more from compiling vs interpreting.

The main difference is really whether types are known at compile time or runtime.

Statically typed helps immensely when working with larger pieces of software, which is a reason it is popular among larger businesses. It is much easier to maintain. Dynamically typed get messy more easily, and not being able to know types makes it harder to navigate.

most people who learn languages like Javascript are more likely to start a business or their own thing as the entire stack is theirs and they can move from front end to back end to database in just one language.

People who can't learn a new language probably won't get very far with their business. And there are more stacks than Javascript available to make products from.

Collapse
 
miketalbot profile image
Mike Talbot ⭐

Just to point out - V8 does compile JavaScript at runtime to have static types based on usage, which can lead to highly optimal code if functions are called with constantly typed parameters, and can lead to deopts if they are frequently called with different arguments - in these cases the code does need to be interpreted.

Collapse
 
brense profile image
Rense Bakker

There's no difference in speed when writing statically or dynamically typed languages. Speed comes with experience in either. The major difference between dynamic typing and static typing is that dynamic typing is more forgiving, which results in more runtime errors, whereas with static typing you get almost all errors at compile time, which makes for easier testing and less chance of the end user being confronted with an error or other unexpected behavior.

Also it's not true that startups use dynamic typing for speed, startups tend to use newer/hyped technologies, right now Typescript (statically typed) and Python (dynamically typed) are popular, but 10 years ago a lot of startups used Java because Java got hyped. Java is famous for being the most horrible statically typed langauge in existence :P

Btw, statically typed languages are available with a variety of different typing systems, for example the way in which type inference is implemented differs between different languages. Type inference is similar to how you described dynamic typing (it "guesses" the type based on the value), but instead of producing runtime errors, it will catch typing errors at compile time. Typescript for example does this:

// if you compile this with Typescript, this will produce a compilation error:
// Type 'number' is not assignable to type 'string'
let myString = "test"
myString = 10

// this function will have return type: boolean because of type inference
function userIsOld(age: number){
  if(age > 55){
    return true
  } else {
    return false
  }
}
Enter fullscreen mode Exit fullscreen mode