4 ms·
In both the original example and this updated version, the nested loops (or foreach calls) create generators on each iteration. However, the first example is cr
by CorvusCrypto 8y ago
In both the original example and this updated version, the nested loops (or foreach calls) create generators on each iteration. However, the first example is creating the generator chain more implicitly than the newer example. Since the original example also uses a coalescing expression (i.e. I mean that he is returning a dynamically-created generator chain as a variable) it means the use of "return" keywords at every subcall to foreach which can confuse programmers that aren't as seasoned with generators or functional generator patterns. It's actually, I would argue, not "bad code" but rather a different approach that procedural programmers probably aren't used to. The benefit of this style of doing things is that it comes with the benefits that usually come with creating lambda expressions. There are better examples of creating on-the-fly generators, and surely thats what the original author wanted to showcase, but to programmers not well-accustomed to common range-based generator patterns, the Pythagorean triple example for this looks and feels a mess when it's clear you don't need to generate the generator dynamically. This updated example I think is more generally useful for showcasing the range iterators to programmers.
Also this is just my opinion. Of course it could be that the original example is hated by all and a total POS, but to me it seemed quite clear in a functional context what it was getting at and what it meant for use of dynamically-created generators in higher order functions.
- Koshkin 8y agoAgree. The "bad code" example looks beautiful to me, albeit unusual for someone who is accustomed mostly to the imperative style; I have no doubt that it would only take a small amount of (self-)training to absorb such style to the extent that it becomes easy to read.
- iseeyoubydesign 8y agoyou could have put "beautiful" in quotes as well. These type of discussions are too subjective to have meaning to engineers. Every project has its guidelines and standards. This is the same problem with python, the language is trying to dictate too much. If someone makes a bunch of oil paint pigments they are not supposed to dictate how the artist uses them. Let the engineers and individual projects figure out how best to use the tools of the language. Any attempt to create coding standards across the board is an attempt to control others creations. If its really good style you would not use the word "beautiful" you would use the word correct , no quotes. Engineers dont deal in vague ideas.