Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a styleguide #27

Open
devromik opened this issue Aug 18, 2022 · 0 comments
Open

Add a styleguide #27

devromik opened this issue Aug 18, 2022 · 0 comments
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@devromik
Copy link
Collaborator

devromik commented Aug 18, 2022

We should create an automatic formatter for IDEA.
The list of rules:

  1. There should be an empty line after a class header:
public abstract class A {
    
      public final MetricName name;
      ...
}

There should be no empty lines if the definition of the class consists only of constants.

public abstract class A {
      public static final MetricName DEFAULT_NAME_PREFIX = MetricName.of("Buffers");
}
  1. We use only 4-space indentation for all the cases.
  2. We use the following formatting schema for long enough parameter lists (2+ usually but it depends):
protected Supplier<LongVarConfigBuilder> longVarConfigBuilderSupplier(
        String description, 
        MetricDimension... dimensions) {

        ...
}

or

protected Supplier<LongVarConfigBuilder> longVarConfigBuilderSupplier(
        String description, MetricDimension... dimensions) {

        ...
}

We add an empty line after a multi-line definition. For example,

registry.longVar(
    nameWithSuffix("startTime"),
    runtimeMxBean::getStartTime,
    longVarConfigBuilderSupplier("The start time of the Java virtual machine in milliseconds"));

registry.longVar(
     nameWithSuffix("uptime", "ms"),
     runtimeMxBean::getUptime,
     longVarConfigBuilderSupplier("The uptime of the Java virtual machine in milliseconds"));
  1. We don't use the prefix 'is' for fields or parameters, only for methods: isDimensional.
  2. We don't add an empty line after a method signature:
public void produceMetrics(MetricRegistry registry) {
   // no empty line here
    for (int i = 0; i < ATTRS.length; ++i) { 
  1. We don't use a space for type casting: (double)i
  2. There should be an empty line before and after if/try inside a method body (but not for the last statement).
  3. There should be no empty before closing brace in a class definition.
@devromik devromik added the documentation Improvements or additions to documentation label Aug 18, 2022
@devromik devromik added this to the 3.0 milestone Aug 18, 2022
@devromik devromik self-assigned this Aug 18, 2022
@devromik devromik changed the title Add a code style guide Add a styleguide Aug 18, 2022
@devromik devromik removed their assignment Sep 5, 2022
@devromik devromik modified the milestones: 3.0, 3.1 Sep 14, 2022
@devromik devromik modified the milestones: 3.1, 4.0 May 13, 2023
@devromik devromik modified the milestones: 4.0, 5.0 Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant