[API-Design] Unsupported Function Exceptions Vs Default Return Values

Discussion in 'Executive Blogs' started by Cloud, Mar 13, 2014.

?

Unsupported Function Exceptions Vs Default Return Values

  1. Unsupported Function Exceptions

    11.1%
  2. Default Return Values

    0 vote(s)
    0.0%
  3. Hybrid Option (See Arbiter's post below)

    88.9%
Thread Status:
Not open for further replies.
  1. Cloud

    Cloud The Developer

    Joined:
    Jul 28, 2013
    Messages:
    2,378
    Likes Received:
    781
    In V1.0.0 Beta 2 The API is designed to throw an exception when a function is used that's not supported in the active game mode. For example, if you try to use Player#getTitle or Player#getAdrenalineGauge in oldschool, an OSRSUnsupportedFunctionException will be thrown. This is a good way to notify a new developer that a function isn't supported in the game mode. The downside is that when creating hybrid scripts bots you either have to have many Environment.isOSRS or Environment.isRS3 calls, or you have to have exception handling code that can make your code more difficult to understand.

    The alternative to this, which could be as implemented as soon as Beta 3 if the community likes it, is to simply return default values and place a RS3Only and OSRSOnly annotation on the method. Examples of default values would be -1 for an int, null for an Object, and an instance of a Collection for any collection (for easier iteration). This would make it so developers would need to be more familiar with the API and javadocs to understand why something is returning a default value, but it would make it easier to create hybrid scripts bots.

    The decision is up to you, vote in the poll and influence the future of the RuneMate API :)
     
  2. Booch

    Joined:
    Mar 9, 2014
    Messages:
    40
    Likes Received:
    7
    Default Return Values would be good :)
     
  3. dog_

    dog_ 0xCAFEBABE

    Joined:
    Nov 3, 2013
    Messages:
    270
    Likes Received:
    55
    Default return values.
     
  4. Arbiter

    Arbiter Mod Automation

    Joined:
    Jul 26, 2013
    Messages:
    2,525
    Likes Received:
    1,042
    I'd like to add a third option to the table, a hybrid. If the script bot metadata contains the required version (i.e. RS3 only method being called by an RS3 only or hybrid script bot) it returns default return values. If the script bot metadata does not contain the required version (i.e. RS3 only method being called by an OSRS only script bot) it returns an Unsupported Version Exception. That way new developers get the informative exception, and experienced developers don't have to exception handle. Added the hybrid option to the poll. Thoughts?
     
    Booch and dog_ like this.
  5. dog_

    dog_ 0xCAFEBABE

    Joined:
    Nov 3, 2013
    Messages:
    270
    Likes Received:
    55
    I like.
     
  6. Arbiter

    Arbiter Mod Automation

    Joined:
    Jul 26, 2013
    Messages:
    2,525
    Likes Received:
    1,042
    If you want your vote changed, just post here. Changed yours for you dog_.
     
  7. Booch

    Joined:
    Mar 9, 2014
    Messages:
    40
    Likes Received:
    7
    Actually, change my vote to that. Very nice way of putting it Arbiter, kind of getting best of both worlds. Change my vote please
     
  8. House

    Joined:
    Nov 8, 2013
    Messages:
    27
    Likes Received:
    3
    Sounds great.
     
  9. Arbiter

    Arbiter Mod Automation

    Joined:
    Jul 26, 2013
    Messages:
    2,525
    Likes Received:
    1,042
    Thanks man. Full disclosure, it does add a marginal overhead, equivalent to checking a boolean (which isn't much fyi).
    Assuming you wanted your vote changed, so I did. Let me know if that's not true and I'll change it back.
     
  10. Cloud

    Cloud The Developer

    Joined:
    Jul 28, 2013
    Messages:
    2,378
    Likes Received:
    781
    More than that, but's it's not nearly enough to even make a noticeable difference.
     
  11. Salvation

    Salvation First Bot Author

    Joined:
    Aug 7, 2013
    Messages:
    249
    Likes Received:
    63
    Neither, the developer should figure this out while writing the script bot.

    The script bot should determine which game it's running on and use simple conditions (as simple as a single boolean, even) to determine the method to be used.
     
  12. Booch

    Joined:
    Mar 9, 2014
    Messages:
    40
    Likes Received:
    7
    How bout the idea of a hybrid script bot that functions for RS3 and OSR?
     
  13. Salvation

    Salvation First Bot Author

    Joined:
    Aug 7, 2013
    Messages:
    249
    Likes Received:
    63
    That was included in my statement.
     
  14. Cloud

    Cloud The Developer

    Joined:
    Jul 28, 2013
    Messages:
    2,378
    Likes Received:
    781
    However if they don't, they can't just have a bizarre error message because the hook isn't available. It needs to fail, but elegantly.

    Edit: The Hybrid solution has been selected, default values if it's a hybrid script bot, with an error message if it's not.
     
  15. Arbiter

    Arbiter Mod Automation

    Joined:
    Jul 26, 2013
    Messages:
    2,525
    Likes Received:
    1,042
    Thanks for helping shape the API folks. This is what the dev beta release is all about. :D
     
  16. Salvation

    Salvation First Bot Author

    Joined:
    Aug 7, 2013
    Messages:
    249
    Likes Received:
    63
    You should just demote the script bot writers who don't know what they're doing or have not properly tested a script bot before releasing it. I'd call that elegant.
     
  17. Booch

    Joined:
    Mar 9, 2014
    Messages:
    40
    Likes Received:
    7
    I'd agree with the latter. If they're completely clueless about scripting then that too but not everyone is born knowing how to develop software and scripts bots(In this case) so instead of demoralizing them we should encourage, help & teach them.
     
    Arbiter likes this.
  18. Salvation

    Salvation First Bot Author

    Joined:
    Aug 7, 2013
    Messages:
    249
    Likes Received:
    63
    Agreed, they can learn and we can help them. But beginner script bot writers (especially with Botwatch around the corner) should not be releasing public scripts bots. Therefore, elegant error throwing isn't needed, it just needs to be effective.
     
  19. Cloud

    Cloud The Developer

    Joined:
    Jul 28, 2013
    Messages:
    2,378
    Likes Received:
    781
    Decision finalized, hybrid selected.
     
Thread Status:
Not open for further replies.

Share This Page

Loading...