Please, tell me I am not the only who who acts this way,
- Step 1: Code is running on the first try. I am a genius.
- Step 2: Question everything. HOW did it run on the first try?
- Step 3: Realize there is a bug. Freak out.
- Step 4: Question your career choices.
- Step 5: Solved bug. I am stable genius.
All of this, of course, happens in a matter of minutes, an hour tops. So, along the way I’ve stocked up on my own set of Swiss knives to help the above crisis occur less often.
Comment Your Code
Bro, this might seem obvious, but it’s not. I’ve even heard people say that it is not necessary to comment your code, because “your code should be clear enough to understand without comments.” No. Please, comment your code for your own sake, for everyone else’s sake.
I mean you might be the smartest person out there, but it is just good practice to comment your code so that anyone that has to maintain it in the future knows what you did and why. It’s happened to me several times where I build something 6 months ago and I’m like “Crap, I was so smart back then how the hell did I figure that out?” Commenting my code has decreased this significantly.
Use Good Variable Names
Avoid vague names like arr1 = [ ] or var1 = [ ].
Use explicit names like, countIceCreamFlavors = [ ]. It will make your code look more professional and legible.
The only way to code faster and work better is to crash and burn and learn from crashing and burning. Explore projects in Kaggle or Code Fights. The more errors, different questions that need answers, etc, the more you’ll recognize common issues or ways to solve these errors/issues.
Set up a blog and make your own apps and projects. Work on projects that excite you. Looks good on a resume too.
The Internet is Your Friend
Don’t be afraid to ask questions. Ask the internet, ask a friend. No shame in that. Even the most experienced developers get stuck or forget how to do things. Nobody really remembers every single numpy module.
Keep Your Code Short
Avoid scripts with thousands of lines. Bundle things up in functions, modules or if you work in Python, write your own packages.
Tests, Tests, Tests
Make sure you have tests set for your script. I work mostly in data science and sometimes you can’t control what the data entry is going to be like. Oh, this column was supposed to have only string vales? Well, screw you, I will add strings, integers, floats, random shit. It happens. Be prepared, be proactive.
Speak Problems Out Loud
My husband taught me this one. As silly as this might sound, when you get a bug or you are trying to do a machine learning problem, etc, speak out the problem and how you’d solve it.
You’ve been working on a bug for more than 4 hours? Get up and walk around, get some fresh air, let your brain rest and then tackle the problem again with a fresh mind.
Accept You Will Never Know Everything
Many years ago, when I was getting my feet wet with programming, my dad told me “Aisha, the best programmers are not those who obsess on getting their code to work on the first try, the best programmers are those who when they get stuck can find ways to get unstuck.” Don’t obsess about having the greatest code or being the greatest programmer that has walked this planet, you will always have things to improve on and you will always have things to learn.
PS: This is a great book on how to be a better programmer.