Deceiver Posted February 18, 2016 Share Posted February 18, 2016 When programming, regardless if you're new or old to programming, it should always be your best practice into improving your code for good(clean) looks, so that you and others may understand it as well, etc. This short and simple tutorial (more of a guide) will help you understand some general tips when you start your new project. Object DefiningBad Example: public RS2Object entrance; public RS2Widget wait; public RS2Widget cont; public NPC guard; public NPC tzkih; public NPC tzkek; public NPC tokxil; public NPC ytmejkot; public NPC ketzek; public NPC jad; public NPC ythurkot; String state; int startHPExp; int startATTExp; int startDEFExp; int startSTRExp; int completed; long startTime; long runTime; This is an example of bad code! Most of us have probably defined our variables like this before and thought it is correct. Though it is correct and will work, it is not the most efficient and clean way to define them. Good Example: int profit, age; int a = 4, b = 6; long startTime, timeRun RS2Object guard, target, chicken; RS2Widget selectX, makeAll; ..... so forth Fewer lines of your code, all your variables are still there and it looks neater and easier on the eyes. Casting and 'this'Bad Example: this.wait = this.widgets.getWidgetContainingText(new String[] { "Hey, JalyYt, you were in a cave only a moment ago." }); this.cont = this.widgets.getWidgetContainingText(new String[] { "Well done in the cave, here take TokKul as reward." }); this.entrance = (RS2Object)this.objects.closest(new String[] { "Cave entrance" }); this.guard = (NPC)this.npcs.closest(new String[] { "TzHaar-Mej-Jal" }); this.tzkih = (NPC)this.npcs.closest(new String[] { "Tz-Kih" }); this.tzkek = (NPC)this.npcs.closest(new String[] { "Tz-Kek" }); this.tokxil = (NPC)this.npcs.closest(new String[] { "Tok-Xil" }); this.ytmejkot = (NPC)this.npcs.closest(new String[] { "Yt-MejKot" }); this.ketzek = (NPC)this.npcs.closest(new String[] { "Ket-Zek" }); this.ythurkot = (NPC)this.npcs.closest(new String[] { "Yt-HurKot" }); In this example, the variable names are the same ones we defined earlier, therefore, we do not need this. As well, we do not need the absurd and gross looking String array and casting. Good Example: wait = widgets.getWidgetContainingText("Hey, JalyYt, you were in a cave only a moment ago."); entrance = objects.closest("Cave entrance"); guard = npcs.closest("TzHaar-Mej-Jal" ); tzkih = npcs.closest("Tz-Kih" ); Refer to the above picture. Method NamingBad Example: void eatfood() {} void attacktarget() {} Good Example: boolean isUnderAttack() {} boolean findTarget() {} void eatFood() {} I hope this simple but hopefully effective guide has opened some new things to your eyes and knowledge of programming your projects. 7 Quote Link to comment Share on other sites More sharing options...
Chris Posted February 18, 2016 Share Posted February 18, 2016 Nice guide. Will help a ton of new scripters. ayylmao Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted February 18, 2016 Share Posted February 18, 2016 Use getters where appropriate npcs //... getNpcs() //... Don't abuse public/static, only when necessary - variables should be private (with setters and getters if needed), to prevent any possible problems. 4 Quote Link to comment Share on other sites More sharing options...
Chris Posted February 18, 2016 Share Posted February 18, 2016 long startTime, timeRun 1 Quote Link to comment Share on other sites More sharing options...
genzyBug Posted February 18, 2016 Share Posted February 18, 2016 CTRL + SHIFT + F .............EZ Quote Link to comment Share on other sites More sharing options...
iJodix Posted February 18, 2016 Share Posted February 18, 2016 (edited) what ?? f -> F ???? Edited February 18, 2016 by iJodix Quote Link to comment Share on other sites More sharing options...
Deceiver Posted February 18, 2016 Author Share Posted February 18, 2016 Nice guide. Will help a ton of new scripters. ayylmao ayylmao Use getters where appropriate npcs //... getNpcs() //... Don't abuse public/static, only when necessary - variables should be private (with setters and getters if needed), to prevent any possible problems. Good tip! what ?? f -> F ???? whatDo(); Quote Link to comment Share on other sites More sharing options...
GoldenGates Posted February 18, 2016 Share Posted February 18, 2016 what ?? f -> F ???? CamelCase conventions, this should be nothing new if you remotely deserve any sort of Scripter rank... 2 Quote Link to comment Share on other sites More sharing options...
Botre Posted February 18, 2016 Share Posted February 18, 2016 (edited) I don't like declaring multiple variables on the same line. It tires the eye imo. Because of completion OCD I occasionally will use a "this" where it's not necessary, or sometimes I'll just do it to improve readability. I will sometimes prefer snake_case over headlessCamelCase when the latter looks awkward. But yeah. Conventions. Edited February 18, 2016 by Botre Quote Link to comment Share on other sites More sharing options...
GoldenGates Posted February 18, 2016 Share Posted February 18, 2016 I don't like declaring multiple variables on the same line. It tires the eye imo. Because of completion OCD I occasionally will use a "this" where it's not necessary, or sometimes I'll just do it to improve readability. I will sometimes prefer snake_case over headlessCamelCase when the latter looks awkward. But yeah. Conventions. Had to take a Python class and it was such a pain transitioning between conventions. D: Quote Link to comment Share on other sites More sharing options...
Botre Posted February 18, 2016 Share Posted February 18, 2016 Had to take a Python class and it was such a pain transitioning between conventions. D: Indent your code blocks with 4 spaces. Two blank lines between top-level definitions, one blank line between method definitions. Quote Link to comment Share on other sites More sharing options...
Deceiver Posted February 18, 2016 Author Share Posted February 18, 2016 I don't like declaring multiple variables on the same line. It tires the eye imo. Because of completion OCD I occasionally will use a "this" where it's not necessary, or sometimes I'll just do it to improve readability. I will sometimes prefer snake_case over headlessCamelCase when the latter looks awkward. But yeah. Conventions. this is a roast thread tbh 2 Quote Link to comment Share on other sites More sharing options...
iJodix Posted February 18, 2016 Share Posted February 18, 2016 CamelCase conventions, this should be nothing new if you remotely deserve any sort of Scripter rank... You obviously missed my point, Why would one need to use camelcase if it doesn't improve anything ? That's like saying go buy a new table and not the old one because how ugly it looks even though they both do the same thing without any issues, Quote Link to comment Share on other sites More sharing options...
GoldenGates Posted February 18, 2016 Share Posted February 18, 2016 You obviously missed my point, Why would one need to use camelcase if it doesn't improve anything ? That's like saying go buy a new table and not the old one because how ugly it looks even though they both do the same thing without any issues, That's like saying dont capitalize first letter of a sentence. It's super common practice, makes reading easier and 'correct' according to standards. Quote Link to comment Share on other sites More sharing options...
iJodix Posted February 18, 2016 Share Posted February 18, 2016 That's like saying dont capitalize first letter of a sentence. It's super common practice, makes reading easier and 'correct' according to standards. Lol .. if only you read my post. Quote Link to comment Share on other sites More sharing options...