Most Used Coding Styles (Just a Few Basic Items)

Started by
22 comments, last by Rydinare 16 years, 1 month ago
Except for html, I try to indent using a tab set to 4 spaces. When I'm using html, I just use 2 spaces for each indent.
Advertisement
Ok, there's been enough interesting responses, I suppose I can post the results of where we are.

Currently, the tech lead of the project is mandating a style. Of particular note is that the style is preferred by the minority of people in the development group, including heavily contrasting with another project he's supposed to be cooperating with.

I liked the comment of using tabs for indenting and spaces for alignment. I do the same thing. Oddly, the tech lead prefers the opposite. He uses 2 spaces for indentation and an 8-space tab for alignment (Why would someone who preaches spaces use tabs for alignment anyway?). This causes some ugly/oddly spaced code. He argues that this is the most common style in the world (utter BS, right?)

We already agreed on consistency: existing modules use existing style; new modules use creator's preference. Now he's also mandating editor configuration. I tend to use 4 space tabs, as from what I can tell, it is the most common style. He's mandating 8 space tabs, which makes no sense.

Quote:Original post by Boder
His example shows a right-hand comment, for "alignment" so tabs would have to be used to guarantee alignment of the left edge

  func();     // comment after five spaces  if(1)  {    boot();   // comment after three spaces  }    // now tabs=4    func();     // comment after five spaces    if(1)    {        boot();   // comment after three spaces    }


Thinking more, using tabs would probably just make it worse [sick]


A better question is why are you lining up comments from different levels of indentations? Am the only one who doesn't think it makes any sense to do so?
This stuff is the basis for many holy wars. The only people who really gain from "Holy wars" are the gunsmiths.
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!
Quote:Original post by speciesUnknown
This stuff is the basis for many holy wars. The only people who really gain from "Holy wars" are the gunsmiths.


Absolutely. I'm merely trying to gain some perspective. The tech lead is an absolute micromanager (and he's not even my manager!). He has the classic "nothing is good enough" syndrome. This post was mostly for informative purposes (and slightly rantative).

If I had it my way, the ideal way would be that everyone uses whatever style they like as long as what was checked in is mostly consistent with the documented coding standards (there are none documented, in this case). Even if there were cases where there were slight inconsistencies, who cares? There's bigger fish to fry.

But some people just can't compromise.
Quote:Original post by Rydinare
I liked the comment of using tabs for indenting and spaces for alignment. I do the same thing. Oddly, the tech lead prefers the opposite. He uses 2 spaces for indentation and an 8-space tab for alignment (Why would someone who preaches spaces use tabs for alignment anyway?). This causes some ugly/oddly spaced code. He argues that this is the most common style in the world (utter BS, right?)


Utter BS, yes.
Okay, my new answer (my original one, before I did some serious overthinking) is

tabs,4,spaces
Quote:Original post by Boder
Okay, my new answer (my original one, before I did some serious overthinking) is

tabs,4,spaces


Can you elaborate?
I dunno. I just ask the IDE to indent things for me (emacs: M-x indent-region, VS: C-k C-f) and it uses whatever is necessary (although I suspect they all use spaces, with two-space for emacs and four-space for VS).
Quote:Original post by ToohrVyk
I dunno. I just ask the IDE to indent things for me (emacs: M-x indent-region, VS: C-k C-f) and it uses whatever is necessary (although I suspect they all use spaces, with two-space for emacs and four-space for VS).


Yes. Well, one thing is that there's at least four editors being used (vim, Emacs, Eclipse, Visual Studio). The fact that people are choosing to use vim and Emacs as their primary editor at this point almost seems ridiculous, though.
Quote:Original post by Rydinare
The fact that people are choosing to use vim and Emacs as their primary editor at this point almost seems ridiculous, though.


I use emacs because it's more flexible than the other editors:
  • It handles OCaml. This includes a decent toplevel interaction system which I've seen in no other IDE. It also provides correct syntax highlighting: C-based IDEs generally fail to recognize nested comments, type parameters ('a is not the beginning of a character literal) or even highlight types.
  • It handles LaTeX. It's auto-configured upon install, it's free, and it provides a reasonable amount of built-in WYSIWYG with minimal effort. Few editors I've seen handle LaTeX this well, and most that do are unusable for anything else and cost money.
  • It handles XML and HTML, and also performs automatic validation of code. While not as advanced as a dedicated HTML editor, it's enough for my needs and doesn't require me to have several editors running at the same time.
  • It handles C, C++, PHP, Java correctly without requiring anything more than apt-get install whatever-mode.
  • It handles script and makefile editing.
  • It's entirely keyboard-controlled by default and in a reasonably standard way across computers. This may sound useless, but it's actually great to be able to keep your hands on-keyboard at all times.


Until I can find a single editor that can handle all the above on my workstation, I will use emacs as my primary editor, and only resort to secondary editors (such as Visual Studio) when I have extremely specific work to do.

This topic is closed to new replies.

Advertisement