Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a dynamic language, and why doesn't C# qualify?

What is a dynamic language?

Whether or not a language is dynamic typically refers to the type of binding the compiler does: static or late binding.

Static binding simply means that the method (or method hierarchy for virtual methods) is bound at compile time. There may be a virtual dispatch involved at runtime but the method token is bound at compile time. If a suitable method does not exist at compile time you will receive an error.

Dynamic languages are the opposite. They do their work at runtime. They do little or no checking for the existence of methods at compile time but instead do it all at runtime.

Why is C# not a dynamic language?

C#, prior to 4.0, is a statically bound language and hence is not a dynamic language.

Why is Ruby the language of the future?

This question is based on a false premise, namely that there does exist one language that is the future of programming. There isn't such a language today because no single language is the best at doing all the different types of programming that need to be done.

For instance Ruby is a great language for a lot of different applications: web development is a popular one. I would not however write an operating system in it.


In a dynamic language, you can do this:

var something = 1;
something = "Foo";
something = {"Something", 5.5};

In other words, the type is not static. In a statically typed language, this would result in a compiler error.

Languages such as C, C++, C#, and Java are statically typed.

Languages such as Ruby, Python, and Javascript are dynamically typed.

Also, this is not the same as "strongly or weakly" typed. That is something different all together.


I'm stunning at the way c# it's embracing a fundamental set of programming paradigms.

We can say that c# alows a rich object oriented programming, a rich component oriented programming, a well integrated functional programing, a complet set of query operations over differents types of data sources (linq), a elegant aproach of cocurrent programming through pLinq and parallel extensions, in the next release (c# 4.0) will have powerfull dynamic capabilities, and it's almost sure that in c# 5.0 will have a solid set of meta-programming features.

With just can say that c# it's doing a great job of integrating all this powerfull stuff in just one tool box. That's in my opinion it's the way it must be, because skipping from one programming language to another it's almost always very painfull.


C# is a statically typed language, because the type of every object you're working with needs to be known at compile time. In a dynamic language you don't need to know what type an object is at compile time. Maybe you import some classes that you don't know before hand, like you import all classes in a folder, like plugins or something. Or maybe even the type of an object depends on user-interaction.

You can achieve a similar effect by using interfaces or base classes, but it's not completely the same because you are limited to using classes that explicitly inherit from or implement that interface.

In dynamically typed languages it doesn't care what the type is when you compile it, it'll try to call the method you specified by name, if that method doesn't exist on the object it'll throw a run-time exception, so it's up to the programmer to ensure that that doesn't happen or handle it appropriately. You gain flexibility, but lose out a little on compile-time error checking.