by nghst · 12y ago · 0 comments
// do blah blah
obvious_thing;
obvious_thing;
obvious_thing;
obvious_thing;
// do something else
obvious_thing;
obvious_thing;
obvious_thing;
obvious_thing;
Even though none of the lines really need documentation, having the comment ensures that you can quickly jump in when you come back later.This is really useful in something like drawing code.
function main()
do_blah_blah();
do_something_else();
end
function do_blah_blah()
obvious_thing;
obvious_thing;
obvious_thing;
obvious_thing;
end
etc.. //really bad example, just something really repetitive
function main()
// set up month boundaries
janStart = blah;
janEnd = blah;
// ...
decStart = blah;
decEnd = blah;
end
where it's not too hard to imagine many languages without great pointers needing to keep that inline to avoid making all of those variables global. In some (hopefully most) cases just better design in general can get around it, but I wouldn't always count it out immediately.edit: oops, formatting fail.
Descriptive function names never lie, comments often do.
Beg pardon[0]?
function _utf8Encode(&$arr){
for($i=0;$i<(count($arr['parameters']));$i++){
$arr['parameters'][$i]= $arr['parameters'][$i];
}
}
function _utf8Decode(&$arr){
for($i=0;$i<count($arr['parameters']);$i++){
$arr['parameters'][$i]= $arr['parameters'][$i];
}
}
Or[1] public static string ReturnEmptyStringIfNullElseValue(string value) {
if (value == null) {
return "";
} else {
return value.ToString().Trim();
}
}
[0] http://thedailywtf.com/Comments/There-and-Back-Again.aspx[1] http://thedailywtf.com/Articles/Common-Functions,-not-Common...
Description function names lie just as much as comments. For example, I have run into cases in the wild where things like "get_item()" create database entries before returning a value. Yes, side effects are evil, etc etc, but the point is that at some point, somebody maintained the code and did not update every use of get_item() to now be get_and_or_create_items_if_it_is_sunday(). In rare cases, I have seen them at least update the local documentation.