Followers 0

# Why do it the easy way?

## 12 posts in this topic

I'm so happy we can vote up in this forum=-)

1

##### Share on other sites

Very good ideas for reafctoring in this thread, keep em coming.

2

##### Share on other sites
if (isActive == TRUE) {
return 1;
}
else if (isActive == FALSE) {
return 0;
}

1

##### Share on other sites

How about something akin to what I find in some of my companies legacy code:

ASSERT(isActive); // We should never be inactive so lets just assert in debug, it'll be fine in release

return TRUE;


2

##### Share on other sites

Was gonna comment on the original topic, but what the— Abbreviations gone awry o_O And this is why you should avoid abbreviations except for a few well-estabilished ones...

As for the original topic, I find this a lot (and yes, with basic types, not classes which could have side-effects):

if (!blah)
blah = true;

This could have easily done the job:

blah = true;
1

##### Share on other sites

Was gonna comment on the original topic, but what the— Abbreviations gone awry o_O And this is why you should avoid abbreviations except for a few well-estabilished ones...

As for the original topic, I find this a lot (and yes, with basic types, not classes which could have side-effects):

if (!blah)
blah = true;

This could have easily done the job:

blah = true;

Unless it is dynamically typed language (like javascript):

var blah = "hello";
if (!blah)
blah = true;

// blah remains "hello"

blah = 15;
if (!blah)
blah = true;

// blah remains 15

blah = 0;
if (!blah)
blah = true;

// blah is true 

I hate dynamically typed languages for allowing this.

2

##### Share on other sites

The examples of that I see are usually in C or C++ though...

0

## Create an account

Register a new account