DEV Community

ProgrammerMoney.com
ProgrammerMoney.com

Posted on • Updated on

How to INSTANTLY write better code?

There is one trick you can start applying today and you will immediately appear like a better programmer.

And not just "appear to be", but actually be a better programmer.

The best part is - you don't even have to learn anything new.

You don't have to do anything hard.

BUT

You do need to put a little more care into this one thing (more than you usually do).

So what is this "magical thing"?

It is function and variable naming.

And before you go "oh I already know that" - no you don't.

I worked with developers who have 2-3 years of experience and this is still a problem for a lot of them.

But why is naming such a big deal?

Because much more time is spent reading the code than it is writing it.

And whether you're being "too clever" or too lazy with your variable names - the result is the same: disaster.

Even if it's you reading it, after 2-3 months you will have no idea what was so clever (or funny) about it.

Better naming is literally the easiest hack you can do that will improve your code quality overnight!

Make your variable names as specific as possible and do not be afraid of longer variable names. (you are not in school anymore where every coding example had the variable "x")

Examples of good variable names:

  • getUsersFromStripe()
  • getActiveStripeUsers()

Examples of bad variable names:

  • getUsers()
    • which users?
  • fetchAll()
    • fetch what from where?

These almost seem OK but they're not specific enough. What if you're downloading both Stripe and PayPal user data? Or just one of them?

You would have to get inside the function and read what it does to find out.

Aside from wasting your time and energy, after a certain point, this becomes completely unsustainable.

So make sure proper naming is your top priority.

PRO TIP

If you find it extremely difficult to name your functions, maybe they're doing too many things.

Break them down into smaller logical pieces and you'll be surprised how much easier it is to name each of them.

Until next time,
Will
Creator of (FREE) AI For Finance Course

Top comments (0)