Skip to content

Latest commit

 

History

History
294 lines (240 loc) · 4 KB

STYLE.md

File metadata and controls

294 lines (240 loc) · 4 KB

Style guide

  • Maximum line length: 120 code points
  • Indentation: 2 spaces
  • Assignment continuation: 8 spaces

Java

Arithmetic

positionForTheNextElection =
        descriptivelyNamedDefaultPosition
          - NAYSAYER_POSITIONAL_INFLUENCE * naysayerCount
          + YEASAYER_POSITIONAL_INFLUENCE * yeasayerCount;
totalQuantity =
        descriptivelyNamedTerm
          +
        SOME_RATE * whateverIsDimensionallyConsistent
          +
        (justDo - whateverGroupingOrIndentation / feelsLogical);

Assignments

Foo foo = fitsOnOneLine;
final FunnyObject descriptivelyNamedInstance =
        (FunnyObject) anotherDescriptivelyNamedInstanceThatNeedsCasting;
final String corruptedText =
        originalText
          .makeImperfectCopy()
          .makeImperfectCopy()
          .makeImperfectCopy()
          .makeImperfectCopy();
final int dollarFigure =
        (int) someMethodThatReturnsFloat(
          verboseButDescriptiveMattress,
          verboseButDescriptivePillow,
          verboseButDescriptiveSheet
        );

Classes

public class SimpleFoo
{
  // etc. etc.
}
public class ComplicatedFoo
  extends Bar
  implements WiseClass.WiseInterface, FoolishClass.FoolishInterface
{
  // etc. etc.
}

Comments

/*
  Block comments.
  Or descriptions.
*/
// Heading for a bunch of logically grouped declarations
private Foo foo;
private Bar bar;
doSomeExtraCheck(); // short remark (e.g. bemoaning a deprecation)

Conditionals

if (conditionIsShort())
{
  // etc. etc.
}
else
{
  // etc. etc.
}
if (
  someBoolean && someOtherBoolean
    ||
  someInequality && anotherInequality && blahBlahBlah
)
{
  // etc. etc.
}

Loops

for (int index = 0; index < count; index++)
{
  // etc. etc.
}
for (
  int index = verboseButDescriptiveInitialValue;
  areYouSureYouAreSure(index);
  cruelAndUnusualAndVerboseIncrement(index);
)
{
  // etc. etc.
}

Methods

public void doSomething()
{
  // etc. etc.
}
public boolean AreThereTooManyParameters(
  final Body commonLaw,
  final Contract misleadingOrDeceptiveAgreement,
  final Party greedyDeveloper,
  final Party peasant
)
{
  // etc. etc.
}

Returns

return OneLiner;
return (
  (isQualified || didDueDiligence && looksQualified)
    &&
  horriblyComplicatedBooleanThingy
    &&
  (thisLooksDodgy || shouldProbablyRefactorThis)
);
return
  someReallyLongMethodCall(whichFitsOnOneLine, ifNotOnTheSameLineAsReturn);
return
  someReallyReallyReallyLongMethodCall(
    whichWillNotFitOnOneLine,
    evenIfNotOnTheSameLineAsReturn,
    becauseItIsReallyReallyReallyLong
  );

Switches

label:
switch (expression)
{
  case goodValue:
    doGood();
    break;

  case evilValue:
    doEvil();
    break;

  case neutralValue1:
  case neutralValue2:
    doNothing();
    break;

  default:
    throwHandsInTheAir();
}
moreComplicated:
switch (expression)
{
  case multipleBreaksInConditionals:

    leaveBlankLineAbove();
    if (conditional)
    {
      doSomething();
      break;
    }

    if (anotherConditional)
    {
      doAnotherThing();
      break;
    }

    doSomeOtherStuff();
    break;

  case singleBreak:
    takeSighOfRelief();
    break;
}

Ternaries

final Foo foo =
        (isThisConditionalSatisfied)
          ? yesValue
          : noValue;

XML

Comments

<!--
  Multi-line comment.
  Blah blah blah.
-->
<!-- One-liner -->

Elements

One-liners:

<Paired attribute="value">content</Paired>
<SelfClosing attribute="value" />

Multi-liners:

<Paired
  attribute1="value1"
  attribute2="value2"
  attribute3="value3"
>
  <SelfClosing1
    attribute1="value1"
    attribute2="value2"
    attribute3="value3"
  />
  <SelfClosing2
    attribute1="value1"
    attribute2="value2"
    attribute3="value3"
  />
</Paired>