-5

void Function( int, char )

versus:

void Function (int,char)

My friend keeps saying otherwise. What is objectively the best way to write brackets?

Ben
  • 2,141
  • 2
  • 22
  • 30
  • 2
    It is important for each project to stick to a consistent coding style. But it is quite irrelevant which one you pick, as long as you just stay consistent. Any minute arguing about the best coding style is a minute of your life wasted. – Philipp Mar 03 '14 at 14:07
  • Not only is this primarily opinion based, it's not game development specific. Please review the [help] before asking further questions. – House Mar 03 '14 at 14:49

2 Answers2

1

There is not a best way. There is just a preferred way, and that changes from person to person. There are many different semantics that various programmers with bicker on about style. I have personally seen the following 3 ways in commercial code:

void DoSomething(int,float,string);

void DoSomething(int, float, string);

void DoSomething( int, float , string );

Although I have a preference for one of these, I can't tell someone that my way is best. Therefore the best advice is to write what works best for you, or the chosen style for a given collaborated project.

  • Though I will say that if you write the first version, you will annoy many other programmers you work with. "Space-averse" programming results in dense, hard-to-read code. Also, can you fix that extra space after the third float? I can't edit it since it's a single-character edit. – Almo Mar 03 '14 at 14:05
  • 1
    Oh totally. But that hasn't stopped the horrible messes of projects with that style :p –  Mar 03 '14 at 14:06
  • Case in point: http://hg.icculus.org/icculus/lugaru/file/97b303e79826/Source/GameTick.cpp#l7276 – Maximus Minimus Mar 03 '14 at 14:28
  • There's some severe tabbing issues going on there. Someone needs to learn how to use functions =P –  Mar 03 '14 at 14:48
1

There is no best way, but there are some cases where one way is better than another.

  • If you're working as part of a team, that team will have it's own coding style, and you should conform to that.

  • If you've inherited a bunch of legacy code you may prefer to conform to the coding style already used by that legacy code.

  • If you're coding something on your own you can sometimes just use whichever style you find most readable.

  • If you're writing something where a pre-defined style already exists and is expected to be used (e.g a GNU utility) you'd better use that pre-defined style.

However, in a world where source code formatters exist and are common (and free) discussions or arguments over coding style seem silly.

Maximus Minimus
  • 20,144
  • 2
  • 38
  • 66