Kovacs Baldvin wrote:
I think that best practices in coding method or function is to have
only one entry point (easy to do) and only one exit point at the end
of the method of function (avoid return in the middle of the code).
Sometimes this just makes the code a bit harder to make clear. Is not
making a lot of explicit tests on the arguments at the top of the
definition, and explicitly returning in cases of error, clearer than
setting an rv and later in the definition having to write around
argument errors that you've already noticed but didn't return simply due
to the above rule? Come on... horses for courses. Hard and fast rules
are for people that can't think for themselves. Soft and squidgy..
that's another matter.
Come on guys, his question was not about wether it is good or bad coding
practice to use several return statements.
To be fair :) I did ask if it was considered "bad form", but that's
purely subjective.
(I am actually with him on this issue. I think
var something = foo() || return E_FAIL;
is way more readable than the spaghetti with the tons of braces.)
I write, or have written, lots of Perl, and I think my style tends to
swing sometimes between overly verbose to very perlish. The construct is
very perlish, I think, and provides an easier read for the expected
execution of a piece of code. You *see* what should be happening, not
all the million possible options as to what could go wrong.
We could argue about it, but that doesn't lead anywhere. However,
the question he asked still interests me, and I don't know the answer:
Is the construct shown above correct, and officially supported in
javascript, or is it not?
Indeed. I'm tempted to look at the ECMA spec, though it always gives me
headaches and never guarantees that it's implemented.
_______________________________________________
Project_owners mailing list
[email protected]
http://mozdev.org/mailman/listinfo/project_owners