• uberrice@feddit.de
    link
    fedilink
    arrow-up
    2
    arrow-down
    1
    ·
    edit-2
    1 year ago

    If you think a block of code needs a comment, turn it into a method and give it a proper name instead.

    Really depends. Yes, if someone doesn’t get what’s wrong with this statement, they should. But you shouldn’t wrap something in a method all the time just because. Sure, maybe you can make it an inline method, but usually, a method call takes time, and while it’s not a lot of time, in constrained or complex system that can accumulate. A lot. Sure, the compiler might optimize stuff away, but don’t just go blindly trusting your compiler.

    Sure, a method call for something that gets called once a second is not a problem. But when you suddenly have thousands and thousands of method calls when say, you click a button, which calls method x which calls method x1 which calls y1 and y2 which call z1-10 and so on, then the method calls can suddenly turn into a problem.

    Maybe not on a fast, modern device, but on an older or more constrained device. If your code never runs on there, sure, don’t bother.