Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

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?

share|improve this question

closed as primarily opinion-based by MichaelT, gnat, Bart van Ingen Schenau, GlenH7, World Engineer Mar 31 '14 at 18:38

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

What the heck is "spartan programming"? Can you provide a link for us ignorant folk? – DarenW Dec 20 '10 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 Dec 20 '10 at 23:11
This is Sparta! – Dean Harding Dec 20 '10 at 23:15
If you end up with code that should be entered into an obfuscated contest, despite any euphemism, you're doing it wrong. – Tim Post Dec 20 '10 at 23:23
@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 ;-) – Dean Harding Dec 20 '10 at 23:43

5 Answers 5

up vote 23 down vote accepted

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.

share|improve this answer
Anyone said "programming"? :p – CesarGon Dec 20 '10 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. – Slomojo Dec 21 '10 at 2:29
@Slomojo: The real WTF on that page is the sections on "Automatic ternarization"... – Dean Harding Dec 21 '10 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. – Slomojo Dec 21 '10 at 2:35
+1 for Anything "taken to extremes" rings alarm bells to me. – Sarawut Positwinyu Jul 19 '11 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.

share|improve this answer
+1 for that first paragraph. – EpsilonVector Dec 20 '10 at 23:56
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. – Dean Harding Dec 21 '10 at 0:00
You say " 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 Dec 21 '10 at 0:33
@Cesargon: It's a matter of documenting the conventions. – Joris Meys Dec 21 '10 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 Dec 21 '10 at 0:39

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

share|improve this answer
It's a joke, right? Minimising variable name length, minimising number of variables... gosh, reminds me of my MSX days! – CesarGon Dec 20 '10 at 23:16
I'm not approving it :) but the article explains it better then I can. – Demian Kasier Dec 20 '10 at 23:17
I know, I know. – CesarGon Dec 20 '10 at 23:20
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) – Felix Dombek Dec 20 '10 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... – EpsilonVector Dec 20 '10 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; 
share|improve this answer

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.

share|improve this answer

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