[webkit-dev] 'final' class specifier and 'final' method specifier
Fujii Hironori
fujii.hironori at gmail.com
Wed Dec 19 01:52:16 PST 2018
Hi WebKit devs,
'final' keyword can be applied to both a class and a method
(non-static member function). I don't know correct terminology for
them. I call them 'final' class specifier and 'final' method
specifier.
I'm now going to update WebKit Code Style Guidelines for using 'final'
class specifier for all classes which has no derived classes in Bug
192844.
https://bugs.webkit.org/show_bug.cgi?id=192844
I believe this is not controversial. This is not a topic I'd like to
discuss today.
I'd like to discuss which 'override' or 'final' should be used for methods.
Currently, WebKit is using both inconsistently.
For example, CSSFontFaceSet class is marked 'final' and its methods are
marked 'final',
while CSSFontFaceSource class is marked 'final' and its methods are marked
'override'.
https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/css/CSSFontFaceSet.h?rev=239365#L93
https://trac.webkit.org/browser/webkit/trunk/Source/WebCore/css/CSSFontFaceSource.h?rev=239365#L83
According to WebKit Code Style Guidelines, 'final' method specifier is
preferable to 'override' if possible. There is a previous discussion
thread.
https://webkit.org/code-style-guidelines/#override-methods
https://lists.webkit.org/pipermail/webkit-dev/2016-March/028022.html
I'd like to change this because 'final' doesn't necessarily imply
'override'. See the following stackoverflow:
https://stackoverflow.com/questions/29412412/does-final-imply-override
IIUC, 'final' method specifier can be useful for such like the following
case:
class B {
public:
virtual foo();
virtual bar();
};
class B1 : public B {
foo() final;
};
class D final : B1 {
bar() override;
};
The 'final' method specifier indicates D can't override the method foo.
Thus, using 'final' method specifier implies other virtual functions
can be overridden. I'm not sure my understanding right. Please correct me.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20181219/48c7bcc9/attachment.html>
More information about the webkit-dev
mailing list