4 ms·
Pointers - ok. But can't you (or are you better off not to) do recursion in Java? Why is that exactly?
by RJF 15y ago
Pointers - ok. But can't you (or are you better off not to) do recursion in Java? Why is that exactly?
- deleted 15y ago[deleted]
- william42 15y agoRecursion isn't worthwhile in Java because of 1) a lack of tail-recursion and 2) the clunkiest possible syntax and most restrictive possible semantics for lambdas.
- esrauch 15y agoThis is a very strong statement. AFAIK most languages don't have do tail-recursion in general (Even most implementations of common lisp, and Clojure only if you use a special keyword). Recursion is worthwhile in certain cases in any language where the problem naturally calls for recursion; things like DFS and BFS are a lot uglier without recursion. Lambdas and first class functions really aren't necessary for a lot of situations where recursion is natural, and in those scenarios it is clearly worthwhile in Java.
- kaffiene 15y agoWhat rubbish. Recursion does not require lambdas and is quite obviously a different concept entirely. Tail recursion is (a) only an optimisation feature and (b) absent is most programming languages anyway. Pure FUD