Live data from Hacker News

I thought I understood recursion

functional.christmas

71–80 of 124 posts

Re: I thought I understood recursion

#71

I was thinking about this recently: is there ever a reason to put recursion in an everyday “workman” code base? Seems like it would be so out of place in a real industry code base, like a infinite loop waiting to happen. There are always better more readable and maintainable ways to accomplish the same thing.

There are contexts where it's banned (MISRA, and other embedded scenarios). But it's very hard to work with tree structures without recursion - if you're not careful you just end up with an explicit stack rather than using the software stack.

In situations where you think auto-vectorisation might help, you definitely want to do it as iteration.

This is partly why I like the system of transformers that LINQ is built out of; you can specify your query in a natural nice functional manner, and then let the optimizer convert it into a fast query.

Re: I thought I understood recursion

#72
post #15

Earlier quoted context omitted.

So if you consider some stack to be inferior (maybe because its highly inconsistent in its design or it only runs on closed and locked down platforms or whatever) you still should just dismiss it as 'oh its just a tool' instead of accepting that it's shitty and makes you miserable when working with it? Why wouldn't I want to work with best thing ever if it helps me keep my sanity every day? Do you want to use somethi…

Maybe you should look within yourself and fix up whatever part of your personality is making you miserable? I'm not being flippant. Programming languages don't make people miserable. There isn't really an argument, just an observation that the most efficient way of thinking about programming is in data structures and algorithms which are mostly language independent. Nobody should be spending most of their time levera…

I agree with you that there is a deeper problem if choice of programming languages makes you miserable (with the possible exception of the situation where things are so bad that it makes it difficult for you to do your job and that makes you miserable).

At the same time though, I think you might be writing off the link between choice of programming language too easily. Rather than pens, where there is relatively little difference even between a fountain pen and a ballpoint, a better example might be a carpenter choosing between power tools and hand tools. There are definitely carpenters who are strongly specialized in using hand tools who would not enjoy being forced to use power tools.

I suspect this may boil down to different people coming to programming for different reasons. Some people are primarily interested in the end product of programming while others are interested in the process of using code to build abstractions. My opinion is that room should be made for each approach.

Re: I thought I understood recursion

#73

Earlier quoted context omitted.

>You just have to look harder to see where it's being used. This is where advocacy slips over the line into a kind of blind faith evangelism -- with an added pinch of pedantry peculiar to our field. I will state without proof that every language ever invented is currently being used for something practical somewhere. E.g. someone has a useful shell utility they wrote in Brainfuck that they run every day and that they…

I'm not sure that holds up. Real people working at real companies are writing real code in Haskell every day. I found several job postings in London that advertised Haskell as a requirement / nice to have. Haskell is also taught and used extensively at my alma matter, and is in fact the first language you will be introduced to at a CS/SE degree. How is that in any way, shape, or form comparable to Brainfuck?!

When was the last time you installed and/or ran a Haskell program? If the answer is more recent then "never", then what was it?

It's possible that Haskell is like COBOL in that it's used in industry but not at all by the community. But I'm not sure how I would characterize it, then. Does industry use count as "practical"? I honestly don't know. Anyway, examples would be nice.

Re: I thought I understood recursion

#74

I was thinking about this recently: is there ever a reason to put recursion in an everyday “workman” code base? Seems like it would be so out of place in a real industry code base, like a infinite loop waiting to happen. There are always better more readable and maintainable ways to accomplish the same thing.

Loops are also infinite loops waiting to happen, yet we still use them :)

The reason one might want to use recursion is when you're working on a data structure that is recursive in shape, like trees. And trees are very common, the Hacker News comments are one such example.

Re: I thought I understood recursion

#75
post #59
post #57

Earlier quoted context omitted.

I think it is more like growing a garden.

I prefer making the distributed club sandwich analogy ...

Never heard of that one, and if it works for you then more power to you! Analogy's are all about making sense of new data using older previously understood data, so if the old reference doesn't ring any bells... you just need to find one that does.

Re: I thought I understood recursion

#76
post #15

Earlier quoted context omitted.

So if you consider some stack to be inferior (maybe because its highly inconsistent in its design or it only runs on closed and locked down platforms or whatever) you still should just dismiss it as 'oh its just a tool' instead of accepting that it's shitty and makes you miserable when working with it? Why wouldn't I want to work with best thing ever if it helps me keep my sanity every day? Do you want to use somethi…

Maybe you should look within yourself and fix up whatever part of your personality is making you miserable? I'm not being flippant. Programming languages don't make people miserable. There isn't really an argument, just an observation that the most efficient way of thinking about programming is in data structures and algorithms which are mostly language independent. Nobody should be spending most of their time levera…

> Programming languages don't make people miserable.

Try coding in MUMPS then saying that again. Or Intercal. Or Whitespace.

Re: I thought I understood recursion

#77
post #13

I do not get what this publication is trying to say. Is Haskell better than C#? are Haskell programs shorter than C#? is recursion difficult? is recursion difficult in C#? I don't get it.

I can't tell if you're seriously enquiring, or simply being snarky. However, taking your comment at face value ...

To me this post is saying that in some languages (in this case Haskell) there are ways of working that are hard to emulate in other languages (in this case C#). The post is talking through a specific example of this, and pointing out that if you only know one language (in this case C#) then you might be missing out on styles of thought that can help in solving certain problems.

The post isn't about one language being better or worse in absolute terms, it's about broadening your range as a programmer so you are aware of other techniques and styles of thought.

To go all "new age-y" it's about enlightenment. Usually Lisp is the language used to help programmers achieve enlightenment, but other options exist, such as fexl, Haskell, and others.

Seriously, many languages are "about the same," but some really do make you think differently. You can be an excellent and productive programmer without them, and the vast majority of programmers never try to step outside the bubble of Imperative & OO languages, but you will be missing out if you don't at some stage embrace one of these other "pure(ish) functional" languages that is genuinely different.

YMMV

Some reading:

* https://www.defmacro.org/ramblings/lisp.html

* https://stackoverflow.com/questions/2036244/whats-so-great-a...

Search for "Lisp Enlightenment" and cull mercilessly.

Re: I thought I understood recursion

#78
post #36
post #7

> My background is in OO programming, mostly using C#. C# being the versatile language it is, I have had the perception that whatever you do in other programming languages, you can with a little more code and hassle achieve in C# as well. If need be, I can program C# using a functional paradigm. And, of course I use recursion all the time. I know all there is to know about recursion. IME there are two kinds of progra…

i don't blame them, i was like that a couple decades ago, too This seems like a fairly good indication there probably aren't really two kinds of programmers. Unless you experienced that particular change, from those particular initial conditions in some strikingly discrete fashion and also believe those are both universal.

I always figured there were two types of programmers

   one who understood recursion
   
     and there were two types of programmers
    
       one who did not understand recursion

Re: I thought I understood recursion

#80
post #57
post #38

Earlier quoted context omitted.

I take your point, but can we avoid this analogy please? Let’s talk about actual code if we’re going to talk about the best tool for a job that requires it. It reminds me of something early in my career that irked me like few work-related things things have: “Building software is like building a house” — No, it isn’t. Not even a little bit.

I think it is more like growing a garden.

Sometimes I feel like a gardener tending to the code base. Pruning deadcode and planting new modules...
Post reply on HN