RFR: 8265473: Move os::Linux to its own header file [v4]

Thomas Stuefe stuefe at openjdk.org
Mon Jul 11 06:53:28 UTC 2022


On Mon, 11 Jul 2022 06:27:57 GMT, David Holmes <dholmes at openjdk.org> wrote:

> 



> @iklam I thought we very recently rejected use of namespaces due to the visibility issue?
> 
> Call me old fashioned by I much prefer classes for defining interfaces.

We really should rethink this rule. I find it baffling that we include a many modern C++ features (e.g. template metaprogramming, which is often a mixed blessing) but still are avoiding simple namespace.

Had a read over the hotspot style guide. It cites advantages of AllStatic vs namespace:


1 Provides access control for members, which is unavailable with
namespaces.

2 Avoids [Argument Dependent Lookup][ADL] (ADL).

3 Closed for additional members.  Namespaces allow names to be added in
multiple contexts, making it harder to see the complete API.


I cannot comment off-hand about the ADL issue (2), but the other two points are actually advantages of namespaces, not disadvantages. At least when it comes to things like "os":

- I don't _want_ access control for members in a public interface. A public interface should be clean and minimal. Allowing private members in an interface tempts devs into adding private implementation details, which have no place in a public header. That leads to a lot of unnecessary include dependencies. Using namespace OTOH would be inducive to clean interface design.

- (3) is actually the biggest advantage. I can extend the os namespace without having to change the central header. Which, as I have argued before, leads to a much cleaner include file structure.

-------------

PR: https://git.openjdk.org/jdk/pull/9423


More information about the hotspot-dev mailing list