views:

44

answers:

3

Where can I learn more about simple programming conventions and design patterns?

When I say simple I mean which is the preferred way of writing the following equivalent functions:

function() {
  if (condition) {
    # condition wraps the entire function
  }
}

or

function() {
  if (!condition) {
    return;
  }

  # rest of the function
}

There's also this:

function() {
  $return_val = 'foo';

  if (condition) {
    $return_val = 'bar';
  }

  return $return_val;
}

vs this:

function() {
  if (condition) {
    return 'bar';
  }

  return 'foo';
}

Are these arbitrary differences or is are there established idioms for such things?

+4  A: 

Code complete. Also read this list of books What is the single most influential book every programmer should read?

eKek0
A: 

Are these arbitrary differences

Yes.

are there established idioms for such things?

No.

Go to a design review. Listen to the arguments over this kind of thing.

S.Lott
A: 

At most places there will either be explicit ie written down and expected or implicit ie copied so often you think it is a standard standards. Over time most people develop there own preferred style that is a mixture of there personality and experience.

rerun