DEV Community

Discussion on: Your most controversial opinion

Collapse
 
josegonz321 profile image
Jose Gonzalez

I work in an awesome place holding pretty high code quality standards, so very little comes to mind.

I have one tiny nit-pick: brackets for one-line if statement in C#

Example:

if (cookies.Any())
{
   Console.WriteLine("Awwwww yisss, cookiieeeessss!!");
}
else
{
   Console.WriteLine("Oh noes, need cookies!")
}

My personal preference

if (cookies.Any())
   Console.WriteLine("Awwwww yisss, cookiieeeessss!!");
else
   Console.WriteLine("Oh noes, need cookies!")

Less code to read, the better. { } add unnecessary noise.

Note: Standards can change and I have an opportunity to change the existing standard. But all propositions are taken to developer votes (you know, democracy style)

Collapse
 
jfrankcarr profile image
Frank Carr

I've been kind of back and forth on this.

From coding in C and C++ in the past, I like the security having the braces bring but I also like the brevity of not having to use them. I've kind of ended up in the use brackets camp because, in the long run, it makes the code easier to read for more people.

Collapse
 
josegonz321 profile image
Jose Gonzalez

Hmm, what type of security do they provide to you? I’m interested now :)

Thread Thread
 
elmuerte profile image
Michiel Hendriks

See Paritosh' comment in this thread.

In short:

if (someRatherLongBooleanCheck) 
   doSomething()
if (someOtherRatherLongBooleanCheck) 
   doSomethingElse()
   doNotLookAtMe()
if (imJustHereToDistractYou) 
   andWeAreDone()
Thread Thread
 
zenmumbler profile image
zenmumbler

Or for a concrete example, the "goto fail" bug from a couple of years ago:

imperialviolet.org/2014/02/22/appl...