4 Ways to de-Junior Your Code


There's no shame in being a junior developer. I was one (and in plenty of technologies, I still am).

However, there are a few easy ways to make sure you don't unnecessarily look like one. Add these to your toolbelt.

4. Find and remove any return true or return false in your code

Whenever you have a return boolean, you'll almost always find it after an if-check of some kind. That if-check itself is necessarily checking a boolean.

Instead of returning true or false, just return the check you did to find it. E.g.:

if (num < 10) { return true } else { return false }

Can just become

return num < 10

Sometimes, you might run into a situation where a function returns a boolean sometimes, and a value other times (like an integer or string).

If this happens, this is a bad function and should be rewritten. You avoid this problem in typed languages like Rust, TypeScript, and Java. But in a language like JavaScript, it lets you cheat. Don't cheat.

3. Remove Print Statements

Unless you are building a logger, you don't want lingering print statements in your code. We all have the ubiquitous

console.log('here');
but it shouldn't be left in once you actually push your code.

2. Use a Linter

It doesn't matter so much what code style you commit to—but make it consistent.

I recommend ES Lint. This will find obvious issues with your code and point out solutions without accidentally breaking everything. Minimal setup, maximum headache-prevention.

1. Write Test Cases for Your App's Core Functions

A junior thinks writing tests is a headache. A senior realizes NOT having tests is a migraine.

If you manage the codebase and aren't just pushing code to it—and especially if you actually have users actively using your code—you will soon care about tests.

Tests are forgotten because they don't have immediate output as a new feature. However, if you actually want to have users that consistently use your creation, you need tests.

Tests are headache prevention. Tests preserve your brand's quality. Tests are a way to get ahead of problems before you have them, and help you think holistically about how your code might be used by end users.

If you don't know where to start with testing, write a unit test for a function. There are lots of open source testing software already out there: jest, mocha, chai, selenium, cypress. Take your pick.

Other Blogs