- Maximum line length: 120 code points
- Indentation: 2 spaces
- Assignment continuation: 8 spaces
positionForTheNextElection =
descriptivelyNamedDefaultPosition
- NAYSAYER_POSITIONAL_INFLUENCE * naysayerCount
+ YEASAYER_POSITIONAL_INFLUENCE * yeasayerCount;totalQuantity =
descriptivelyNamedTerm
+
SOME_RATE * whateverIsDimensionallyConsistent
+
(justDo - whateverGroupingOrIndentation / feelsLogical);Foo foo = fitsOnOneLine;final FunnyObject descriptivelyNamedInstance =
(FunnyObject) anotherDescriptivelyNamedInstanceThatNeedsCasting;final String corruptedText =
originalText
.makeImperfectCopy()
.makeImperfectCopy()
.makeImperfectCopy()
.makeImperfectCopy();final int dollarFigure =
(int) someMethodThatReturnsFloat(
verboseButDescriptiveMattress,
verboseButDescriptivePillow,
verboseButDescriptiveSheet
);public class SimpleFoo
{
// etc. etc.
}public class ComplicatedFoo
extends Bar
implements WiseClass.WiseInterface, FoolishClass.FoolishInterface
{
// etc. etc.
}/*
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)if (conditionIsShort())
{
// etc. etc.
}
else
{
// etc. etc.
}if (
someBoolean && someOtherBoolean
||
someInequality && anotherInequality && blahBlahBlah
)
{
// etc. etc.
}for (int index = 0; index < count; index++)
{
// etc. etc.
}for (
int index = verboseButDescriptiveInitialValue;
areYouSureYouAreSure(index);
cruelAndUnusualAndVerboseIncrement(index);
)
{
// etc. etc.
}public void doSomething()
{
// etc. etc.
}public boolean AreThereTooManyParameters(
final Body commonLaw,
final Contract misleadingOrDeceptiveAgreement,
final Party greedyDeveloper,
final Party peasant
)
{
// etc. etc.
}return OneLiner;return (
(isQualified || didDueDiligence && looksQualified)
&&
horriblyComplicatedBooleanThingy
&&
(thisLooksDodgy || shouldProbablyRefactorThis)
);return
someReallyLongMethodCall(whichFitsOnOneLine, ifNotOnTheSameLineAsReturn);return
someReallyReallyReallyLongMethodCall(
whichWillNotFitOnOneLine,
evenIfNotOnTheSameLineAsReturn,
becauseItIsReallyReallyReallyLong
);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;
}final Foo foo =
(isThisConditionalSatisfied)
? yesValue
: noValue;<!--
Multi-line comment.
Blah blah blah.
--><!-- One-liner -->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>