> i like recursive functions

they are worst thing about programming

Attached: 1539722155636.jpg (720x546, 38K)

t. 1st year CS student

lol. learn how to code first in whatever language you're starting out with (most likely Python).

>the worst thing about programming
You don't believe that come on.

I try to avoid primitive recursion, but I pretty much use recursion exclusively via foldl and friends

As I have always said, recursion is black magic and should be banned.

I believe it. Back in school I knew people who had been programming for 2-4 months who really did have this opinion.

i think an iterative function definition is preferable to a recursive definition for a function most of the time... but theres nothing inherently bad about recursion... why do you hate it so much

It would be impossible for an NPC taking a shower to imagine themselves as an NPC taking a shower because that would imply they are in some way selfaware, and therefore not an NPC

In a small embedded system, it can easily cause stack overflow.

They’re not that hard in python. I was so happy when I figured out how to write my first recursive function. It let me iterate and get data from a source supposedly impossible to loop down, up, and through.

NPC detected

Not hating on recursion, however I really only use it back when studying linked lists, do they have any other useful function?

Can someone explain me the meme about recursive functions ?
When I started programming, recursion wasn't more difficult to understand than a for loop, I even think that it's easier to understand.

They are extremely useful for anything involving trees.

Some people are just retarded and not cut out to be programmers.

They're better for navigating tree structures.

traversing trees

some people find it difficult to understand
maybe its because they follow execution by reading the code on their screen and can't understand it when you're executing the same words twice

Recursion is useless and should be avoided unless you're doing ackermann function

there are some algorithms which are extremely difficult to implement iteratively whereas a recursive implementation is pretty straight forward

>Recursion is useless and should be avoided

Attached: brainletcastle.jpg (645x1000, 107K)

T. front-end web-shitter

i dont get it either

Recursion is bad programming

Attached: 8nRqoXW.png (800x729, 48K)

without recursion, how were you able to nest your head so deep into your stupid ass hole?

Most problems recursion causes me when it comes to time complexity of it

You're wrong.
Templates are.
And I'm looking at you STL.
Also Java, because being a Java developper is slavery.

It's usually not the fastest option.
But it can be easier to read with less chances of bugs.

Not everything has to be optimized for speed or memory use, often things just need to run error free.

Post your code to print every element of a balanced binary search tree (where all values to the left are smaller than their parent and all values to the right are larger) without using iteration

It's used all the time in artificial intelligence.

lmfao, what a fucking post

i mean without recursion kek not deleting that

As the other anons said, tree traversal is extremely difficult without recursion.
Also check out the Ackermann function.
One of the nice things about recursion is that it can often make deeply-nested logic more flat and modular. I'm working on a lisp interpreter in C, and I found that rewriting my stack machine as a bunch of mutually-recursive functions reduced line count and allowed me to move a lot of stuff from the heap to the stack, improving performance.

I have a MSc in artificial intelligence.
What do you have?

haahhahaah

I find that even tail recursion can be nicer to work with than iteration, despite being equivalent in power.

void iterativePrint(Node a) {
int traversed = 0;
int depth = 1;

while (traversed < Math.pow(2, getMaxDepth(total) - 1)) {
// 1. Go fully left
while (a.left != null) {
a = a.left;
depth++;
}
System.out.println(a.value + " " + depth);
traversed++;
// 2. Up until we can turn right
a = a.parent;
depth--;
// 3. Go right
a = a.right;
depth++;
System.out.println(a.value + " " + depth);
traversed++;
if (traversed >= Math.pow(2, getMaxDepth(total) - 1))
break;

while (a.value > a.parent.value) {
a = a.parent;
depth--;
}
a = a.parent;
// 5. Go right
a = a.right;
}
}

static int getMaxDepth(int a) {
return (int) Math.sqrt(a) + 1;
}

My solution for iterating over a bst without recursion. It worked when i did it but not sure if it's actually flawless or not. This is like 3 lines with recursion kek

fuck it looks like i'm squaring and square rooting something back for no reason i have no idea i haven't looked at this for a while

Nice argument NEET

>They are extremely useful for anything involving trees.
this. when you take algorithms you'll probably be looking at recursion a lot

>using recursion in a language who doesn't support recursion like Scheme does

Recursion is extremely easy to write and harder to mess up. There is a performance malus when compared to an iterative solution in many cases which is why I tend to avoid them. It'll always boggle my mind that people don't like recursion because it's "harder".

Recursive counterparts of iterative definitions aren't more complex. Like mapping a list is a linear time operation with both iterative and recursive definitions.

a degree from Jow Forums University

Preorder, postorder, inorder or some inverse order?

>I really only use it back when studying linked lists

Attached: American here.jpg (399x370, 23K)

best*
Imagine not liking elegant efficient code.
Brainlet.

There's still time to change your major. Maybe there will be a hot market for Art Historians by the time you graduate.

Oh boy another high-schoolers hate on recursion thread
I unironically LOLed, you can't be this retarded 10/10
> Templates are.
Can you elaborate? I don't disagree, just curious