Team Cape Posted December 4, 2016 Share Posted December 4, 2016 (edited) If I've missed any, let me know and I'll add them. It seems like a lot of people are having problems with this, so I want to fix this up. It's a very simple thing that greatly improves the readability of your code Variables: All variable names should start with a lower case letter for the sake of clarity. Example: private long time = System.currentTimeMillis(); Another example: private Area area = new Area(1, 2, 3, 4); Notice how the names in both are lower case. If you want to make a variable with more than 1 word, you would capitalize the first letter of the second word. private Area theArea = new Area(1, 2, 3, 4); private long timeStarted = System.currentTimeMillis(); Note that methods follow essentially the same format. Examples: public int onLoop() { return 0; } Note that the first word is not capitalized, but the second word is capitalized. public void eat() { } The first word is also not capitalized. Simple, right? Constants This is used for values such as widget ID's - values that are final that never changed. All letters are upper case and instead of putting a capital letter to start a new word, instead put a _ to signify a space. private static final int SOME_ID = 57; public static final int TIN_ROCK_COLOUR = 53; Thanks to @@Transporter for reminding me to put this in Objects and class definitions Classes define objects, and their first letter is always capitalized so people know that a class is being referenced. Notice how we said: private Area theArea = new Area(1, 2, 3, 4); The 'Area' object has a capital first letter, so we know we're not referencing another variable, for instance the one we named just before called 'area'. If we are defining a class, we would do it like so: public class Thing { //attributes } *** Notice the upper case first letter! *** If we wanted to define a 'Thing', then we would say: Thing something = new Thing(); ^ capitalized ^ capitalized Enums If you're not familiar with what enums is, but you're still coding on OSBot, this will probably look familiar to you: private enum State { BANK, MINE, RUN_AWAY }; Notice that all letters are capitalized. This is how enums are named - exactly like the static IDs from before. This is a very simple task that takes about 5 seconds to learn. If you're not going to properly format your code, and you ask someone for help, you will come across as either very unknowledgeable or just lazy. If you have any questions, please feel free to ask . If I made any mistakes, tell me - I wrote this up in about 5 minutes. Edited December 8, 2016 by Imateamcape 7 Quote Link to comment Share on other sites More sharing options...
Transporter Posted December 4, 2016 Share Posted December 4, 2016 private Area theArea = new Area(1, 2, 3, 4); This is normally refereed to as lower camel case. Another thing you could include is constants, which you use full capitals and separate words with the _ character. e.g public static final int TIN_ROCK_COLOUR = 53; 1 Quote Link to comment Share on other sites More sharing options...
Team Cape Posted December 4, 2016 Author Share Posted December 4, 2016 private Area theArea = new Area(1, 2, 3, 4); This is normally refereed to as lower camel case. Another thing you could include is constants, which you use full capitals and separate words with the _ character. e.g public static final int TIN_ROCK_COLOUR = 53; true i'll add that in now Quote Link to comment Share on other sites More sharing options...
Alek Posted December 4, 2016 Share Posted December 4, 2016 I flat-out don't allow scripters to use .NET bracket conventions on the SDN. It's one of my triggers. 2 Quote Link to comment Share on other sites More sharing options...
k9thebeast Posted December 4, 2016 Share Posted December 4, 2016 (edited) I flat-out don't allow scripters to use .NET bracket conventions on the SDN. It's one of my triggers. sleep(random(4000000,6000000)) 11/10 antiban Edit: Also @@Imateamcape you could add function javadoc, not that I think a ton of people use it but its a good intro none the less. Edited December 4, 2016 by k9thebeast 1 Quote Link to comment Share on other sites More sharing options...
Transporter Posted December 4, 2016 Share Posted December 4, 2016 I flat-out don't allow scripters to use .NET bracket conventions on the SDN. It's one of my triggers. By that do you mean this ugliness? public class Example { public void exampleVoid() { //doStuff } } 1 Quote Link to comment Share on other sites More sharing options...
Team Cape Posted December 4, 2016 Author Share Posted December 4, 2016 (edited) sleep(random(4000000,6000000)) 11/10 antiban Edit: Also @@Imateamcape you could add function javadoc, not that I think a ton of people use it but its a good intro none the less. i added in method formatting at the end of variables section because its essentially the same format (even though they're not variables) Edited December 4, 2016 by Imateamcape Quote Link to comment Share on other sites More sharing options...
k9thebeast Posted December 4, 2016 Share Posted December 4, 2016 i added in method formatting at the end of variables section because its essentially the same format (even though they're not variables) Ah meant like the description on the top /** * Whats this function do? * @param url an absolute URL giving the base location of the image * @param name the location of the image, relative to the url argument * @return the image at the specified URL * @see Image */ public Image getImage(URL url, String name) { try { return getImage(new URL(url, name)); } catch (MalformedURLException e) { return null; } } 1 Quote Link to comment Share on other sites More sharing options...
sudoinit6 Posted December 5, 2016 Share Posted December 5, 2016 Do enums get the underscore treatment for multiple words? Which of the following is correct for an enum? WALKINGTOBANK WALKING_TO_BANK Thanks! Quote Link to comment Share on other sites More sharing options...
Team Cape Posted December 8, 2016 Author Share Posted December 8, 2016 Do enums get the underscore treatment for multiple words? Which of the following is correct for an enum? WALKINGTOBANK WALKING_TO_BANK Thanks! yup Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted December 8, 2016 Share Posted December 8, 2016 By that do you mean this ugliness? public class Example { public void exampleVoid() { //doStuff } } Please don't, it hurts! 1 Quote Link to comment Share on other sites More sharing options...
pizzaman15 Posted December 16, 2016 Share Posted December 16, 2016 lol this wouldve been good to know about years ago for my school.. Quote Link to comment Share on other sites More sharing options...
Xerifos Posted December 16, 2016 Share Posted December 16, 2016 Please don't, it hurts! I have to program that way everyday at school since we program in C#... #VisualStudioProblems 1 Quote Link to comment Share on other sites More sharing options...
sudoinit6 Posted December 16, 2016 Share Posted December 16, 2016 I have to program that way everyday at school since we program in C#... #VisualStudioProblems From this noobs perspective it seems like it makes it easier to keep track of which curly brackets are a pair..... Quote Link to comment Share on other sites More sharing options...
Xerifos Posted December 16, 2016 Share Posted December 16, 2016 From this noobs perspective it seems like it makes it easier to keep track of which curly brackets are a pair..... Hahah once you get used to it you won't be that confused really, it's just a matter of time. Quote Link to comment Share on other sites More sharing options...