Thursday, May 21, 2015

34 tips for my 34th

1. Comment your code

                This is for several reasons. One of which, is that when you develop something today when the idea is fresh in your head and makes sense to you now, you may not remember everything a year from now when you decide to update the code or try to extract part of it for another project. So, comments can be little reminders about what this particular line of code does or the explanation and logic behind a series of steps and procedures or what the expected end result is supposed to be.

                Another use of commenting is very important in debugging problematic lines of code. Commenting can be used like when the police section off or rope off streets surrounding a protest march or when your Christmas tree lights don’t work and you try to figure out which bulb is causing the problem. By quarantining little by little with comments and working forwards and backwards to see if the whole program works with or without a line or several lines of code, you can finally find the culprit and get rid of it or figure out how to fix it.

2. Set time limits for debugging

                There is nothing more frustrating than trying to debug using the tip from above and never figuring out where the real problem is. Or you figure out what the problem is, but try every variation you can think of and nothing seems to fix the problem. I don’t want to suggest giving up because perseverance is an important aspect of programming, but sometimes you need a break. Breathe a little, do something else, come back a few hours later or the next day, and try to approach the situation with fresh eyes or a new mindset. And especially as a newbie, you may be approaching everything from the wrong end of the stick and it may be months or years from now until you actually discover the way the pros tackle it. So, don’t go completely crazy when debugging. Patience is important!

                Also, similar to the tip above, make sure you keep a log of bugs that you do fix or that are still pending to be fixed. This can help you stay focused when you come back later. You can add a comment near problematic code to remind you to fix it later and explain what the problem is and at the top of your code add a list of the dates you have worked on the code and what you added or fixed or deleted at that time. Your future self will thank you for keeping track of everything.

3. Use version numbers or explicit project titles when saving your projects

                The coding folder on my laptop is full of many many versions of the same project, but it becomes almost impossible to keep track of whether this is the most recent version or what the differences are between different versions. Hello_world1, Hello_world2, Hello_world_new, Hello_world_current. Save yourself the burden of opening and having to read several lines of code before realizing this is the old version that doesn’t work anymore or oh, this is the version I sent to Mike, but this isn’t the version currently on the blog. Again, comments at the top of your code can help, but you have to open the code to see those comments. I unfortunately have these long titles that explain what new features I have added. I currently have a timetracker that has _optionlist_localstorage_changecomments in the title. I know when looking at that title that the code currently includes an option list for the user to select activities, that it uses local storage to save user data, and that I finally added automatic updating of user data when any comments in the text boxes were changed. Also, including the date in the title can help you remember what is most recent aside from stating it in a comment about updates.

4. Stay motivated by working on your own ideas and projects

As a newbie I went through many programming tutorials oncodecademy.com and the little code snippets on w3schools.com and on millions of other websites that offer tutorials. They are great and wonderful for getting your foot in the door, but learning a dictionary or glossary of tips and tricks gets overwhelming if you aren’t focused on your own ideas. Don’t let your current skillset or programming limitations limit your ideas or your imagination. Stop yourself if you hear yourself saying, “Well, I don’t know how to do that yet, so I’d better just settle for doing it this way.” Be ambitious and push yourself and set big goals and you’ll be surprised how much more motivated you will be to learn and how much you can accomplish. With this in mind, I started going through tutorials like a buffet until I found the solutions for my ideas and my projects and I started to put little pieces of code into a bigger picture. Don’t let the tutorials stay theoretical and impersonal; you need to apply them to your projects and personalize them as soon as you can. Make them your own.

(Work in progress)




No comments:

Post a Comment