Spartan Programming

to Yossi Gil:
Or do you say it may lead to wrong results on some machines?

Yes, for example the -0 could be printed as -0, which could baffle some souls.

tirat is right, it should really be:

return (x = 0) ? x : -x;

Take a look at http://en.wikipedia.org/wiki/%E2%88%920_(number)

Is it that it is spartan, or that one is taking the time to think it through and design it better. A bit of a mini code re-factoring if you will.

ss

Agree! There is no point to stuff in fat code for a lean task. If this is done so, then who else would want to jump in your code and learn from it? It might actually be better to rewrite everything if isn’t so minimalist.

Paul: You probably know that the term Laconic is after Laconia, the name of the piece of land were Sparta is located. In choosing the term Spartan, I was referring to this meaning as well: Spartans did not talk much. But, also to aspect of their lives and training.

Graham: Thanks for the -0 reference. Not sure how relevant this is e.g., what should be the absolute value of -0? And, in working with Java, this should not be a concern.

All: I fixed the link to terse naming. And, the entry is too short… Still, my argument for one (or two) letter names is ONLY in the case that the variables are general instances of their respective types.
So, in

sendMail(…, String subject, String[] attachements) {
}

the names subject and attachements should not be abbreviated.

but in

traverseNode(Node n) {
}

the parameter name n is OK

Interestingly, the web link to the wiki page on Spartan Programming specifically states that early returns are to be encouraged, as to reduce control code.

I know this isn’t /., but c’mon, RTFA:
http://ssdl-wiki.cs.technion.ac.il/wiki/index.php/Spartan_programming

This discussion highlighted the fact that the term terse names may be confusing to some, and people may think that spartan calls for obfuscating the code with short and cryptic names.

To clarify: names consisting of a couple of letters are to be used for GENERIC variables only. You write Message m = new Message(…) to denote that you are authoring a generic message. If the context is not sufficiently small so that m is clear to readers, then you probably should rewrite it to make it sufficiently small.

You write Message response = new Message(…) when you wish to compose a specific message, serving as a response.

I cannot stand maintaining code with no descriptive variables. Java programmers are absolutely notorious for this idiotic behavior. It seems, particularly with the use of client side scripting visible to users who View Source that programmers intentionally make their code difficult to read and follow so that others cannot easily decipher what is being done.

And I also agree with those questioning the removal of whitespace. Whitespace is my friend. I refuse to write code that does not have whitespace for readability. If I am maintaining code, I always add the whitespace.

The maxim KISS should apply only to the complexity of what you are doing, not in the readability of the code. Descriptive variable names and readability whitespace should NEVER be altered and in most cased, should be added to existing cluttered crap. Keep It Simple, Stupid applies to using the least amount of variables and the lowest scope possible and the fasted method’s for getting a given task accomplished. Spartan Programming does not mean make the damn code difficult to maintain or read.

I agreed with the Java email example, until the end, when he used $ as a variable name without explanation. That’s just not right.

@Adam - I don’t really know what side you’re arguing for, or what your argument is for that matter.

I also practice some of the principles of the spartan programming, but I don’t know how good it is on those projects which won’t have a 2.0 version, because thinking about how to write shorter and more elegant code slows you down.

Probably the most pointless thing I have ever read. As a software contractor of 6 years, and 16 years development experience, if I ever worked with someone who says they use Spartan programming, I would move to have them fired. You are gaining nothing by improving code in this way, in these days of advanced IDEs with code templates and intelligent code completion. The emphasis should be more on readable, maintainable code. I read an article not long ago about lazy programming which made far more sense.

In case anyone is interested, I worked out another case of code simplification using spartan programming.

http://ssdl-wiki.cs.technion.ac.il/wiki/index.php/GnuParser_flatten_case_study

I like it. I’m a spartan programmer too.

From code bloat to Spartan Programming - Too much or too little, either is bad. Besides, the Spartans fought naked, covered in olive oil and not at all like that silly movie; olive oil is bad for my keyboard and mouse but the naked part is OK. :slight_smile:

What should drive code is architecture. Unfortunately, in today’s slap-dash coding practices, the programmers usually back-engineer the code so that they can explain what they did to future programmers. No one wants to THINK any more - so they just start slinging code and hope that something good comes of it. Spidey Man isn’t the only web slinger in the world.

SDG
jco

For Sparta!

@uv - You’re apparently a student, so I’ll try to be nice.

  1. Single letter variable names went out with Fortran.
  2. While shortening variable names to 1 letter may in fact be a litmus test of complexity, it doesn’t mean that leaving them in a short form is desirable nor good practice.

if you have many long- and descriptively-named variables (which are a mental-load
Which part is the mental load? Long names or to many vars?

Your ‘spartan’ rule for using a single letter variable is so seldomly applicable in real life that’s it’s a useless rule, and given it’s frequency of occurrence, you’re better off sticking to longer variable names to decrease cognitive dissonance.

It is also true that variable names that are too long and wordy, or if there are too many variables in a method (regardless of their length) are also a bad smell, and refactoring should be considered. That statement is nothing groundbreaking. Most of us already know that.

‘Spartan’ may be a cute name, but it’s not a style, nor a methodology. It’s collecting a few accepted refactoring patterns with a few pet rules for non-oo php programming.


[rant…]
I’ve noticed that Coding Horror more and more targets an uninformed audience when it comes to coding. Discussion tend to revolve around fixing other posters braindead notions, and certainly not anything like a rational discourse. Seriously - f’ing single letter variables. I feel like I’ve been trolled. I feel dirty. Talking about this makes me feel dumb.

Spartan is a Coding Horror. Coding Horror is a horror :frowning:

Lift your head out of the muck and read some real books on programming. Talk about something cool like Linq, lambda’s and closures. I don’t care about xml config files or single letter variable names. That crap is just housework. Are you sweeping the floor, or are you building a skyscraper?

later

If you like the principles of Spartan Programming, we’ve developed in the Technion an Eclipse plug-in that automatically applies them to your Java source code. The plug-in is completely free and open source: https://www.spartan.org.il