Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

enter a newline character, tab-in the same number of tabs as the previous line, then add spaces to align.

That method is broken unless we also agree on a tab width, in which case we may as well use spaces anyway.



I suggest you try it. Here is an example file [1]. Try adjusting the tab size: you'll find the arguments are always aligned. I like to set vim's listchars with the UTF-8 light shade and medium shade blocks to make tabs visible. Here are screenshots with ts=4 [2] and with ts=16 [3].

[1] http://sprunge.us/AOGg

[2] http://i5.minus.com/iu14dVi9QRTri.png [3] http://i4.minus.com/itno9LlgJobQD.png


I see the confusion. For aligning function call arguments your strategy works fine. Here are a couple use cases that don't work out so well with tabs (taken from the Jalopy manual [0] to make finding examples easy):

function declaration (most people would accidentally use too many tabs here):

    public void severalParameters(String one, int two, String three,
                                  StringObject four, AnotherObject five) {
        ...
    }
assignments:

    String        text  = "text";
    int           a     = -1;
    History.Entry entry = new History.Entry(text);
Ultimately the problem with mixing spaces and tabs in one document is that programmers are human. Someone will inevitably make a change to the lines you've carefully indented and mess up the whitespace, and someone else will have to go back to fix it in a dummy commit. Having a simple rule that's easy to follow eliminates that source of wasted effort.

[0]: http://jalopy.sourceforge.net/existing/manual.html


The strategy works perfectly fine for those examples.

    	public void severalParameters(String one, int two, String three,
    	                              StringObject four, AnotherObject five) {
    		// No problems here. It's just like my example.
    		// We're two levels of indentation in for these comments.
    		// The argument list continuation was at 1-level indentation with spaces for alignment
    	}
For these assignments, anything to the left is a semantic indentation (tabs), the rest is all alignment (spaces).

    	String        text  = "text";
    	int           a     = -1;
    	History.Entry entry = new History.Entry(text);


Sure, you can make it work. By point is just that you're introducing a burden making people remember which whitespace to use in which context. At that point you're forcing your devs to show non-printable characters in their editor to get it right. You devs are now spending their time checking whitespace instead of writing code, which is lost productivity.

As with any coding standard, the point of the rule is to eliminate such sources of lost productivity.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: