1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Tutorial Correct use of If Statements

Discussion in 'Tutorials & Resources' started by goody599, Jun 23, 2019.

  1. goody599

    Joined:
    Nov 13, 2015
    Messages:
    11
    Likes Received:
    2
    -
     
    #1 goody599, Jun 23, 2019
    Last edited: Sep 5, 2021
  2. Savior

    Savior Java Warlord

    Joined:
    Nov 17, 2014
    Messages:
    4,906
    Likes Received:
    2,748
    If statements themselves dont add any real overhead whatsoever. The real cause of unoptimized bots is not reusing already processed data.
    For example you should calculate the distance once and save it in a variable, instead of calculating it 3 times in a row for the same block of code.

    Doesnt mean that you shouldnt care about an optimized controlflow though, in fact it can solve other problems such as sticking to one action per loop.
    --- Double Post Merged, Jun 24, 2019, Original Post Date: Jun 23, 2019 ---
    Also you picked a bad example, the original code is perfectly fine and only 1 of those if statements can be executed anyway. Whereas your version has side effects.
     
    Derk and Defeat3d like this.
  3. goody599

    Joined:
    Nov 13, 2015
    Messages:
    11
    Likes Received:
    2
    -
     
    #3 goody599, Jun 24, 2019
    Last edited: Sep 5, 2021
  4. Defeat3d

    Defeat3d Primate

    Joined:
    Oct 30, 2014
    Messages:
    3,072
    Likes Received:
    1,894
    [​IMG]
     
    Derk and Jhinn like this.
  5. Jhinn

    Joined:
    Jun 9, 2015
    Messages:
    3,646
    Likes Received:
    1,337
    [​IMG]
     
    Derk and Defeat3d like this.
  6. Savior

    Savior Java Warlord

    Joined:
    Nov 17, 2014
    Messages:
    4,906
    Likes Received:
    2,748
    I wasn't immediately referencing your code, i was just expanding on the example you gave for simplicity.

    I mean this is pretty much irrelevant to the discussion but i dont see how distance calculations could possibly be wrong, assuming you're selecting the correct entities to begin with.

    PlayerSense is merely an API for persisent key-value mapping, how or where you apply it in your code is completely unrelated.


    So again, optimizing the control flow will almost naturally result in less redundant computations, but if statements are inherently not a factor considering how complex other computations are in comparison.
     
    Derk and Defeat3d like this.
  7. Defeat3d

    Defeat3d Primate

    Joined:
    Oct 30, 2014
    Messages:
    3,072
    Likes Received:
    1,894
    stackedoverflow
     
    Fabreze and Derk like this.
  8. goody599

    Joined:
    Nov 13, 2015
    Messages:
    11
    Likes Received:
    2
    -
     
    #8 goody599, Jun 24, 2019
    Last edited: Sep 5, 2021
  9. x3r4

    Joined:
    May 30, 2019
    Messages:
    13
    Likes Received:
    9
    If you want to prove a point, provide evidence. Make some runtime tests comparing "shitty' if statements with your constructs. You're just guessing right now, wouldn't want to be an ignorant programmer in court now would we? :D
     
    Fabreze and Savior like this.
  10. Derk

    Derk 12 year old normie

    Joined:
    Jan 8, 2015
    Messages:
    2,766
    Likes Received:
    1,339
    You're hella clueless brother. 4 years developing bots and you're talking about if statement efficiency?

    Almost everything you say isn't fully correct and you sound like you have to Google what stuff means and then insert words that you think make you sound smart.

    What the fuck does polymorphism have to do with using if statements... Overloading functions does not cause stability issues.... Reusing implementations is actually a good thing to do to avoid rediscovering the wheel....

    And your English is abhorrent.
     
  11. Savior

    Savior Java Warlord

    Joined:
    Nov 17, 2014
    Messages:
    4,906
    Likes Received:
    2,748
  12. Fabreze

    Fabreze #1 Fabric Cleaner

    Joined:
    Mar 18, 2017
    Messages:
    388
    Likes Received:
    106
    Bro what???

    Don’t worry about the distance returning the wrong value, that’s a point of abstraction that is not your area of concern but that of the client developer/whoever created that method in the first place... This will hold up in court as it up to the creator of the method to ensure it works properly. If you build your code around these api abstractions, your code will run absolutely fine due to the very nature of Runemates bot architecture which can handle/correct inaccuracies loop to loop. In addition your code will be guaranteed much more efficient if you take saviors advice and cache complex api calculations instead of “optimizing if statements” and this not only creates more efficient code, it is easier to do as you dont have to mess with any of the already established bot logic, assuming that it works fine already.... you should really at least learn fundamental computer science concepts before spouting nonsense.
     
    #12 Fabreze, Jul 27, 2019
    Last edited: Jul 27, 2019

Share This Page

Loading...