una_maquina 35 Posted May 10, 2021 Hi, so as you know it's all about readability of code that separates noobs from pros in programming. I think I'm not a complete noob anymore, but I still think that my way of writing code can be improved. Anyways, the way I write my code is I use a node-based system; but here's where I'm asking for help (here's a code example): private static Area geArea; public static boolean isInGe() { if(!geArea.contains(Client.getLocalPlayer())) { //logic to be made return false; } return true; } @Override public boolean validate() { return some condition that triggers the node; } @Override public void execute() { // Go to G.E. if not there if(!isInGe()) { return; } // Continue here } } This is how I usually structure my code, just making methods in node classes. I have to write a lot of returns, and can easily mess up by forgetting to put it there. Is this any good and how could I improve writing node classes? I'm still missing a lot of Java principles, so hopefully you can enlighten me. Thank you!
Bonfire 334 Posted May 10, 2021 Abstracting your code can work wonders toward improving readability (though there is such a thing as too much abstraction). I'd recommend using something like a Tree-Branch Framework to organize your code. Moving from normal task scripts to the aforementioned framework has significantly helped me structure my own code and make it more readable. In the case of the code you've provided above, it can help pull the validation away from the task/node/leaf, and allows you to create general conditions (like your isInGe() method) at a higher level in your script's structure. Though I would still consider myself a learner as well, so please take that with a grain of salt and do find what works for you. Best of luck 🙂
Aeglen 370 Posted May 10, 2021 1 hour ago, una_maquina said: Hi, so as you know it's all about readability of code that separates noobs from pros in programming. I think I'm not a complete noob anymore, but I still think that my way of writing code can be improved. Anyways, the way I write my code is I use a node-based system; but here's where I'm asking for help (here's a code example): private static Area geArea; public static boolean isInGe() { if(!geArea.contains(Client.getLocalPlayer())) { //logic to be made return false; } return true; } @Override public boolean validate() { return some condition that triggers the node; } @Override public void execute() { // Go to G.E. if not there if(!isInGe()) { return; } // Continue here } } This is how I usually structure my code, just making methods in node classes. I have to write a lot of returns, and can easily mess up by forgetting to put it there. Is this any good and how could I improve writing node classes? I'm still missing a lot of Java principles, so hopefully you can enlighten me. Thank you! I would totally use the tree-branch thing as Bon said, although it doesn't mesh with my weird coding style it will probably suit you. For nodes, I put all my utils methods in a single Utils class, which is where this GE checking thing would go. I don't like using number priorities, that's just asking for trouble and the validate() is almost always determined by a global String variable to avoid annoying complexities. Also I tend not to use areas unless they're really needed, I just find them yucky but as I said my coding style is weird
una_maquina 35 Author Posted May 10, 2021 Thanks guys, appreciate the inputs. I've heard about tree-branch, I'll take a further look into it
Recommended Posts
Archived
This topic is now archived and is closed to further replies.