Bee Organized

Have you ever got in a situation when you needed to review some application or a piece of code you wrote several month ago ? And once you open the file, the code looks like a bunch of random characters rather than a sequence of lines of code that can actually drive an application ? I bet there are plenty of those who had to rethink a part of their application, to remember what that part of code should do and then try to rebuild it. All this, because the code is intelligible and there are no comments to give you a hint on what you were trying to do. That was the moment when you said to yourself: Enough !!! From now on I gotta be more organized, more careful with the code I write… Yes… I bet there are plenty of those who thought that… And I bet there are plenty of those who couldn’t keep their promise of being more organized…

Respect your work and you will respect yourself. Respect yourself and others will respect you… (quite a Zen moment :D )

There are plenty of articles on the web about how to organize your work and how to organize your code. However, I feel this will always be a subject worth reading about. Especially by those who just started coding or by those who feel they are not organized enough. Having been through this, myself, I’ve decided to give some advice to those who need one. Maybe this article could help others…

Organize your code

With OOP (Object Oriented Programming) is a lot easier to organize the projects. The application could be considered a sum of objects that interact with each other. These objects are instances of classes that model similar entities or behavior. Further more, similar classes can be organized into a package. This way you will always know a package what type of classes could contain so even if you don’t know the name of the class, at least you know where to look for it. Once you find your class, you could easily find certain properties or methods that you need.

Also, the flash animations you create could contain quite a lot of code on the time line. It is a good practice to have all your code, when possible, written into the same place: a single frame or even an external .as file. The code shouldn’t be written inside the objects on the stage, try to put the entire code of the frame in one place so you can easily find it.

There are a few articles on the web on how to write ActionScript code, especially for AS2. You could spare some time to read Jen deHaan’s article on ActionScript 2.0 Best practices or Simon Wacker’s article about the methods in ActionScript 2.0. Simon Wacker gives us a great insight about how to correctly write methods and how to write JavaDoc-like comments for them.

Comment your code

If, by any chance, after a few months you’ll need to look over your code to improve it, reuse it or just reapply the algorithm you used and you didn’t write any notes on why and how did you write the code the way you did it, then you’ll spend enough time contemplating on that piece of code, wasting valuable time of your current project. You won’t be able to deliver your part of the work on time. You’ll have to spend extra time at work to try to finish it on time. If you won’t be able to deliver on time, maybe other parts of the project that depend on your part will be delivered late, which in the worst case spells as disaster for you, your team or even the entire company. At the best, you’ll get a bad review from your project manager or team leader (that’s not so good either). All this, because you couldn’t or wouldn’t take the time (just a few minutes) to write down a few notes on the algorithm that you just used.

If you need to write a lot of code, this could mean a lot of notes and, of course, increase the time you spend on your part of the project. However, I believe this to be a necessary evil (I’m talking about the increased production time not about the use of notes or comments). Project managers and programmers should take this into consideration when planning their work, because this could turn out to be a “life saver” in the near or far future. So, my advice to you is comment your code: describe everything you code or you believe it might be important to you or others who could have access to your piece of code. Describe the entire class you are creating, every parameter (or at least every parameter that has a more cryptic name), every method you write for your class, describe each parameter passed to that method and what that method would return. Also, you can write comments inside your methods, explain why or how did you use a certain algorithm. This could turn out to be a real time saver when you or another teammate need to reuse a piece of that code (which isn’t quite easy to understand) into another project you work on.

Discipline, discipline, discipline…

I know it’s easy to tell people how to organize their work or to read about it. But, by far, the greatest challenge is to actually keep yourself organized. For someone who wrote code in a chaotic way for quite a lot of time it will be very hard to change his/her habits. And trust me, this won’t happen over night. This requires a lot of discipline. Discipline to say no, when tempted to write the code very fast and without respecting any rules, just to have it done quickly. Discipline to write your code according to the rules you set. But, again, trust me when I say that after a while, you will see the benefits of this and you’ll be able to keep yourself organized without even thinking about that. This will a be habit that you’ll like to keep.