News for hackers. Stuff that matters.
Re:Misconceptions about loops in C by paulddraper on Thursday June 27, 2024 @03:19PM (#40814035)
Recursion is more beautiful.

But take a newbie, and "do this 3 times" in a loop is far more clear than the recursive equivalent.

Re:Misconceptions about loops in C by pineapple_sauce on Thursday June 27, 2024 @03:27PM (#40814110)
How 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).

Re:Misconceptions about loops in C by mbivert on Thursday June 27, 2024 @06:08PM (#40815709)
> 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.

Re:Misconceptions about loops in C by o11c on Thursday June 27, 2024 @07:05PM (#40816132)
Often I get the impression that beauty is defined as "how far is this from what the computer can actually do efficiently?"
Re:Misconceptions about loops in C by paulddraper on Thursday June 27, 2024 @08:09PM (#40816535)
> How do you measure beauty?

Using the beholder's eye, of course.

Re:Misconceptions about loops in C by vsuperpower2020 on Thursday June 27, 2024 @08:26PM (#40816639)
I never understood anyone who used such strong language like "beauty" when talking about something mundane like recursion. I suspect it's just in-group language like how a cult understands the meaning of their own words, while to outsiders it would appear nonsensical. I have seen other groups appropriate the word "beauty" too, like people who chronically overeat.
Re:Misconceptions about loops in C by burnished on Thursday June 27, 2024 @11:31PM (#40817438)
Nope, it just has its own beauty. The material blew me away in school.

What culty group even exists around recursion anyway? Can you get me an invitation?

Re:Misconceptions about loops in C by paulddraper on Thursday June 27, 2024 @09:04PM (#40816848)
https://en.wikipedia.org/wiki/Mathematical_beauty

Simplicity is actually a hallmark of this sense of beauty.

Re:Misconceptions about loops in C by burnished on Thursday June 27, 2024 @11:33PM (#40817451)
This is a painfully stemlord response. 'Aesthetic qualities cannot be objectively measured therefor they do not exist'. Christ. Its fine to pick a metric to evaluate one thing against another, its another to deny that there are other ways to value things.
Re:Misconceptions about loops in C by xigoi on Friday June 28, 2024 @03:56AM (#40818622)
Too bad C doesn’t have a “do this 3 times” loop.