Hacker News new | ask | show | jobs
by rbanffy 4605 days ago
> C# 4 added serious dynamic typing, so that you can make ruby/pthon/js-style dynamic objects;

So you can match the so-so performance of dynamic languages (which is debatable, BTW) with C#'s horrid (when compared to Python or Ruby, at least) syntax.

I fail to see the advantages here. If I'm doing something that demands dynamic types, I do it in Python. If I need static-types, I do it in C, C++, Objective-C, Go, Java- whatever better fits the problem.

4 comments

The purpose of dynamic is not to turn C# into a dynamic language. It was added to make it easier to interface with certain other parties. Sometimes you just don't have the type information (practical example is handling JSON data) and dynamic can make the code cleaner in these cases.

More about this: http://msdn.microsoft.com/en-us/magazine/gg598922.aspx

Dynamic typing support helps in a pinch in C#, as you can avoid a lot of code in some cases where performance isn't paramount. I've personally used that in a few cases in the past.
Develop in Asp.Net MVC and change your viewmodels to dynamic (ExpandoObject) types.

You'll notice the advantages :)

ps. want to iterate over the object like in reflection, just convert the object to a (IDictionairy<string,object>)

What problems are there that you would consider choosing a statically typed language for them, because of the typing?
Static typing helps generating very concise and fast native code. I'd go with C or C++ when speed and or very precise control are absolute requirements. It also doesn't hurt you when you have a clearly defined problem that will never change - when you know you'll never receive a float instead of a 64-bit integer.

But there are other reasons to pick static typing. Using Java is natural for writing Android apps, Go has a very natural syntax for expressing concurrency and C# is the best choice when you want to write a Windows app. A programmer should always pick the language that better fits the problem it has to solve.