Jump to content

Good Code Organization


JKreas

Recommended Posts

Hey there,

 

I'm working on my third script and I notice that I have had just the main class Java file for my first two scripts. For a lot of the open source scripts I learned from, people had TaskHandlers and seperate files to the point where they had folder organization for the whole script. Am I missing something, or are my scripts probably just too simple to need additional files?

 

I've done a bucket collector from Lumby bank, seaweed picker, and fish cooker in Burthy. 

 

Cheers

Link to comment
Share on other sites

It generally depends on the complexity of the script you're making and how you like to code. You're only coding for OSRS, so it's easy to pick up bad practices, and it generally doesn't matter too much. For example, a zulrah killer's been written in a singe class before, but it's just horrific to maintain. Find something that works for you :)

 

Link to comment
Share on other sites

I believe that, the more complex a script is, the more organization you must have for it (this mean more classes and shit)

I don't see how the scripts you mentioned would need to have lots of classes, unless you wanna make your own walking, your own methods to cook, pick stuff up, but that would be a time you wouldn't need to consume cuz the osbot API is rich enough and can provide everything you need.

Link to comment
Share on other sites

For the scripts you are describing it wouldn't be a problem to have everything in one class, but it's always nice to separate actions or tasks (like banking) from the main class when it gets a little more complex. This way you can easily adapt it when necessary & find/fix bugs. The general idea is that you can look back at the script in 2 years & still understand it while at the same time being readable/adaptable for another scripter (even if that'll never happen). Commenting your code helps with that too.

This is also an interesting read for any script that you want to be expendable (or is big in general):

 

Link to comment
Share on other sites

I feel like that for small scripts, and for other small programs too, it does not matter how you organize your code as it most likely will only have some hundred lines of code. However, if your script is bigger or could eventually become bigger it's good to at least try to follow the single responsibility principle, which basically means that one class should be responsible of one functionality/feature. For example one functionality could be banking, pathing or a break manager. Not only will this help with organizing your code, but you might get some reusable modules which you can use in your other scripts. If you want to do even more or just learn what you could do, check out SOLID design principles.

Link to comment
Share on other sites

Often, a single class is enough, but for larger projects you might need to take advantage of object oriented design principles. While most scripts can make good use of object orientation, it is typically AIO scripts which make best use of it, as abstracting away details such as specific string values becomes really powerful. As an example of this, here's the source code for my AIO Herblore script (available on the SDN) for you to peruse: https://github.com/apaec/aio-herblore

  • Heart 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...