views:

1123

answers:

12

I heard on some podcast that C# is not dynamic language, but Ruby is. I searched online to understand why, but no success.

So here is my question; what is “Dynamic Language”? Is this means there’s a static language?

Why C# is a dynamic language and what other languages are dynamic?

If C# is not dynamic, so why Microsoft is pushing is strongly to the market? As well why most of .NET programmers are going crazy over it and leaving other languages and moving to C#??

And why “Ruby is the language of the future.”?

Thank You,

[UPDATE]

I found this useful and nice post from Jeffrey Palermo http://jeffreypalermo.com/blog/static-vs-dynamic-languages-what-i-really-want/ which it make sense as he said: "I want static behavior between assemblies/libraries/packages but dynamic abilities within."

+28  A: 

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.

JaredPar
Thanks JaredPar, about "Why is Ruby the language of the future?" i heard that on one of podcast show, and the guys were talking about it as if it's fact. Now i know they were wrong...
egyamado
People are always declaring "the language of the future." It always happens to be their favorite language.
Chuck
+1 great points.
Chuck Conway
Note that there is nothing to preclude a language from supporting both static and dynamic typing. One such language is Curl.
Christopher Barber
+7  A: 

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.

Brian Genisio
+1  A: 

c# is statically typed, ie int i =0; try setting i to be a string. the compiler will complain,

where as python a variable that used to hold an integer can then be set to hold a string,

Static: Types are final, Dynamic: Types can be changed,

c# is trying to add more dynamic like features, var for instance

Fusspawn
var in c# is not a dynamic feature, it's just implicit typing. The type of the variable is still strongly typed and cannot change.
blowdart
var in C# is just shorthand to save typing.Also, a dynamic language is more than just dynamic types, otherwise you could use object or a variant to store all your variables.
Steven
+1  A: 

The words static and dynamic are not cleary defined.

However, what is most often meant is two issues:

1) In static languages, the type of a variable (that is, the type of value the variable can contain or point to) cannot change during the course of a program. For example in C#, you declare the type of a variable when you define it, like:

int a;

Now a can only ever hold an int value - if you try to assign a string to it, or call a method on it, you will get a compile type error.

2) In static language the type of an object cannot change. In dynamic languages, an object can change in that you can attach or remove methods and properties, thereby basically turning it into a completely different object.

JacquesB
Regarding (1): That's explicit vs implicit. There are many languages where you don't declare the type of the variable, but it's still static, with types checked at compile time. This is called type inference.
RHSeeger
+1  A: 

In C# 3.0, the types of everything needs to be known at compile-time. It's a static language. A dynamic language uses dynamic dispatch at runtime to decide the type of things and what methods to call on those things. Both types of languages have their advantages and disadvantages. C# 4.0 will add dynamic capability. Anders Hejlsberg gave a great talk on static v.s. dynamic languages and C# 4.0 at PDC.

JP Alioto
Wow. say it ain't so! Static typing is C#'s single greatest advantage over the rubies and phps of the world. Misspellings are compile-time errors rather than strange runtime inconsistencies. I certainly hope that dynamic typing can be turned off.
Jason Kester
@Jason: It's actually quite awesome what they are doing in 4.0. "dynamic" becomes a keyword to declare dynamic types, so yes, it's optional. :) But they are adding an entire Dynamic Runtime Layer ("DLR") as well. Great stuff. The video is nice too b/c at the end Anders goes into a bit about what's after 4.0. Very sweet stuff. Just a small spoiler ... REPL in C#!
JP Alioto
+1  A: 

There is no true "language of the future". Different languages have different purposes. At most, you could say Ruby is a language of the future.

According to Wikipedia:

Dynamic programming language is a term used broadly in computer science to describe a class of high-level programming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all. These behaviors could include extension of the program, by adding new code, by extending objects and definitions, or by modifying the type system, all during program execution. These behaviors can be emulated in nearly any language of sufficient complexity, but dynamic languages provide direct tools to make use of them. Most dynamic languages are dynamically typed, but not all.

Ruby is a dynamic language and C# is not, since Ruby is interpreted and C# is compiled. However, C# does include some features that make it appear dynamic.

luiscubal
>Ruby is a dynamic language and C# is not, since Ruby is interpreted and C# is compiled.This is completely wrong.
Steve Klabnik
+1  A: 

A dynamic language is generally considered to be one that can dynamically interpret & generate code at runtime. C# can't do that.

There are also dynamically typed & statically typed languages. Dynamically typed means that the type of a variable is not set and can change throughout the program execution.

Steven
+1  A: 

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.

Davy8
+1  A: 

Looking at the Wikipedia entry, we see that a dynamic language is one that does things are runtime that most do at compile time. Typically, in a dynamic language, a variable could change types quickly and easily, and there typically is no separate compile step (but rather either interpreted execution or really fast compiling). C# is a more conventional language, using variable declarations and being compiled.

The Wikipedia entry lists numerous dynamic languages.

"X is the Y of the future", on the other hand, means that somebody's trying to sell you something. (Not necessarily literally, but trying to influence your beliefs in a way convenient to the speaker.)

David Thornley
@David - "'X is the Y of the future', on the other hand, means that somebody's trying to sell you something. " +1 Excellent comment. Languages are like religions... there are lots of them and so single one is the best neither is the religion of the future. It just doesn't make sense.
jasonco
+2  A: 

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.

A: 

Did you know that VB6 is both static and dynamic?

If you declare variables with a given type, then you get static behaviour:

Dim name as Label

You can now only access members of name that are Labels and intellisense knows that.

If you have a class and add the implements keyword, then your class can implement methods of another class. This is inheritance of interface that VB6 allows. You can get some runtime polymorphism.

You can also declare variables like this:

Dim proxy As Object

Now intellisense doesn't give you any help and VB6 will allow you to do anything you like with proxy:

proxy.foo()

This line can sit inside a compiled and running program and cause no offence, especially if its not run itself. Its only when the line is run does the lookup take place.

You can also perform:

set proxy = <any instance>

and this will run. It doesn't matter whether <any instance> has a foo method or not.

And then any instance of any class that does implement foo can be assigned and the method called and VB6 will be happy.

Note that there are run-time performance penalties as you become increasingly dynamic.

quamrana