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 questionWhere 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.
精彩评论