Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Andy Stevens
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Andy Stevens
Front End Web Development Techdegree Graduate 20,417 Points

What's better dynamically or statically typed?

I'm genuinely interested to see others opinions on this, surely from a performance perspective statically typed is better? I say this because variables are declared and assigned and as such this process does not need to be completed at run time, thus saving on time even if we are only talking milliseconds.

Dynamically typed is slightly more human readable, but for me that is the only benefit. What are the other benefits if any?

1 Answer

Rune Andreas Nielsen
Rune Andreas Nielsen
5,354 Points

Hi Andy,

There are a few benefits to each of them. One of the major benefits of statically typed languages is that they can catch type errors at compile-time. The compile-time error catching can catch a lot of type errors that would first be shown at runtime in a dynamically typed language. Most static typed languages also come with better IDE-support (IntelliSense) that can both speed up the development process and help catch errors even before compile-time. The downside of a statically typed language is that it can take time to declare the static types and you will sometimes end up with a lot of type-casting that you would not get in a dynamic language.

The dynamic language can be really fast to develop in, not to be confused with runtime performance, but this development speed does come with the disadvantage of type errors at runtime which could have been caught by a statically typed language.

Some developers swear to statically typed languages so much that they make transpilers (Transpilers, or source-to-source compilers, are tools that read source code written in one programming language, and produce the equivalent code in another language). An example of this is TypeScript that is a statically typed language that transpiles to the dynamic-typed language JavaScript.

Just to clarify I personally don't see anything wrong with either statically typed or dynamically typed languages, personally I love working in both types and each of them has their upsides and downsides

I hope this can clear some things up.

// Rune