Re: Procedure, function and return

new topic     » goto parent     » topic index » view thread      » older message » newer message

I usually think of it this way:

A procedure is handy when I find myself needing to do something more than once, and would rather not write out the same code multiple times (with the possibility for making multiple errors). A return is never required, and there are only a few instances where a return makes code simpler.

A function always requires a return (but you aren't obligated to use it). Is that "bad programming" ? Well, the alternative, if your program sometimes needs to use the return value, and sometimes doesn't need to use it, would be to clutter your code with dummy assignments:

object junk = myfunc(x) 

While that construct makes it plain to the reader that you are discarding the return value, it also looks like you didn't plan things out as thoroughly as a "good programmer" would have done.

Modifying global variables inside functions or procedures is great - by that, I mean a great way to introduce hard-to-find "bugs" that can occur randomly and unpredictably. It's also a great way to obfuscate your code, so that no one (including yourself) can easily figure out what is going on.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu