Views

Code Style

Introduction

"Every second spent enforcing code style is a waste of time". -- Someone, at some point

Status: FALSE

When I encounter really pretty code in the open-source world (and the closed-source world for that matter), I'm a lot more confident that the software has real quality. Of course, from case to case, this may actually not be true, and the style might lie to me, but the important thing is that it appears to have high quality to people. On the other hand, if I encounter code which appears to be shit (although it might really be of excellent quality), it's tempting for me to try and find some alternative. So while enforcing code style might technically be a waste of time, it's psychologically. Also, if you ever intend to use LÖVE as a reference when applying for a job (I've done that), there is a slight chance they will take a ten second look on the code. Even if they are advanced enough to evaluate the code properly, they will not be immune to good (nor bad) style.

Therefore, because I'm such a fucking drone, I'm going to refactor some code here and there (or everywhere) to make things more beautiful. And since I'm potentially fucking up everything anyway, I thought we could decide on a coding style that the majority likes. It's unlikely that we all agree on everything ... but hopefully everyone will accept the decision of the majority.

Spaces vs Tabs

I personally prefer tabs, but I know I'm the only person in the world. We will probably end up with spaces, in which case I suggest 4 spaces per level.

EDIT: I was wrong, everyone (who has so far given a damn) has preferred tabs. In that case, let me specify a more advanced indentation guideline for the truly l33t, hardcore, and handsome.

MIXED TABS AND SPACES (*monocle pops*)

Use tabs for normal indentation.

I.e. when indicating scope.

YES:

if(foo){<tab>bar();}

NO:

if(foo){<space><space><space><space>bar();}

Use spaces for alignment.

If you really want to align stuff, then the important thing to keep in mind is that the alignment should not break if the viewer is using a tab-size that's different from yours. So, in this example, we're aligning stuff:

However, use alignment sparingly, because it makes a lot of diff noise when you add something that's longer than the currently longest thing, and you have to realign everything. So the best option is actually:

Trailing whitespace

Trim all trailing whitespace.

Tabs and spaces before a newline character increase the noise in commits and the source code.

If you agree to this, and you also agree that we're using tabs. You're agreeing that tabs and spaces be mixed (although in a very defined way). For a function declaration that's indented one block, you would type something like: