6 ms·
C loops are natural and easy to understand for programmers who were trained on loops. I doubt that tail recursion is any harder to get for students who don't ha
by svachalek 2y ago
C loops are natural and easy to understand for programmers who were trained on loops. I doubt that tail recursion is any harder to get for students who don't have that background. Would be an interesting experiment though.
- tedunangst 2y agoThis is what happens when we eliminate shop class. Sand this table leg. Good. Now do that three more times. Kids used to know loops before they ever touched a computer.
- klyrs 2y agoExactly. Go make a table with 4 legs and also every leg has 4 legs. Now you get recursion and a very steady table. You were a kid in shop class. Now you want your kids to take shop class. Because, recursion.
- adwn 2y ago> Go make a table with 4 legs and also every leg has 4 legs. If you have to make up nonsensical examples to prove your point, then you probably don't have a point. > You were a kid in shop class. Now you want your kids to take shop class. Because, recursion. That's not recursion.
- svachalek 2y agoC doesn't have a "do this 3 times" loop though. It has an "initialize counter to 0 first, increment counter after each operation, and compare the counter to 3 (or is it 4?)" loop. Kids definitely don't get this without being taught.
- salawat 2y ago//Precon: Need 4 legs. Have none. Int counter_of_sanded_legs = 0; do{ Sand_a_leg; Counter_of_sanded_legs++; } While (counter_of_sanded_legs < 4); Need four legs, have none. Doing while I don't have enough. How many legs do I have? 1. Doing. How many legs do I have? 2. Doing. How many legs do I have? 3. Doing. How many legs do I have? 4. Done. Alternatively: for (int i=0;i<4;i++;) { //how we start; whether we repeat; how we update our counter. Sand_leg(); } You only need to sand a leg when you don't have enough legs. These aren't that far off of actual things you'd do moving about. In fact, not realizing that you're distilling something physical into the symbolic is a leading cause of confusion in my experience. A "do x times" dedicated looping construct would be syntactic sugar that detracts from understanding what the underlying semantics are; which if you're teaching how to program is a bad idea. The idea is to have your understanding precede the machine. Not lag behind. You can start screwing around with abstractions after you get the basics. As once you have the basics, you can compose them into any form you want. The rest is just increasing levels of crippling mental illness.
- paulddraper 2y agoRecursion is more beautiful. But take a newbie, and "do this 3 times" in a loop is far more clear than the recursive equivalent.
- pineapple_sauce 2y agoHow do you measure beauty? You can't: "beauty" is subjective. And even if you try e.g. count the times you use recursion vs. iteration: that metric is subjective and not grounded in reality. Sometimes recursion does allow you to reason about code more easily or come to a working solution faster, sometimes it does not. Measure the concrete: CPU time and memory consumed. Iteration will likely trump recursive methods w.r.t both these metrics. If it doesn't, you can likely transform your iterative algorithm to one that utilizes SIMD (not always).
- mbivert 2y ago> How do you measure beauty? You can't: "beauty" is subjective Let me try: in classical dance, martial arts, or even skateboarding, advanced skills manifest as effortlessness: the movements comes naturally, they're not forced, things just flow. If you compare a typical functional (recursive + pattern matching, but the point would stand even with a fold) factorial with an imperative one (for loop), the functional approach is more effortless, you have to be less explicit about what's going on. It's more eloquent. However as you seem to imply, when we're programming, the focus should be on delivering something that works as expected; this particular kind of aesthetic is secondary at best.
- o11c 2y agoOften I get the impression that beauty is defined as "how far is this from what the computer can actually do efficiently?"
- paulddraper 2y ago> How do you measure beauty? Using the beholder's eye, of course.
- vsuperpower2020 2y ago
- mbivert 2y agoIteration is more natural for most people than recursion. There are a few aliens for whom recursion is more natural, but iteration matches more closely daily life.
- Gibbon1 2y agoPeople that see programming as math get really excited about recursion. Everyone else doesn't care, shouldn't care.
- timeinput 2y agoThere's this summation notation that these people who see programming as math and get excited about recursion forget about too.
- mbivert 2y agoI think recursion is just another tool in the toolbox: sometimes, some solutions are easier to think of recursively, and so it makes sense to use it, at least for the first prototype. But yeah, using it systematically (in a non-functional language) is unwise.
- burnished 2y agoHey, other kinds of needs can do and should care. Recursion is a very interesting perspective to apply to a problem and gratifying in its own right.
- zelphirkalt 2y agoRecursion is a form of iteration.
- mbivert 2y agoWorse: both are theoretically equivalent. But this doesn't change the fact that humans seem to intuitively perceive iteration as more natural. Like, "space" and "time" can't be understood as two distinct notions, per relativity. But we still perceive them as such on a daily basis.
- eigenket 2y agoI think its fairly clear that loops are more natural and obvious for most people for most tasks. There are examples of other communities which have invented something pretty much the same as loop syntax, for example you get things which are basically loops in knitting patterns or (less reguarly) in recipes. I have never seen an example of recursion outside computer science/programming.
- playingalong 2y agoRinse and repeat.
- KineticLensman 2y ago> for example you get things which are basically loops in knitting patterns Also in crochet. A pattern will have instructions like * (2tr, 3ch, 2tr) all in next 2ch sp; repeat from * 6 times more where statements like 2tr mean 2 treble stitches and the bit between the * symbols is repeated 6 times
- warkdarrior 2y agoYou guys should write these crochet patterns in continuation passing style!