Hacker News new | past | comments | ask | show | jobs | submit login

Isnt this a CPU optimisation thing, ie code & languages working better for some instruction sets than others?

One of the languages I've used in the past always performed best on certain AMD cpu's, but that was when we could choose what cpu the compiler was to optimise for, ie 286, 386 etc etc.

I'm also aware of backroom shenanigans going on with some languages and tools working better for some CPU's.

This 12 year old post goes into a lot of detail https://stackoverflow.com/questions/1414911/intel-x86-assemb...




Tail call optimization has nothing to do with optimizing for different CPUs, it's about dropping a function's stack frame when it's evaluating its return expression and its stack frame isn't needed anymore.


Is this the difference in calling conventions ie callee or caller stack clear up? https://en.wikipedia.org/wiki/X86_calling_conventions#List_o...

This is half the problem different terminology in use between different age groups, just like slang is different between different age groups.


I'm not sure, so here are a couple examples.

    def f() =
       g()
In a language implementation that doesn't optimize tail calls, the stack would look like the following after the call to g:

    g
    f
    main
In a language implementation that does optimize tail calls, the stack would look like this, because the result of f is whatever the result of g is so f is no longer needed:

    g
    main
If a language implementation doesn't optimize recursive tail calls, the following code will quickly overflow the stack and the program will crash:

    def loop() =
        do something...
        loop()
In a language implementation that does optimize recursive tail calls, this code can run forever because loop's stack frame gets replaced with the stack frame of the new call to loop.

The reason people want recursive tail calls optimized out is at a much higher level than anything to do with the actual CPU instructions being used, they just want to have a way to write recursive functions without worrying about the stack overflowing.

What's my age group, by the way?


I have never seen this referred to anything other than things like tail-call recursion, tail-call optimization, etc.

Languages like Python make implementing simple loops like:

    def loop():
        <whatever>
        loop()
impossible.

Python will reach a maximum recursion depth and error.

Why is this important? Like I said, it makes looping very easy. For example, actors can almost be trivially implementing in languages with tail-call recursion.

It’s not in Python because like most things in Python, van Rossum doesn’t like it because <reasons>.

https://stackoverflow.com/questions/13591970/does-python-opt...

There’s little point in having full traces of the data doing in and out of the tail-call loop is immutable, so you only really care about the current call of the function.


<goes away to find out what if its in my preferred language & tool>

Its not something I've every heard of before, I guess its peculiar to Python though but dont most languages have some eccentricity?


It's absolutely not peculiar to Python, it's something that every single language implementation has to make a decision on one way or the other.

Here's an SO answer from 2008 about how to enable TCO in various C and C++ compilers: https://stackoverflow.com/questions/34125/which-if-any-c-com...

There are many things both you and I have never heard of before. That's normal.


Yes, the different terminology is a reflection of the entrance of so many new entrants going for what is easy in the short term, instead of learning the theory of their industry and thus learning better approaches that are not 'immediately' obvious.

This lack of learning theory in our industry, instead going for something that is 'easy to get started' explains the popularity of python and javascript, and at the same time why python and javascript are littered with problems that have already been solved, and cluttering up the field of knowledge by reinventing terminology because they never learned the original existing terms.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: