开发者

Learning simple programming conventions [closed]

开发者 https://www.devze.com 2023-01-21 05:24 出处:网络
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing
Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 4 years ago.

Improve this question

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 开发者_C百科differences or is are there established idioms for such things?


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消