Replies: 8 comments 7 replies
-
We are not going to deprecate this as it would break huge programs around the world.
I don't know what this means. 'dynamic' is for dynamic programming. Where the type is not known. Generics are for generic programming, where the types are statically known, but you want code to specialize for each potential static type. Note: you are free to deprecate any language feature you want in your own projects. Writing an analyzer here would be about 5 minutes of work. This would be the only thing we would support wrt deprecation. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I've used dynamic to optimize performance by deferring the selection of a method overload until runtime. Normally, overload selection is done at compile time. My specific examples are in complex object domains that would take far more time to explain, but here's a simple illustration of the idea. We can define a minimal interface for a printer as public interface IPrinter
{
void PrintPage(Bitmap image);
} with implementations including And then we can define printable documents: public interface IPrintableDocument
{
void PrintTo(IPrinter printer);
} with implementations including Anywhere in my code, I can then print any document: myDoc.PrintTo(myPrinter); But, and here's where dynamic is super useful, this will always use the lowest common denominator implementation where each page is rendered as a bitmap image and send to the printer page by page. Some combinations of document and printer can function in a much more efficient way. For example, sending an To achieve this efficiency, we start by adding a couple of overloads of public class HTMLDocument
{
void PrintTo(EmailPrinter printer) { }
}
public class PostScriptDocument
{
void PrintTo(PostScriptPrinter printer) { }
} And then, we use dynamic when sending the document to the printer: var dynamic dispatchDoc = myDoc;
dispatchDoc.PrintTo(myPrinter); That's it. As simple as that, and now the most specific overload of |
Beta Was this translation helpful? Give feedback.
-
I wanted to touch on this. It's very much the case that lazyness is a virtue. As something of a developer myself, i like it when i can get more done with less effort on my part. Dynamic absolutely helps with that. So calling it (and developers who use it) out for being more effective isn't a good argument for getting rid of this extremely useful feature :) |
Beta Was this translation helpful? Give feedback.
-
Don't forget late-bound COM interop. 😅 |
Beta Was this translation helpful? Give feedback.
-
I'd say it's better to make assumptions that are based on facts rather than assumptions that are based solely on your experience /beliefs and then go on to make claims, just because you don't find a feature interesting or haven't used it yet doesn't mean it should be removed and it certainly doesn't mean you should imply certain things about the group of people that do find it useful and make good use of it. :) |
Beta Was this translation helpful? Give feedback.
-
Well, seems I'm clearly wrong on this one. Cheers for the input everyone :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
C# is a strongly typed language. Having
dynamic
really just serves to enable developers to be lazy.I can't think of any places where using
dynamic
is actually preferably to using a generic.I'm open to having my mind changed on that though if anyone has any convincing examples.
If there are none, why don't we deprecate it?
Beta Was this translation helpful? Give feedback.
All reactions