|go ahead... be a heretic|
Re^3: Write code diferentlyby BrowserUk (Pope)
|on Aug 23, 2013 at 20:56 UTC||Need Help??|
to tell the truth, the first map looks a bit clunky to me.
Truth is good; but "looks a bit clunky to me" doesn't cut much ice as a technical objection. It reflects only your own limited expectations.
The map function is really designed to return a list.
Repeating cargo cult does not make it so.
map maps a function over a list; optionally returning a new list. Used in a void context; it does not create an output list.
If you are using it only for its side effects on $_ and therefore on the original list, then I submit that for/foreach is a better choice.
In the abstract, that is sound reasoning; but it concentrates on the minutia rather than the bigger picture.
The purpose of that line of code is to apply a function: f(x) := x / (mutation rate * 100); in place, to every element of a matrix.
The original language, Darwin, has matrix operators that allow this to be written very naturally.
Perl does not have those operators; but does provide the tools to allow them to be written quite concisely. Thus allowing the purpose of the code; the mutation of the elements of the matrix to stand clear of the mechanics of the code required to iterate over the matrix dimensions.
I contend that this:
Distracts from the purpose of the code, by making too great an emphasis of the (purely mechanical) process of iterating the matrix.
Clearer and possibly faster.
Clearer is in the eye of the beholder -- and I disagree with your view.
Faster is a matter of benchmarking, but my guess is that there will be little in it; and it will probably favour the map version:
The perl code:
was written to mirror the original Darwin code:
as closely as possible; which I think it does admirably.
The reason for asking the OP why he wanted it coded a different way; was so as to get some idea of how best to address his concerns when doing so.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.