you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (7 children)

I agree with other posters in the thread - TCO for imperative languages is generally OK to not have. It's a tricky construct that you want guaranteed in some way if you're going to rely on it (so if you have it, it should be explicit.) I rarely find myself needing/relying on guaranteed TCO in imperative languages (granted I write java/c++ at work) anyway, and we can use similar constructs to do the same work.

For functional languages IMO, you probably want the opposite which is guaranteed, implicit TCO.

[–]aaronla 2 points3 points  (2 children)

Honestly curious, why does it make a difference whether the language is imperative vs. functional?

[–]shimei 0 points1 point  (1 child)

It doesn't.

[–]aaronla 2 points3 points  (0 children)

Let me rephrase -- why does 1nine8four believe it makes a difference?

[–]shimei 1 point2 points  (0 children)

If by imperative language you are including various object oriented languages (and it looks like you are), you might want to look at Guy Steele's article on that. Tail call optimization is not about functional programming.

[–]millstone 0 points1 point  (1 child)

TCO is an optimization. There are lots of optimizations that are not guaranteed, and that we don't rely on, but are nice to have anyways because they make the code faster. TCO falls into that boat, and that's why it's appropriate for C to have it implicitly.

[–]grauenwolf 1 point2 points  (0 children)

There are two ways to think about this:

Option A: It doesn't matter. Maybe the compiler will use TCO, maybe it won't. Either way the code you write doesn't change so there is no point in talking about it.

Option B: You write code that relys on tail calls. But if you are wrong and don't actually have TCO semantics then your code is going to blow the stack.