Hi Jared,
Hi Rich!
If you do put a return; at the end of all of your functions, I'm curious as to why? If a function doesn't actually return a value (which is highly possible) then it isn't /required/, but that doesn't stop me from doing it. I *do* put 'return;' at the end of all functions (my question to the list was - does anyone else?)
I went through a phase where I *did* make a point to put returns on all functions and class methods. This helped for a little while, as it caused me to slow down a little and think about my code (why is why I think it could be a healthy practice, especially for someone who is less experienced). Now, I don't worry at all about it all (meaningless returns, that is). The way I do things supercedes in a lot of cases worrying about returning values, and since I have many more experiences, I don't worry about it. When putting together some code, having meaningless "return;"s inserted at the end of every code block seems more wasteful than helpful in most cases, so I don't by practice append returns when unnecessary, although at times I have done it. It really doesn't matter in PHP (AFAIK), it all has to do with coding patterns and practice, and what and how that is impacted by appending returns. Is it helpful to always stop and think about a return value? Sure! If you've been coding for five years and you are now equipped with advanced methods and factoring iterations that render it moot? Personal preference and dogma I assume will rule the day here.
That is all my original thread was ever really asking - I was just curious what other people thought about returning from functions that don't actually require a return value. So far the responses have been pretty varied, from the (somewhat blinkered) 'how can a function never return something?', to 'yes I always return' to 'no I just let it run out'.
Maybe someone can shed light on what happens when the parser encounters a "return;". Would there be anything useful to that (I don't think so, but I don't know).
Based on the variety of replies it appears there is no 'standard' for this. Just as with code structure and studly-caps it's obviously a bit of a religious debate.
If bumpy/camel case zealots are the bedouins of programming, what are people who insist on returns? Returnaholics?
I think perhaps it is a psychological thing actually, as if I don't consider the function 'finished' until it hits a return;. Almost like you're issuing an instruction to tell PHP "yes, as the programmer I am now happy for you to return to where-ever you were called from" - perhaps just a way of exerting our control :)
It can also be used to visually parse a page of code ("returns at this tab spacing means end of code block..."). So it can make the code modestly easier to read, maybe. And no, I don't think programmers are ever control freaks. Ever. No, I said EVER. You're wrong.
> Should those checks be contained in the codeblock or class BEFORE
returning?
> I think so. I would agree (because it's how I do it ;), but this isn't an approach everyone takes.
There are times when "return;" is meaningful, such as breaking out of loops (and the function), switch statements, and whatnot. For all other times when a return isn't expressly meaningful, I see it as a matter personal preference, which is usually influenced by someone else's overarching dogmatic philosophy being impressed on them. Good thing there aren't folks like that in programming! Right?!? -- Jared Farrish Intermediate Web Developer Denton, Tx Abraham Maslow: "If the only tool you have is a hammer, you tend to see every problem as a nail." $$