Making if statement conditions into local variables? via /r/learnprogramming


Making if statement conditions into local variables?

I remember a while back I once read someone advise making a variable for any semi-complex if conditions, so that the condition would have a name and be more readable.

I can't seem to find the original source of this advice to look into it more. Are there any downsides to this? Is it something many programmers do? I can see the value in it, but I just wanted see some other opinions on it.

Example (excuse the crappiness of the example, i'm having a hard time thinking of one):

if(foo.isReady && !foo.isRunning) 

vs

canStart = foo.isReady && !foo.isRunning if(canStart) 

Submitted July 10, 2017 at 09:47PM by paleclaw
via reddit http://ift.tt/2tC3VJj

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s