If you are new to the world of development, considering a degree in computer science with your eyes on web development read on code warrior, you’re in the right place, read on.
If you are new to the world of development, considering a degree in computer science with your eyes on web development, read on valiant code warrior, if not this is probably standard issue to you.
Bullet-proof code … kind of.
Do you write a function, run it and everything works exactly as intended 99% of the time? If the answer is yes, you’re a liar. Let me introduce you to my friend unit testing. Most people could benefit from at least a basic level of understanding about what unit testing is and how it can help you write better code.
What is unit testing?
Simply put, unit testing is testing small components of your code. It’s scientifically saying I passed X in, and I’m expecting Y out and Z definitely shouldn’t come out. If it does, the world will explode. This is assertion. You are asserting the result of the function and running your tests to see whether your assertions match up.
Okay, I admit it unit testing isn’t the silver bullet, it won’t solve world peace and it definitely won’t ensure your code is perfect but what it does mean is that you can edit, optimise and refactor your code safe in the knowledge that it still works (if your unit tests are good enough!).
This might not seem so important now, but imagine you need to change someone else’s function, you can see what’s happening, but you never really know what could be passed in and whether your additional changes are okay.
Unit testing gives a degree of confidence.
Debugging, the real way.
When you start out, you probably spend a lot of time writing your own code, reading your own code and debugging your own code. Unless you’re thinking of starting a solo venture this is probably not the way the world is going to be for you in the near future. You’re going to soon find yourself in a sea of code that you’ve never seen before and you’ll need to get acquainted fairly quickly.
‘console.log’ probably isn’t your best friend
So how do I get good at debugging?
If you find yourself dropping in some console logs (or even alert’s) to see what’s happening inside your code, try to break the habit and have a go at using some developer tools; most browsers have them, but the best introduction is probably in Chrome.
Have a peek at the Chrome Developer tools, they’re not as scary as they might seem at first … i promise. Start planting breakpoints in your code, or dropping in a ‘debugger;’ to pause the execution, check out the variables that are in your scope, and have a real look into the inner workings of your code. I can guarantee it will be enlightening and a lot more effective than mindlessly console logging.
A playground for your new skills
You are presented with some simple (at first) challenges in a number of languages that you complete to rank up. The more you rank up the harder the challenge. Even the most experienced developer will soon find themselves getting stretched by its library of challenges. But what is cool is that Code-wars has a test suite for each challenge so you can easily write and run tests.
What makes Code-wars so special?
Being a guitar player I know how easy it is to get into the habit of using what’s comfortable. I soon find myself noodling through the same scales, and hitting the same notes; this is the same for development. If you develop on your own all the time you’re probably resorting to the same utility functions and the same methods to solve problems. Code-wars helps you break the mould by letting you see how other developers approached the same problem. When you think your 5 line function is awesome, some crazy dude probably created some mind boggling regex and did it in 1 line.
Intrigued yet? Give it a go.
p.s don’t forget to use your debugger and write some tests.