3 ms·
From DougWebb, explaining why this would be a good thing to do. >> These expressions are the same; they're not meant to strictly indicate order of execution, t
by grayclhn 11y ago
From DougWebb, explaining why this would be a good thing to do.
>> These expressions are the same; they're not meant to strictly indicate order of execution, they're meant to express programmer intent.
We can achieve perfect precision and clarity by naming all of our variables x1, x2, x3, x4, etc. But it's better to give descriptive variable names because it helps us and anyone else reading the code understand what it does. This sort of expression is similar.
- chrisseaton 11y agoI can't see any argument in there. 'meant to express programmer intent'? What does that mean? Basing programming languages on mathematical notation or something else would also of course be 'meant to express programmer intent'. Why are natural languages a better foundation for programming languages than, for example, maths notation or calculi? Everyone in the Perl community seems to think they just intuitively know it is, but can't explain why.
- DougWebb 11y agoWhen you're speaking to another programmer, explaining what a bit of your code is trying to do, do you speak in mathematical notation? I doubt it. I don't think even mathematicians do that. If you want a well-expressed explaination for why Perl's approach is a good idea, you should read what Larry Wall has written about it. All I can really say is that it worked really well for me and my team for many years. We rarely misunderstood each other's intent, even though our code reviews were mostly just reading commit diffs.
- grayclhn 11y agoThink of it as a commenting or documentation system that's also interpreted by the language. Comments that can never get out of date. If you think that human-readable comments and documentation are not useful... then I'm not going to try to convince you that you would benefit from perl's syntactic flexibility. But surely you recognize that there are some people that like documentation, useful comments, and informative variable names.
- iopq 11y agoEveryone already knows what `if x then y` means, why is there a need for `y if x`? They're both as clear
- raiph 11y agoIf all someone wants to express to a reader is literally `if x then y` then `y if x` doesn't really help. But we typically don't write utterly trivial one-liners with single letter names for conditions and actions. In actual programming there are times when it's more like a series of lines, each of which is something akin to `if some-expression-that's-so-much-longer-than-a-single-letter-that-you-start-to-consider-factoring-it-out-in-to-another-variable-or-function then some-function-or-flow-control`. And when that happens there are times where by far the most important thing a writer wants to first bring to the attention of a reader (eg themselves, later) is some-function-or-flow-control. Sticking with made-up examples for a moment, there's: if long-complex-conditional----that-you-might-start-to-read-thru-in-an-attempt-to-understand-the-code-you're-reading---is-true then blow-rocket-up vs blow-rocket-up if long-complex-conditional----that-you-don't-need-to-read-and-understand-to-understand-that-the-rocket-will-blow-up-if-it's-true----is-true Or it takes me I estimate less than a second to know the gist of the overall control flow of this fragment from a recent Advent of Code entry[1]: next unless (() = /[aeiou]/g) >= 3; next unless /(.)\1/; next if /ab|cd|pq|xy/; $count++; I can immediately see that it increments `$count` unless it bails out of the containing loop (`next`s) due to any of several (complicated looking) conditions. In contrast, it might well take me more than a second to figure that out if they'd written: unless (() = /[aeiou]/g) >= 3 { next } ; unless /(.)\1/ { next }; if /ab|cd|pq|xy/ { next}; $count++; While these examples are pretty weak, I have hope that they might at least give you pause for thought. If you don't see anything going on here worth even thinking about, or more importantly seriously reflecting on, well, at least I tried. And if you're a trained linguist and/or able to quote science to refute what other scientists are finding in recent studies[2], please quote away. :) [1] https://www.reddit.com/r/adventofcode/comments/3viazx/day_5_solutions/cxnt51w https://www.reddit.com/r/adventofcode/comments/3viazx/day_5_... [2] http://www.infosun.fim.uni-passau.de/cl/publications/docs/SKA+14.pdf http://www.infosun.fim.uni-passau.de/cl/publications/docs/SK...
- gluggymug 11y ago