Default Tab Size and Indentation

262 views
Skip to first unread message

Jan Kassens

unread,
Nov 12, 2009, 7:07:29 PM11/12/09
to golang-nuts
I’m cool with adopting to a global enforced standard. In fact I love a unified coding style without any “manual styling” of code.

Just the tab size seems way to high to me. I know, that one can argue about tab sizes. Personally, I prefer 4 and the online code examples for instance use that width.

I’d suggest tabs for indenting and spaces to align stuff. This has the advantage, that every developer can set the preferred tab size in his editor and adjust the indentation with that setting without distorting the alignment. This would reduce one flag of gofmt and result in even more unified code style.

gri

unread,
Nov 12, 2009, 9:23:13 PM11/12/09
to golang-nuts
[apologies if you get this twice - we had some mail forwarding issues
here]

Unfortunately this won't work: if you use spaces for the alignment of
columns but tabs for indentation, the alignment will be off once you
change the tabwidth. If you want alignment, it's either spaces
everywhere, tabs everywhere (and the matching tabwidth setting in your
editor), or tabs for indentation and spaces afterwards, but no
alignment in this last case.

But in the meantime you can trivially reformat all source to your
preference in your clone:

gofmt -tabwidth=4 -w $GOROOT

to get to your setting, and

gofmt -w $GOROOT to get back.

- gri
Reply all
Reply to author
Forward
0 new messages