Click here to Skip to main content
15,893,668 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: when algorithms attack Pin
Sander Rossel16-Aug-19 5:37
professionalSander Rossel16-Aug-19 5:37 
GeneralRe: when algorithms attack Pin
Jon McKee16-Aug-19 9:27
professionalJon McKee16-Aug-19 9:27 
GeneralRe: when algorithms attack Pin
honey the codewitch16-Aug-19 9:32
mvahoney the codewitch16-Aug-19 9:32 
GeneralRe: when algorithms attack Pin
honey the codewitch16-Aug-19 9:34
mvahoney the codewitch16-Aug-19 9:34 
GeneralRe: when algorithms attack Pin
Sander Rossel16-Aug-19 9:52
professionalSander Rossel16-Aug-19 9:52 
GeneralRe: when algorithms attack Pin
Jon McKee16-Aug-19 10:29
professionalJon McKee16-Aug-19 10:29 
GeneralRe: when algorithms attack Pin
Sander Rossel16-Aug-19 10:52
professionalSander Rossel16-Aug-19 10:52 
GeneralRe: when algorithms attack Pin
Jon McKee17-Aug-19 10:19
professionalJon McKee17-Aug-19 10:19 
Sander Rossel wrote:
Only as you said, should do one thing vs. should do x things, but that's something that changes with specs, and both can be easily changed.
The difference is that when the specs are changed to "if x do y and now also z" the code with braces is almost certain to be changed correctly, but without braces that change is more likely to cause a bug.

If going from a single statement to a block of statements, extracting those statements into a function or expressing it as a block with {} should be done. But I do see where this argument has traction. I don't personally think it's compelling though.

Solution: comment out the if statement too.
C#
//if (x)
//   DoSomething(); Commented out for now.
AlwaysDoThis();
Braces have an issue here as well:
C#
if (x)
{
//   DoSomething(); Commented out for now.
}
AlwaysDoThis();
Now you've got an empty check just wasting time. And it does nothing so you'll only ever fix it if you manually stumble across it in the code-base. Both of these examples are mistakes of not commenting out the code only coupled to DoSomething().
C#
if (x)
{
   if (y)
      DoSomething();
   else
      DoSomethingElse();
}
I agree with you here. With nested elses it's much clearer to add braces. Also without the braces, as you alluded to, one has to know the else binds to its closest if - something a dev might reasonably not know.
GeneralRe: when algorithms attack Pin
Sander Rossel17-Aug-19 10:34
professionalSander Rossel17-Aug-19 10:34 
GeneralRe: when algorithms attack Pin
honey the codewitch16-Aug-19 10:30
mvahoney the codewitch16-Aug-19 10:30 
GeneralRe: when algorithms attack Pin
Sander Rossel16-Aug-19 10:59
professionalSander Rossel16-Aug-19 10:59 
GeneralRe: when algorithms attack Pin
honey the codewitch16-Aug-19 11:02
mvahoney the codewitch16-Aug-19 11:02 
GeneralRe: when algorithms attack Pin
Sander Rossel16-Aug-19 11:09
professionalSander Rossel16-Aug-19 11:09 
GeneralRe: when algorithms attack Pin
honey the codewitch16-Aug-19 11:16
mvahoney the codewitch16-Aug-19 11:16 
GeneralRe: when algorithms attack Pin
Sander Rossel17-Aug-19 1:35
professionalSander Rossel17-Aug-19 1:35 
GeneralRe: when algorithms attack Pin
honey the codewitch17-Aug-19 3:16
mvahoney the codewitch17-Aug-19 3:16 
GeneralRe: when algorithms attack Pin
Sander Rossel17-Aug-19 4:08
professionalSander Rossel17-Aug-19 4:08 
GeneralRe: when algorithms attack Pin
honey the codewitch17-Aug-19 4:14
mvahoney the codewitch17-Aug-19 4:14 
GeneralRe: when algorithms attack Pin
Sander Rossel17-Aug-19 4:27
professionalSander Rossel17-Aug-19 4:27 
GeneralRe: when algorithms attack Pin
honey the codewitch17-Aug-19 4:30
mvahoney the codewitch17-Aug-19 4:30 
GeneralRe: when algorithms attack Pin
Sander Rossel17-Aug-19 4:32
professionalSander Rossel17-Aug-19 4:32 
GeneralRe: when algorithms attack Pin
honey the codewitch17-Aug-19 4:41
mvahoney the codewitch17-Aug-19 4:41 
GeneralRe: when algorithms attack Pin
dandy7216-Aug-19 5:06
dandy7216-Aug-19 5:06 
GeneralRe: when algorithms attack Pin
honey the codewitch16-Aug-19 5:08
mvahoney the codewitch16-Aug-19 5:08 
GeneralRe: when algorithms attack Pin
dandy7216-Aug-19 5:11
dandy7216-Aug-19 5:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.