1

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?

gruner
  • 1,572
  • 2
  • 15
  • 26

3 Answers3

4

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

Community
  • 1
  • 1
eKek0
  • 23,005
  • 25
  • 91
  • 119
0

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
  • 25,014
  • 6
  • 48
  • 78
-1

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
  • 384,516
  • 81
  • 508
  • 779