eclipse / omr

Eclipse OMR™ Cross platform components for building reliable, high performance language runtimes
http://www.eclipse.org/omr
Other
933 stars 392 forks source link

Revisit coding standards #7371

Open ThanHenderson opened 2 weeks ago

ThanHenderson commented 2 weeks ago

Given the updated supported-feature list for C++11 (https://github.com/eclipse/omr/pull/7369) (edit: still updating), we should revisit the coding standards (https://github.com/eclipse/omr/blob/master/doc/CodingStandard.md) and add in guidelines and standards for newer features e.g. nullptr and lambdas.

While there, it may be beneficial to audit the existing standard -- it hasn't been meaningfully revisited in 8 years (for better or worse) -- and see how these newer features could change the current guidelines.

Moreover, the standard for return states that multiple return points should be avoided. Despite the standard attempting to back this statement up with [multiple return points] can make the flow of code more difficult to understand, I'd argue the opposite; avoiding multiple return points often leads to unnecessary complexity in control flow and, in the presence of goto, complexity in variable declarations and brittleness that is counter to modern C++.

In particular, procedures that require manual cleanup are often riddled with goto done and deep nesting. With the support of lambdas, an alternative approach could be to define lambdas with cleanup code and have early returns accompanied by calls to the cleanup lambda, leading to flatter, more understandable procedures.

dsouzai commented 2 weeks ago

@0xdaryl maybe this could be discussed in the next architecture meeting?