Small sample program that is easy to understand and work with. |
Output of above program. |
More complex part of a program that determines what code to run next. |
To organize this code, Java has classes which are used to put related code all in one file, while keeping less relevant code in another file. This helps with organization, similarly to how a book is divided into chapters.
Code all put into a single class without being properly organized. |
On the left is part of the original code when all of it is in a single class. As you can see, it's long and confusing with so much there that you can't easily see all of it at once.
Simplified code that is properly organized and distributed throughout multiple classes. |
However, below that image is a simplified version where I have put the code responsible for loading add-ins into a separate class. It is now easy to see that the single
Code for "loadJars()" method shown above. |
Below that is a third image, which shows the code that is run when the "loadJars()" method is used. This is much easier to understand and won't result in as much confusion down the road. As you can see, even the "loadJars()" method contains another method, "loadJar(f, false)" that loads each specific file.
By putting methods within other methods, the code is even neater and simpler to understand! This is known as object-oriented programming, where "all the functionality that's associated with an [object] is collected inside the code for the [Object] class" (Burd 170).
What do you think of the organization used in modern, object-oriented programming languages? Does it make the code look neater and less confusing, or is the condensed form easier to follow as the code doesn't jump around?
Works Cited:
Burd, Barry. Java for Dummies. 7th ed., John Wiley & Sons, 2017.
Hi Josh! You really emphasized the importance of keeping code organized and accessible. As a new programmer with no prior experience, I can use this information to help me edit and write code efficiently while keeping it neat and tidy! I have little experience in the coding field, but I think that the organization of the code can sometimes seem confusing when it is condensed, since I prefer seeing each individual part. How do you personally organize your code? Is there a specific way you do it or is it situational?
ReplyDeleteHi William! I like to make sure that the code is all in separate places based on what it is for. For example, all code that keeps track of files is in one place, while the code that keeps track of the users will go in another place. Then if there is an issue with the users, I can narrow down the cause of the problem faster!
DeleteHi josh! I have always been interested in programming and this post really helped me! I don't have any experience in stuff like this but i have always wanted to learn about it. The way you explained classes and codes made it really easy to understand and i found it fascinating.
ReplyDeleteHi Kasyn! Programming is very easy to begin learning! There are lots of great tutorials online and in the libraries that make it a fun and easy thing to learn, not to mention very useful! Good luck!
Delete