Tagged Questions
93
votes
22answers
6k views
Elegant ways to handle if(if else) else
This is a minor niggle, but every time I have to code something like this, the repetition bothers me, but I'm not sure that any of the solutions aren't worse.
if(FileExists(file))
{
contents = ...
26
votes
3answers
3k views
if ('constant' == $variable) vs. if ($variable == 'constant')
Lately, I've been working a lot in PHP and specifically within the WordPress framework. I'm noticing a lot of code in the form of:
if ( 1 == $options['postlink'] )
Where I would have expected to ...
14
votes
6answers
966 views
Most readable way to format long if conditions? [closed]
Long winding if conditions should be avoided if at all possible, yet sometimes we all end up writing them. Even if it's a very simple condition, the involved statements are sometimes simply very ...
8
votes
4answers
913 views
Is the use of explicit ' == true' comparison always bad? [duplicate]
Possible Duplicate:
Make a big deal out of == true?
I've been looking at a lot of code samples recently, and I keep noticing the use of...
if( expression == true )
// do something...
...
4
votes
6answers
2k views
Clarification of “avoid if-else” advice [duplicate]
The experts in clean code advise not to use if/else since it's creating an unreadable code. They suggest rather using IF and not to wait till the end of a method without real need.
Now, this if/else ...
0
votes
1answer
92 views
Which is preferred coding style to validate and return from a method [duplicate]
Which of the below is a preferred coding style (in c# .net)
public void DoWork(Employee employee)
{
if(employee == null)
return;
if(!string.IsNullOrEmpty(employee.Name))
return;
// Do ...
0
votes
0answers
47 views
Boolean condition before variable [duplicate]
I have noticed this style from time to time:
if ( 0 == myVar )
Rather than:
if ( myVar == 0 )
Is this just the individual programmers idiom? A defensive programming style? Does anyone know if it ...