Keep Your Code Clean Kids

I have learned a valuable lesson this week. One that I probably should have seen coming, or maybe even learnt earlier... but no. The moment came when I was neck-deep in new code to add to multiple pages of a site. 


What am I talking about you ask?


Code. 


If you have ever had the unpleasant experience of dealing with the jumble of words, numbers and symbols that make up the beautiful web pages we all probably take for granted, you may know what I'm talking about. 


If you haven't, if you are a template, what-you-see-is-what-you-get or content management system user.. then stick with what you know and disregard everything I'm about to say. It probably won't make any sense. Actually it might not even make any sense to anyone, but who knows!



STAY ORGANIZED


Really, this is what I should have known months ago when I started adding and changing code around on the website. I backed up nothing and left no trace of where anything was, or is supposed to go. These were two big mistakes.


ALWAYS, ALWAYS, ALWAYS backup your template or webpage HTML before you mess with it.


Luckily for myself, I got away with having a few different parts of the page saved and an older version of the code from a month back to fall on when my project went south. I would advise however to keep updated copies of your website saved on your computer or cloud storage for reference and when you make mistakes. We all do.


USE COMMENTS!


I always wondered why I saw people leave little notes to themselves in their code. You know, that little green bit of text that says where something starts or ends. I thought, "What a waste of space!" Boy, was I wrong about that. This single little piece of advice would have saved me so much time, and is now saving me hours of laboring over lines and lines of code running together into mush.


<!-- your text goes here -->


Show yourself what you added, keep things labeled and noted- This way when you go back, you can easily add, change or remove something without having to look for it. 


BONUS ADVICE!


Ctrl-F
This command in most programs like Notepad ++ or CMS HTML editors will bring up a search field. Type in what you are looking for and it will highlight the words or phrases you've entered! Which can come in handy when you want to find one thing really quickly, to replace it or otherwise.




The moral of the story is, if you work with code, keep it clean. Don't learn the hard way and lose all your hard work! Research what you're doing before you do it, but if you're going to experiment have a backup plan! 


Thanks for reading.