We are being forced to use Spartan programming on a project, to everybody's dismay. So I get it, it makes the methods really short and it handles the simple cases first. But is it really worth the price of the code looking like something out of the Obfuscated C Code contest?

Can you see it being useful for something?

  • 3
    What the heck is "spartan programming"? Can you provide a link for us ignorant folk?
    – DarenW
    Commented Dec 20, 2010 at 23:08
  • You're "forced to use Spartan programming on a project"?! How does that work? I mean, I can (to a point) imagine being forced to use (an editor/a VSC/...) on a project, but how can one be forced to use a certain approach?
    – Rook
    Commented Dec 20, 2010 at 23:11
  • 17
    This is Sparta! Commented Dec 20, 2010 at 23:15
  • 2
    If you end up with code that should be entered into an obfuscated contest, despite any euphemism, you're doing it wrong.
    – user131
    Commented Dec 20, 2010 at 23:23
  • 3
    @EpsilonVector: Ah, so this is a school project, not something in "the real world"? Then I would just suck it up and do the work. Perhaps the professor is trying to teach you that blind adherence to dogmatic rules is typically detrimental to your ability to work efficiently. Or maybe he's just sadistic... I know many professors who are ;-) Commented Dec 20, 2010 at 23:43

5 Answers 5


Many of the tenants of Spartan programming just seem like good practise to me. For example, keeping methods short, minimizing the scope of variables, minimizing the number of parameters to a method, or methods to a class, etc. These are all good things and exactly what you should be striving for.

But then there's stuff like minimizing character count, minimizing token counts, ternarization (seriously?), etc which really make no sense.

I think my main problem with it is exemplified by this quote:

But, spartan programming is more than just a technical coding style, in that is has a single underlying, unifying principle---minimalism and simplicity taken to extremes.

Anything "taken to extremes" rings alarm bells to me.

  • Anyone said "programming"? :p
    – CesarGon
    Commented Dec 20, 2010 at 23:41
  • ternarization is interesting, in the first case cited in the linked paper, it's a good idea, in the second... hmmm ok, I'd let that go, but to take ternarization to silly extremes (e.g. nested ternaries) is, well, silly.
    – ocodo
    Commented Dec 21, 2010 at 2:29
  • @Slomojo: The real WTF on that page is the sections on "Automatic ternarization"... Commented Dec 21, 2010 at 2:32
  • that regex is pretty awesome, as long as you review each ternarization I don't see a big problem with it. As long as they are still readable they're ok. - As you say, it's the extremes (or perhaps more correctly, extremists) that would be the problem.
    – ocodo
    Commented Dec 21, 2010 at 2:35
  • +1 for Anything "taken to extremes" rings alarm bells to me. Commented Jul 19, 2011 at 8:16

Now that looked disturbingly familiar. Even the minimizing on the tokens, although not taken to the extremes. I rather use fname than filename for example, out for output, x for the data input, n for counts, l for lengths and so on. lx would be length of x, ly length of y,... you get the drift.

Plus, as I often manipulate large datasets in scientific applications, I use the index facilities in R a lot. When I write out all those indices, the code hurts my eyes. So index becomes id, or even just i.

Even more, the specific loop structures in R (the apply family) often demands of function declaration within the apply call. In those cases I always use x,y,z,... These functions are often one or two lines, so it's clear where it's coming from, and it doesn't clutter the screen.

It's not a bad thing, as long as you have some naming conventions that are coherent through the complete code, and you supply comments to explain the more obscure variable names. In the end, it makes code more readible to me than a long train of camels hobbling over the screen.

  • 2
    I agree that shorter variables are often easier to read than extremely long variable names. As I said in my answer, 'Anything "taken to extremes" rings alarm bells to me' and that goes both ways. Your ultimate goal is to maximize readability, regardless of particular character counts. Commented Dec 21, 2010 at 0:00
  • 1
    You say "..it makes code more readible to me..."; I put the emphasis in "to me". When your code is used and maintained by other dozen people, then your variables and logic must make sense to them as well as you. In those cases, your conventions and abbreviations may not be so clear. :-)
    – CesarGon
    Commented Dec 21, 2010 at 0:33
  • @Cesargon: It's a matter of documenting the conventions.
    – Joris Meys
    Commented Dec 21, 2010 at 0:38
  • @Dean I agree completely on that. Yet, I notice a tendency to the other extreme, noteably in some specific programming languages. Jave comes to mind...
    – Joris Meys
    Commented Dec 21, 2010 at 0:39

Here's an article that discusses the benefits of spartan programming


  • 3
    It's a joke, right? Minimising variable name length, minimising number of variables... gosh, reminds me of my MSX days!
    – CesarGon
    Commented Dec 20, 2010 at 23:16
  • I'm not approving it :) but the article explains it better then I can. Commented Dec 20, 2010 at 23:17
  • I know, I know.
    – CesarGon
    Commented Dec 20, 2010 at 23:20
  • 1
    Shouldn't these things shown in the article belong to every refactoring action? I didn't know that this was called "Spartan Programming", but generally I try to care about these things while I write code (apart from the variable name length, but I haven't found that issue in the article anyway) Commented Dec 20, 2010 at 23:23
  • Yeah I'm familiar with that link, except that it used to not load when we tried to access it a while ago... OK so it's less insane than my team members made it sound, but I still side with CaesarGon on this one... Commented Dec 20, 2010 at 23:36

This is an accentuation Compactness of the Cs.

  1. Correctness
  2. Completeness
  3. Compactness

No one cares about your code if it isn't correct.

If your code isn't complete (handles every case), then there are bugs.

If it isn't compact than you are wasting memory or clock cycles ( compiler optimizations aside )

Note the order here is paramount. The most Compact program is rarely correct. E.G.

void main() {
 return 1; 
  • You can make that even more compact if you want to. void main(){return 1;} Commented Oct 29, 2018 at 5:36

Wow, I actually program like this, didn't know it had a name. I would say it benefits readability but more in a spatial way... meaning you don't get lost in a soup of code even if you have few lines that are kind of hard to read.

However, I'd say that when you get used to certain constructs you find your way easier in less time than at the very start.


Not the answer you're looking for? Browse other questions tagged or ask your own question.