You may have noticed that when I close a block in my code, regardless of the language, I put a comment on the closing brace, like so:
function my_function ([some parameters]) {
...
}// my_function;
Why do I do this? It was a trick taught to me by my original mentor and, simply it shows what the closing brace closes. When I programmed in Pascal (yes, I am that old) I would do this:
function my_function ([some parameters]) begin
...
end {my_function};
Why do I do it? Quite simply, so I know what the closing brace (or “end” statement) closes. Why is this useful? I generally have a rule that no function should be larger than a screenful, but this isn’t always possible. Furthermore, when the implementation is contained within the overall class (as is the case with most modern languages) and several classes can be contained within a single namespace, the end may be several screens below the opening statement, so I would have a brace and have no idea what it closes. I would have to, either infer from the indenting, or scroll to the top.
It’s just easier and more convenient to add this tiny comment.
Leave a Reply