WebKit Bugzilla
Attachment 358061 Details for
Bug 192844
: Update code style guidelines for using 'final' specifier for all classes which has no derived classes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-192844-20181225190124.patch (text/plain), 6.98 KB, created by
Fujii Hironori
on 2018-12-25 02:01:25 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Fujii Hironori
Created:
2018-12-25 02:01:25 PST
Size:
6.98 KB
patch
obsolete
>Subversion Revision: 239551 >diff --git a/Websites/webkit.org/ChangeLog b/Websites/webkit.org/ChangeLog >index 6302f1f547cd01db8e43de9c6a2931ef0961c10a..443b023fd26e691b6fc93a6504b24cf4658bacb9 100644 >--- a/Websites/webkit.org/ChangeLog >+++ b/Websites/webkit.org/ChangeLog >@@ -1,3 +1,16 @@ >+2018-12-25 Fujii Hironori <Hironori.Fujii@sony.com> >+ >+ Update code style guidelines for using 'final' specifier for all classes which has no derived classes >+ https://bugs.webkit.org/show_bug.cgi?id=192844 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * code-style.md: Added #classes-final to use 'final' specifier for >+ all classes which have no derived classes. Revised >+ #override-methods to use 'override' specifer only for classes >+ without 'final' specifer. Added 'final' specifer to classes in >+ other examples. >+ > 2018-12-20 Jon Davis <jond@apple.com> > > Ensure new styles are served on webkit.org. >diff --git a/Websites/webkit.org/code-style.md b/Websites/webkit.org/code-style.md >index 0b71e8d6666d4cea08ac951983b6c01a8543e5b0..b8951aa4d39b180724298f9b221c2e53f7791c2b 100644 >--- a/Websites/webkit.org/code-style.md >+++ b/Websites/webkit.org/code-style.md >@@ -388,7 +388,7 @@ int main() { > ###### Right: > > ```cpp >-class MyClass { >+class MyClass final { > ... > }; > >@@ -404,7 +404,7 @@ for (int i = 0; i < 10; ++i) { > ###### Wrong: > > ```cpp >-class MyClass >+class MyClass final > { > ... > }; >@@ -576,7 +576,7 @@ short tabulationIndex; // bizarre > ###### Right: > > ```cpp >-class String { >+class String final { > public: > ... > >@@ -588,7 +588,7 @@ private: > ###### Wrong: > > ```cpp >-class String { >+class String final { > public: > ... > >@@ -1173,17 +1173,19 @@ signed int c; // Doesn't omit "signed". > > ### Classes > >+[](#classes-final) Use final specifier for all classes which have no derived classes. >+ > [](#classes-explicit) Use a constructor to do an implicit conversion when the argument is reasonably thought of as a type conversion and the type conversion is fast. Otherwise, use the explicit keyword or a function returning the type. This only applies to single argument constructors. > > ###### Right: > > ```cpp >-class LargeInt { >+class LargeInt final { > public: > LargeInt(int); > ... > >-class Vector { >+class Vector final { > public: > explicit Vector(int size); // Not a type conversion. > Vector create(Array); // Costly conversion. >@@ -1194,7 +1196,7 @@ public: > ###### Wrong: > > ```cpp >-class Task { >+class Task final { > public: > Task(ScriptExecutionContext&); // Not a type conversion. > explicit Task(); // No arguments. >@@ -1209,7 +1211,7 @@ public: > ###### Right: > > ```cpp >-class MySingleton { >+class MySingleton final { > public: > static MySingleton& singleton(); > ... >@@ -1218,7 +1220,7 @@ public: > ###### Wrong: > > ```cpp >-class MySingleton { >+class MySingleton final { > public: > static MySingleton& shared(); > ... >@@ -1227,7 +1229,7 @@ public: > ###### Wrong: > > ```cpp >-class MySingleton { >+class MySingleton final { > ... > }; > >@@ -1273,23 +1275,33 @@ drawJpg(); // TODO: Make this code handle jpg in addition to the png support. > > ### Overriding Virtual Methods > >-[](#override-methods) The base level declaration of a virtual method inside a class must be declared with the `virtual` keyword. All subclasses of that class must either specify the `override` keyword when overriding the virtual method or the `final` keyword when overriding the virtual method and requiring that no further subclasses can override it. You never want to annotate a method with more than one of the `virtual`, `override`, or `final` keywords. >+[](#override-methods) The base level declaration of a virtual method inside a class must be declared with the `virtual` keyword. All subclasses of that class must either specify the `override` keyword when overriding the virtual method and further subclasses can override it or the `final` keyword when overriding the virtual method and requiring that no further subclasses can override it. You never want to annotate a method with more than one of the `virtual`, `override`, or `final` keywords. > > ###### Right: > > ```cpp > class Person { > public: >+ virtual String name() { ... }; >+ virtual unsigned age() { ... }; > virtual String description() { ... }; > } > > class Student : public Person { > public: >- String description() override { ... }; // This is correct because it only contains the "override" keyword to indicate that the method is overridden. >+ String name() override { ... }; // This is correct because it only contains the "override" keyword to indicate that the method is overridden and further subclasses can override. >+ String description() final { ... }; // This is correct because it only contains the "final" keyword to indicate that the method is overridden and no further subclasses can override. >+} >+ >+class HighSchoolStudent final : public Student { >+public: >+ unsigned age() final { ... }; // This is correct because it only contains the "final" keyword to indicate that the method is overridden. > } > > ``` > >+###### Wrong: >+ > ```cpp > class Person { > public: >@@ -1298,13 +1310,10 @@ public: > > class Student : public Person { > public: >- String description() final { ... }; // This is correct because it only contains the "final" keyword to indicate that the method is overridden and that no subclasses of "Student" can override "description". >+ virtual String description() override { ... }; // This is incorrect because it uses both the "virtual" and "override" keywords to indicate that the method is overridden. Instead, it should only use the "override" keyword. > } >- > ``` > >-###### Wrong: >- > ```cpp > class Person { > public: >@@ -1313,7 +1322,7 @@ public: > > class Student : public Person { > public: >- virtual String description() override { ... }; // This is incorrect because it uses both the "virtual" and "override" keywords to indicate that the method is overridden. Instead, it should only use the "override" keyword. >+ virtual String description() final { ... }; // This is incorrect because it uses both the "virtual" and "final" keywords to indicate that the method is overridden and final. Instead, it should only use the "final" keyword. > } > ``` > >@@ -1325,7 +1334,7 @@ public: > > class Student : public Person { > public: >- virtual String description() final { ... }; // This is incorrect because it uses both the "virtual" and "final" keywords to indicate that the method is overridden and final. Instead, it should only use the "final" keyword. >+ virtual String description() { ... }; // This is incorrect because it uses the "virtual" keyword to indicate that the method is overridden. > } > ``` > >@@ -1335,9 +1344,9 @@ public: > virtual String description() { ... }; > } > >-class Student : public Person { >+class Student final : public Person { > public: >- virtual String description() { ... }; // This is incorrect because it uses the "virtual" keyword to indicate that the method is overridden. >+ String description() override { ... }; // This is incorrect because it uses the "override" keyword in a final class. > } > ``` >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 192844
: 358061