Skip to content

Coding Conventions

Markus Ackermann edited this page Mar 13, 2014 · 3 revisions

Allgemeines

  • Tabs bestehen aus 4 Leerzeichen
  • sprechende Bezeichner

Java

  • CamelCase für Typnamen ((innere) Klassen, Interfaces, enums,...)
  • lowerCamelCase für Member-Variablen, Methoden, lokale Variablen und lokal genutzte Konstanten
  • UNDERSCORED_CAPS für öffentliche Konstanten und enum-Elemente
public class CodingConventionsExample {
    
    public static final int CONTANT_AS_PART_OF_PUBLIC_INTERFACE = -1;
    
    public String publicField;
    private Optional<Double> privateField = Optional.absent(); //set default values at declaration if possible

    public CodingConventionsExample(String publicField) {
        
        this.publicField = publicField;
    }

    public String publicMethod() {
        
        return publicField.toUpperCase();
    }
    
    protected Double nonPublicMethod() {
        
        final double localAndInternalConstant = (double) CONTANT_AS_PART_OF_PUBLIC_INTERFACE; 
        return privateField.or(localAndInternalConstant);
    }
    
    public static class InnerClass {
        
        public List<Double> member = Lists.newArrayList();
    }
}

Ruby

  • Underscore-Schreibweise für Bezeichner

Javascript

  • CamelCase