digitalmars.D - Static Analysis at Mozilla, must_override
- bearophile (18/18) Jul 12 2010 A video, Large-Scale Static Analysis of C++ code at Mozilla, video, July...
- Andrei Alexandrescu (8/12) Jul 12 2010 I discussed this with Walter. The pattern is of pretty narrow
- Michel Fortin (20/41) Jul 12 2010 Not necessarily. The basic implementations of opCmp and opEqual in
A video, Large-Scale Static Analysis of C++ code at Mozilla, video, July 9th, 2010: http://vimeo.com/12614626 From the video I have seen that Mozilla developers have felt the need to add this new attribute in C++ (implemented in JavaScript through their hydra plug-ins and used with a define NS_MUST_OVERRIDE): http://mxr.mozilla.org/mozilla-central/source/xpcom/analysis/must-override.js I have not felt a need for it (do you see any need for it in your programs?), because I have not written one million lines long C++ programs, but if necessary I think it's not hard to add it to D as the attribute: must_override (Alternative name: to_override). It's similar to the keyword "abstract", it requires overloading in derived classes, but it allows the implementation of the method in the original class too (that's not abstract). class Foo { must_override int foo() { return 1; } } class Bar1 : Foo { int foo() { return 2; } // OK } class Bar2 : Foo { // error, missing foo() } If the creation of custom attributes in user code is allowed, then a (scoped) must_override can be defined and tried out. To implement custom attributes a good amount of static introspection is needed. Bye, bearophile
Jul 12 2010
On 07/12/2010 07:15 AM, bearophile wrote:A video, Large-Scale Static Analysis of C++ code at Mozilla, video, July 9th, 2010: http://vimeo.com/12614626 From the video I have seen that Mozilla developers have felt the need to add this new attribute in C++ (implemented in JavaScript through their hydra plug-ins and used with a define NS_MUST_OVERRIDE): http://mxr.mozilla.org/mozilla-central/source/xpcom/analysis/must-override.jsI discussed this with Walter. The pattern is of pretty narrow usefulness, but the scenarios are quite compelling: - cloning - opCmp - opEquals Such functions, if ever used, must be overridden transitively. Andrei
Jul 12 2010
On 2010-07-12 10:36:05 -0400, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> said:On 07/12/2010 07:15 AM, bearophile wrote:Not necessarily. The basic implementations of opCmp and opEqual in Object are quite good for a variety of cases (when comparing the reference pointer is good enough). You only need to override them when two different instances having the same value makes sense. As for cloning, if we had a little more runtime reflection it'd be easily doable like this: T clone(T)(T o) { ClassInfo ci = o.classinfo; if (ci.hasConstructorWithArguments!(ref const(T))) { return ci.construct(o); } throw new Exception("No copy constructor"); } Don't try to make that compile, it won't work. But it could be made to... -- Michel Fortin michel.fortin michelf.com http://michelf.com/A video, Large-Scale Static Analysis of C++ code at Mozilla, video, July 9th, 2010: http://vimeo.com/12614626 From the video I have seen that Mozilla developers have felt the need to add this new attribute in C++ (implemented in JavaScript through their hydra plug-ins and used with a define NS_MUST_OVERRIDE): http://mxr.mozilla.org/mozilla-central/source/xpcom/analysis/must-override.jsI discussed this with Walter. The pattern is of pretty narrow usefulness, but the scenarios are quite compelling: - cloning - opCmp - opEquals Such functions, if ever used, must be overridden transitively.
Jul 12 2010