Ka0s_Dem0n
Ka0s_Dem0n

Reputation: 13

Anonymous Methods too much of a good thing? (C#)

Greetings,

I'm working in a code base that uses alot of anonymous methods, where the anonymous methods are chaining other anonymus methods that call the same thing the first one calls.

main()
{
 anonymous1(); 
}
anonymous1()
{
  // call anonymous2 
}
anonymous2()
{
 //call anonymous3
}
anonymous3()
{
  // Call anonymous1
}

thats the basic break down, sorry for the over simplification.

My concern is that one of the anonymous methods are causing problems chaining the calls like that. IMO it looks like it's just bad recursion that is going to cause a stackoverflow exception.

Thanks for your help in advance.

Upvotes: 1

Views: 315

Answers (2)

devoured elysium
devoured elysium

Reputation: 105037

It'll all depend on how you implement logic.

Recursion by itself is not and should not be a problem.

One could argue the same about any file/folder algorithm that uses recursion. If it is well implemented, you have nothing to worry about.

Upvotes: 2

Gordon Gustafson
Gordon Gustafson

Reputation: 41209

Its not really the anonymous methods that are the problem, even though them being anonymous can make things a tad bit harder to keep track of. The code in the methods themselves is what would cause a stackoverflow or any other types of problems. As long as the code is as clear as possible and accomplishes its task well, you don't really need to worry about the structure.

There's nothing wrong with recursion, and you can allay any of your doubts with some testing and contemplation of your needs.

Upvotes: 0

Related Questions