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

12

32

Listening to a podcast, I heard that C# is not dynamic language while Ruby is.

What is a "dynamic language"? Does the existence of dynamic languages imply that there are static languages?

Why is C# a dynamic language and what other languages are dynamic? If C# is not dynamic, why is Microsoft pushing it strongly to the market?

As well why most of .NET programmers are going crazy over it and leaving other languages and moving to C#?

Why is Ruby "the language of the future"?

Biggs answered 24/4, 2009 at 19:30 Comment(8)
Ruby the language of the future.. please!Hepza
@jasonco, I know. Cobol is the future.Glendoraglendower
LOLCODE is the future!Warbeck
We have several other versions of this question already ... https://mcmap.net/q/453819/-uses-for-dynamic-languages-closed ... #312382Caoutchouc
Recently Scott Hanselman uploaded an interview with Michael Foord about IronPython (another dynamic language), the interview is interesting and could perhaps give you some insight. hanselminutes.com/default.aspx?showID=177Fanatic
Thanks everyone for your answers, but why people voting it down? Is it not programmer related???!!Biggs
The one and only true language of the future is Lisp. It is the only one that has the honor of being the language of the future for over 50 years in a row!Necessarian
-1 for Why is Ruby "the language of the future"?Fourflush
G
74

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.

Glendoraglendower answered 24/4, 2009 at 19:30 Comment(4)
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...Biggs
People are always declaring "the language of the future." It always happens to be their favorite language.Brinson
Note that there is nothing to preclude a language from supporting both static and dynamic typing. One such language is Curl.Subminiaturize
Ruby is the language of the future of the one who where talking on the podcast show. These ones who move from RoR to .NET MVC they may say that Ruby is the language of the past. Also I heard from one Ruby devs that Ruby was created to make developers happy :). There is a lot of myths around that subject.Sharasharai
F
26

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.

Fourlegged answered 24/4, 2009 at 19:30 Comment(0)
W
6

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.

Whistling answered 24/4, 2009 at 19:30 Comment(0)
C
3

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.

Cartouche answered 24/4, 2009 at 19:30 Comment(0)
F
3

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.)

Formulate answered 24/4, 2009 at 19:30 Comment(1)
@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.Hepza
C
3

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.

Christenson answered 24/4, 2009 at 19:30 Comment(0)
M
2

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.

Montgomery answered 24/4, 2009 at 19:30 Comment(1)
Good to see someone who knows there is a difference between a dynamic languages and support for dynamic typing. I'm not sure that C# isn't dynamic though - you can certainly self modify objects at runtime.Ardellardella
C
2

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.

Calamitous answered 24/4, 2009 at 19:30 Comment(2)
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.Roving
@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#!Calamitous
R
2

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.

Removable answered 24/4, 2009 at 19:30 Comment(1)
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.Plumbery
L
1

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.

Lamarlamarck answered 24/4, 2009 at 19:30 Comment(1)
>Ruby is a dynamic language and C# is not, since Ruby is interpreted and C# is compiled. This is completely wrong.Minded
C
1

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

Candlepower answered 24/4, 2009 at 19:30 Comment(2)
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.Jeer
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.Montgomery
H
0

A language is dynamically typed, that means a variable in that can be used for anything. Variables are not typed, values are. A variable can have the value of any primitive type, or it can reference to any object.

Howerton answered 24/4, 2009 at 19:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.