2

When people write functions/methods with bodies smaller that the call header (-_- ).

Function calls are not free people! Just Inline that shit manually (or at least make sure the compiler does so)!

double degree_to_radians(double degree){
....return (degree / 180.0) * M_PI;
}

Comments
  • 4
    Or make it static so that the compiler can inline it. Making it a macro could already blow up the way it is written, and even if that were adapted to macro usage, it could still cost performance.

    Btw., the "devrant" tag does not mean "developer rant". There are only devs here, so every rant is obviously a developer rant. No finance, HR, or sales folks rant. "devrant" is for stuff about devrant.com itself.
  • 1
    Yadda yadda, devrant tags actually for devrant.io devrant.com and devrant app only.

    As for your question, throw a inline there and call it a PR.
  • 1
    If it is not in a class, the compiler should inline it. So this isn't too bad.
  • 1
    (I hope that I got the point, so..)
    When I was learning code I was taught to make some methods as smaller as possible like this to be easier to read and make it possible to be reused:

    function calculatevalue(a)
    return a * 100

    Later I learned about the cost of functions, but also that the compiler can optimize it, making something like the inline and the static.

    Anyway, if I'm going to use this calculate function a lot of times, even if the compiler isn't going to optimize it and it is not a big cost, then I prefer to write that small function to make it easier to maintain
  • 0
    @rittmann sure there is a cost but are you working with a system with hard limits?
  • 0
    @melezorus34 yes, and no. I work with Android then I need to presume that the user has a limit amount of resources, but I know that the compiler can lead well with that kind of methods, then I do it a lot when I'm coding for it. When I'm coding games or others stuffs I generally don't do it
  • 0
    @rittmann well I can assure you it's negligible with current processors, so don't worry optimizing first, do the thing then optimize and refactor.

    Part of the excuse of us never releasing our side-projects is perfectionism.
  • 0
    @melezorus34 I don't optimize first if it isn't required, but a like do optimize the code as possible as I can
Add Comment