Skip to content

Instantly share code, notes, and snippets.

View arcanis's full-sized avatar
:octocat:

Maël Nison arcanis

:octocat:
View GitHub Profile

The Indentation Nightmare

If there is something that I have never fully understood during the last years of learning programming languages, it's the chaos around indentation. Some says that you should use spaces, some others says that you should use tabs. And even if you're willing to use spaces, there will be multiple schools, some people saying that you should use two spaces, instead of four for some other developers.

Why is it such a mess ? I don't even see why it is such a debatable topic : indentation is made by tabs. Alignment is made by spaces. Nothing more, nothing less. Want to know why ?

Spaces have a fixed length

Spaces are usefull because they have a fixed length. It means that it should be used when you have to align code. What's aligning ? Take this piece of code :

<?php
class StringRandomizer {
public function process( $text ) {
return preg_replace_callback('/\{(((?>[^\{\}]+)|(?R))*)\}/x', array( $this, 'replace' ), $text );
}
public function replace( $text ) {
$text = $this->process( $text[ 1 ] );
#!/usr/bin/env sh
# Usage :
# $> sudo set-python-version 2; python -V
# Python 2.7.2
# $> sudo set-python-version 3; python -V
# Python 3.2.2
python=$(which python)
pythonX=$(which python$1)
@arcanis
arcanis / gist:2724085
Created May 18, 2012 08:59
Classes en javascript
// Chaque fonction est un constructeur
var Foo = function ( ) { this.bar = 'hello world'; };
var instance = new Foo( );
console.log( instance.bar ); // "hello world"
// Chaque fonction possède un prototype
var Foo = function ( ) { };
Foo.prototype.bar = 'hello world';
var instance = new Foo( );
console.log( instance.bar ); // "hello world"
/**
* @mixin foo
*/
var foo = {
/**
* Does something.
*/
/**
* @class
*/
var foo = function () {
/**
* Stop, hammertime.
*
* @memberOf foo#
/**
* @class foo
*/
var foo = function () {
/**
* Stop, hammertime.
* @member foo
* @returns 42
This file has been truncated, but you can view the full file.
[[[0.03100680559873581,0.03100680559873581,0.02847377024590969,0.028717918321490288,0.028717918321490288,0.03024384379386902,0.026612140238285065,0.03265480697154999,0.03265480697154999,0.020966216921806335,0.021820735186338425,0.006317331455647945,0.006317331455647945,-0.056581318378448486,-0.06955168396234512,-0.061342205852270126,-0.061342205852270126,-0.06695760786533356,-0.0632648691534996,-0.06482131779193878,-0.06482131779193878,-0.06433302164077759,-0.0640278309583664,-0.0636310949921608,-0.0636310949921608,-0.07016205042600632,-0.07663197815418243,-0.07492294162511826,-0.07492294162511826,-0.07525864243507385,-0.07513657212257385,-0.07480086386203766,-0.07480086386203766,-0.07473982870578766,-0.07477034628391266,-0.07412946224212646,-0.07412946224212646,-0.07473982870578766,-0.07379375398159027,-0.07379375398159027,-0.07422101497650146,-0.08294931054115295,-0.08606220036745071,-0.08606220036745071,-0.08520767837762833,-0.08474989980459213,-0.08560442179441452,-0.08560442179441452,-0.08319345861673355
@arcanis
arcanis / pre-commit.sh
Last active August 29, 2015 14:06
Linting Moumoute
#!/usr/bin/env bash
result=0
cd "$(git rev-parse --show-toplevel)"
# Stash the current changes, so that we preserve them
git stash -q --keep-index
# Get the list of changed files from the index