Matt Gerrans
Posts: 1153
Nickname: matt
Registered: Feb, 2002
|
|
Re: Versioning, Virtual, and Override
|
Posted: Sep 17, 2003 10:55 AM
|
|
Having now done plenty of C++, Delphi, Java and C#, I'd say there is no particular advantage to the more explicit inheritance mark-up in C# to offset the annoyance of extra typing and spurious (unrelated to the task I'm really working on and trying to think about) decision-making. The problems it ostensibly solves don't seem to be big ones, they are corner-cases and the solution only shifts to different problems. Conversely, I never had much of a problem in other languages with accidentally overriding base methods -- is this really such a common problem that it needs to be so aggressively tackled? Anyone else out there have experiences where this was a huge problem? Would the C# syntax have solved it?
As far as versioning goes, I thought that the side-by-side execution of assemblies was intended to solve problems arising from interface (and implementation) changes. Amusingly, the experience I've had so far with this is that the bloated, but unfortunately commonly-used, MSI installer's most common behavior shoots this feature right in the head. Usually, when you upgrade a software package, it cleverly does an uninstall+install, effectively removing all the assemblies it uses from the Global Assembly Cache, then installing the new versions; if any other compoents depend on these assemblies and didn't update the reference count (a common mistake), they are completely hosed and will unceremoniously croak on starup -- not much better than "dll hell," if you ask me. In any cases, it seems like this particular explicit stamping of a method's vituality doesn't solve the problem by any means.
Anders was complaining that in Java, designers don't use the final keyword often enough. If this is a problem, then why does C# have any default at all? Why not force the designer to declare all methods virtual or final, then there is no need for the override and new silliness. (By the way, overloading the meaning of new in this way is probably especially confusing for new (!) programmers -- I was a little confused on the meaning of using when I first started in C#, because it is likewise overloaded and used in to completely different contexts).
The only real advantage I can see to this is performance, since methods are all final by default. This helps particularly well when touting C# performance over Java's by doing little comparisions between C# and Java code speed, because most observers will fail to notice that they are comparing a C# program running final methods with a Java program running virtual methods. However, I also think that people pay too much attention to the performance effects of virtual vs. final, which I think are small compared to bigger inefficiencies that are usually just bugs in design or coding of a particular subsystem.
|
|