Rules for Spartan Programmers

A month ago, Jeff Atwood (Coding Horror) wrote a blog post about Spartan
The idea is to tend toward minimalism coding style: Minimalism
isn’t always the right choice, but it’s rarely the wrong choice


I figured out that many of Spartan Programming tenets can be expressed as


Horizontal complexity. The depth of nesting of control structures.



Vertical complexity. The number of lines or length of code (all routines, and and preferably larger software units such as classes fit within a single screen).



Parameters. The number of parameters to a routine or a generic structure.

WARN IF Count > 0 IN SELECT METHODS WHERE NbParameters > 4





Conditionals. The number of if and multiple branch switch statements.

WARN IF Count > 0 IN SELECT METHODS WHERE CyclomaticComplexity > 7



Minimize visibility of
identifiers (what I call Optimal Encapsulation).


This applies also to types and fields and to any non-public visibility
level, for example.

WARN IF Count > 0 IN SELECT TYPES WHERE CouldBeInternal 



Minimize variability of
variables. Strive to make fields read-only, methods pure and types
immutable (see also Immutable types: understand their benefits and use them).

Immutables fields that could be declared with the readonly keyword. 

IsImmutable AND !IsInitOnly 


Immutable types that could be tagged with a ImmutableAttribute.

!HasAttribute "OPTIONAL:NDepend.CQL.ImmutableAttribute"


Pure methods that could be tagged with a PureAttribute. 

!HasAttribute "OPTIONAL:NDepend.CQL.PureAttribute" AND 
!ChangesObjectState AND !ChangesTypeState AND
NbLinesOfCode > 0



Use annotations or restrictions whenever possible: Types that could be declared as sealed (see also Rambling on the
sealed keyword

IsClass AND NbChildren == 0 AND !IsSealed
This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Jon Rowett

    this is a bit like the list of “dos and don’ts for wives” in Marge Simpson’s housekeeping magzine – they’re all “don’ts”.

  • Damon Wilder Carr

    Fantastic content… Thanks!