I’ve known about the new dynamic keyword in C# 4 for about a year now but really haven’t thought much about it. It’s suppose to be syntactic sugar for dealing with things like COM interop and objects from other DLR languages. This can be done now by using the existing reflection framework/library, but it can be tedious dealing with method name strings and the chain of method calls needed to get to the method invocation. Variables declared as dynamic bypass static type checking.
I came to the realization today this new keyword might well trigger the downfall of western civilization. Not only can this keyword be used for local variables, but also method parameters and return values. If you have experience working in Corporate America, you know that the there are plenty of developers out there who will abuse this keyword to no end. Can you imagine a ginormous, multi-thousand source file code base littered with dynamic!!! Methods that return dynamic!!! Methods that take dynamic!!! Does this not frighten anybody? I’m so scared. Am I alone? Can we stop this?
It will be no worse than various other dynamic languages, none of which have caused the downfall of western civilization *yet*.
And then you’ll switch to Python. Zi Horror. NOOOOOOOOOOOOOOOOOOOOOO
As any new language feature, it will be abused. This does not mean languages should not evolve. A bad thing about language abuse and C# is that the new features will not be abused by “Corporate America”, but also by microsoft employees. An example of language abuse in C#3 is the use of anonymous types for things like routeconfiguration in asp.net mvc. How do we stop this: Just tell the abusers on a friendly way how to code better.
> Just tell the abusers, in a friendly way, how to code better.
sadly, there are two flaws with this
(1) programmers are often quite independently minded people
(2) your first contact with other peoples code is normally at the point its too late for your advice to help
there is a natural trade off between language feature ‘power’ and how readable (or open to abuse) the resulting code is. Java has the interesting property that bad programmers will toil for a long time writing very verbose code that can normally easily be unpicked and discarded. C# features like true function types and maybe the dynamic keyword are likely to make this more difficult.
Many useful code navigation and alteration tools will not work with dynamic types, so I’m also in the camp that assumes this will maybe do more harm than good.
All this will really do is allow even worse programmers to write silly applications that will break in slightly different situations.
For the people who actually know what they’re doing this can be a really nice feature