14

uSE AnY pRogrAmMinG L@ngu@g3 yOu liKe.

1nTervi3weRs Do N0t CarE aBouT tHe L@nGuAge.

Fuck you. Stop asking time complexity or space complexity of functional code. No one fucking knows.

Comments
  • 2
    "functional code" code that works or code programmed in functional style?
  • 1
    @Demolishun functional style
  • 3
    I could see this being an issue with C++. gcc likes to take recursive functions and turn them into loops when compiling. So the space used would be small for stack variables. Which compiler used might make a difference.
  • 0
    @Demolishun if you're writing recursions you're doing something wrong already, no?
  • 5
    @iiii Some problems are easier to reason with recursion.
  • 1
    @Demolishun and are easy to remake into loops as well. Just add some fake stack and done.
  • 7
    @iiii
    Actual functional languages do tail call optimization. Tail-recursive functions are compiled as loops there.

    In such functional languages, you are allowed to write a recursive solution as a tail-recursive function. You don't need to convert it to a loop by hand.
    And sometimes a recursive solution is easier to read and understand.
  • 2
    @iiii I'm very interested in how that works. Can you show me an example
    with the classical filesystem traversal problem?
  • 0
    @Oktokolo and C++ is not a functional language. It can do some recursion optimisation but no one should rely on that, because it's actually not a defined feature of the language, as far as I am aware
  • 0
    @hjk101 what is the definition of it?
  • 1
    How can you not get time complexity from functional code?
  • 0
    @iiii https://rosettacode.org/wiki/...
    Or pick any other language example with a recursive walk function actually visible.
  • 1
    @hjk101
    1. scan current directory.
    2. Print all files.
    3. Add all subdirectories to a list.
    4. Take the first directory in a list and remove it from the list
    5. Apply everything from 1 to this directory
    6. Repeat until the list is empty.
  • 0
    @iiii thanks didn't know what you meant with fake stack but makes sense now.
    I was thinking along the same lines with building an itterable datastructure.
  • 2
    @hjk101 anything that can hold intermediate values in the way you need
  • 1
    @iiii good luck trying to parse languages without using recursion.

    Doable? Maybe.
    Maintainable? No way.
  • 1
    @GeorgeBool I find some problems are much easier to reason about with recursion. Also, why spend the time making it non-recursive? If you structure it with a tail call the compiler can do whatever it likes with the code. The place I use it the most is trees.
  • 0
    @bioDan for parsing languages no one sane uses recursive functions but parsers based on automatons and grammar...
  • 0
    @iiii which are recursive.. if you are building a parser.
Add Comment