3

I genuinely want tp know why few devs don't add the opening brace on the same line as method/class declaration ??

Whenever I find a piece of code which follow such style a part of me cries thinking of the time I'll be spending first correcting...

Comments
  • 2
    I'm not sure if I understand what you mean by "few" in this case. Do you mean that there are too few devs who don't add the opening brace on the same line as the declaration, i.e. you're in favour of
    "
    foo
    {
    "
    ...or the opposite, that you wonder why there are some devs that do this, i.e. you're in favour of
    "
    foo{
    "
    ?
  • 6
    Personally I'm in favour of
    "
    foo
    {
    "
    because the opening and closing braces are aligned on the same indentation level, making the code easier to overview and debug. IMHO.
  • 2
    @TerriToniAX, I'm in the favor of the second style. BTW, you're the first one to give some sensible reason other than "I've been doing this from day 1"
  • 1
    @mayank9856 Cheers :)
  • 1
    Having the same indentation is why I did it originally, now it's a habit - I do get younger devs pointing out the editor highlighting support regularly though!
  • 3
    This is a very classic question that comes up every now and then, like variableName vs variable_name. It actually matters very little (at least to me), but is the subject of debates that take an undeserved amount of time and energy from devs.

    "Correcting" insignificant coding flavour like this seems like a waste of time though. Considering what a "huge" problem this is to many devs, perhaps the makers of IDEs such as Visual Studio etc., should actually address it by making it an option and format the code automatically for each user.
  • 1
    @TerriToniAX, for me I'll refactor it if I have to work on it for two or more days, it's worth effort for me as it doesn't distract me from actual logic throughout. Plus there for sure are plugins that do it for you.
  • 1
    Being distracted by unimportant things like this is common among devs. To you, linebreak before brace is a problem, to me autocomplete of closing tags/braces is disturbing like hell, and autocorrect while typing makes it compelety impossible to type anything! And to some third dev, it's something else that distracts or annoys the crap out of them. I think that this high sensitiveness among devs is evidence that most of us have some sort of mental disorder, although most haven't been diagnosed. Perhaps the instance one becomes a developer, one should automatically be diagnosed with something like "Hypersensitive Developer Disorder" ;) And those of us who immediately start thinking of hard drives, "Compulsory Acronymizing Disorder".
  • 1
    @mayank9856 I wouldn't call it refactoring if only removing/adding white space. Dunno the exact definition though so you may present another view if you like, but to me refactoring is when, for example, replacing a bunch of if...else if...else if... with a switch statement, or breaking up a lengthy function into multiple smaller functions (or vice versa).
  • 1
    @TerriToniAX, yeah my bad. The end result of refactoring should be to improve the nonfunctional aspects which in this case doesn't happen.
  • 2
    I simply follow language conventions 'cause of consistency, but I prefer opening on the same line.
  • 0
    The argument about having the same indentation is simply wrong. In the same-line style you have the same indentation for the definition (e.g. "for") and the closing brace, which is just as easier to review.
  • 1
    I just follow jetbrains code format. And frankly, my dear, I don't give a damn. (But i do about tabs)
    (I will push you down the stairs..)
  • 1
    @pagongski Yeah, thanks for reminding me about another thing. Correct indentation is absolutely mandatory to me too, even more important than the things I already mentioned. When I see something like this,
    if(<some expression>)
    {
    <some tabs>}
    I can go MAD I tell you *pounding the palm of my had against my forehead* :D
Add Comment