9 Ninja Tips on How to Code Faster

INTRODUCTION

FAST AND PROBABLY FURIOUS

Welcome to a list of tips on how to code faster – By programmer, for programmers. Once upon a time, I was a slowpoke newbie code ninja, just like any other beginner trying to figure things out left and right. Thankfully, having an understanding boss was a good thing, and having time to pick the pace up is a privilege.

Sadly, I figure that not everyone has the same level of patience. Some people can be really pushy, and how do we become efficient programmers to meet such expectations? That is, how do we get more work done in a less amount of time. Read on to find out!

 

TECHNIQUES & KNOWLEDGE

When it comes to faster coding, I will narrow it down to just 2 things – Improving your coding techniques, and getting more knowledgeable with the programming language plus frameworks. Sadly, there is nothing we can do about the knowledge, since it will only come with time and experience. So in this guide, we will be touching on a couple of coding techniques instead.

 

1. EFFICIENT CODING – LESS IS MORE

C, Java, Javascript, Python, PHP, ASP – It does not matter which language you work with. In the many years of my career, I have seen my fair share of bad inefficient programming. Maybe a simple short example will illustrate this better:

Inefficient function
function join ($first) {
  $second = "hello";
  $third = "world";
  return $first . " " . $second . " " . $third;
}

 

 

Now, that may seem perfectly all right to the unskilled code ninjas. But to the veterans, that is just a load of overheads, and it can be compressed down into:

The efficient one
function join ($first) {
  return "$first hello world";
}

That is three lines of code cut down into one. To the smart alecks who are laughing and thinking that this is dumb – Think twice before you laugh. It is exactly all these tiny little details that people brush aside, which is not just in the variables. Consider all the useless classes, functions, hooks, callbacks, loops, events, and more that can be cut away.

It all adds up over time and volume. Sure thing, a couple of lines of code may not seem much. But just spending some time every day to review and optimize your code will have a snowball effect over time:

  • The performance of your scripts is increased.
  • You make your code simpler. Easier to understand, easier to work with.
  • Less code also means easier to debug, fewer chances of making mistakes.
  • Most importantly, you force yourself to code as efficiently and quickly as possible.

Let’s just say that cutting down on all the useless codes will save you 100 lines of code a day on average. That will be 36500 lines of code a year. Would you rather complete projects faster, make more money, rest more, or spend more time on creating more useless code?

 

 

2. RECYCLE YOUR CODE

While we are still on the topic of “less is more”, remember the good old school days where your lecturers preach “object-oriented programming” and “reusability”? Yep, this is also a part of efficient coding. That is, to create your own set of libraries and reusable code. Over the years of my career, I have written a thousand code fragments and created all sorts of things like:

  • Website layouts – Single column, double column, etc…
  • HTML widgets – Hidden sidebars, dialogue boxes, hamburger menus, AJAX with queue and loading screen, etc…
  • All sorts of classes – Database, email, pagination, etc…
  • All sorts of modules – Users, admin, products, shipping, orders, delivery, payment, etc…
  • Email templates.
  • System monitors and scheduled tasks.
  • Push Notifications.

The whole idea is to “package” as many codes that you write into libraries, then reuse them whenever you can. Why reinvent the wheel when you have already created one before? Over time, you will start to realize that programming becomes easier. Because you are simply doing “plug-and-play” with all your existing goodies.

 

3. ADOPT FRAMEWORKS & WIDGETS

So what should you do if you are just starting out? You don’t have a lot of experience, nor do you have your own collection of goodies? Thankfully these days, we have all sorts of frameworks in the world – Angular, React, jQuery, Bootstrap, Cake, Spring MVC, Django, so much more.

Just why would you want to code from scratch when things are already done? If a good framework can help to speed up your project, then use it. It is not just the frameworks that can help you to code faster. Do a search on the Internet, and on my favorite haunt, Github – You will find plenty of widgets for all kinds of programming languages.

 

 

4. PLAN, STRUCTURE & PROCESS

Raw programming speed is only the start, smart efficient planning is the way to go. Before you even start a project, always plan out the overall structure first.

  • Framework and overall structure of your project.
  • The libraries and functions you need to develop.
  • The database structure, if any.
  • More stuff – Maybe like the written contents, or even the pictures and videos that you need.

Please don’t think that the planning process is useless, and I am saying this out of my own experience. A well planned, well designed, well-executed project from the start will spare you from a world of pain. The more you prepare, the fewer surprises there will be. You will spend a lot less time trying to develop parts that have been missed out, or busy covering up for mistakes.

 

5. PROPER CODE FORMAT & INDENTATIONS

Some people just LOVE to code in “one chunk style”, without any indentations, without any line breaks:

Efficient but inhuman code
function addToCart(id){var data=new FormData();data.append('request','add');data.append('product_id',id);var xhr=new XMLHttpRequest();xhr.open('POST',"ajax-cart.php",!0);xhr.onload=function(){if(xhr.status==200){dialog.show("Item added to cart")}else{dialog.show("ERROR ADDING ITEM TO CART!");console.log(this.response)}};xhr.send(data)}unction addToCart(id){var data=new FormData();data.append('request','add');data.append('product_id',id;var xhr=new XMLHttpRequest();xhr.open('POST',"ajax-cart.php",!0);xhr.onload=function(){if(xhr.status==200){dialog.show("Item added to cart")}else{dialog.show("ERROR ADDING ITEM TO CART!");console.log(this.response)}};xhr.send(data)}

Yep, I get it, you are an Android in human skin, but what happens to the poor humans working on your code? What happens when you want to work on your old code, and there isn’t a single line of documentation?

 

 

We will have to spend more time reading through the code again, line-by-line, and that is a waste of time. There is no shame in adding comments and do proper formatting. It only helps others to understand your code faster, remind yourself of what a section of code does.

Human legible code
function addToCart(id) {
// addToCart() : add an item to the shopping cart
// PARAM id : product id

  // FORM DATA
  var data = new FormData();
  data.append('request', 'add');
  data.append('product_id', id);
 
  // AJAX SEND
  var xhr = new XMLHttpRequest();
  xhr.open('POST', "ajax-cart.php", true);
  // WHEN THE PROCESS IS COMPLETE
  xhr.onload = function() {
    if (xhr.status==200) {
      dialog.show("Item added to cart");
    } else {
      dialog.show("ERROR ADDING ITEM TO CART!");
      console.log(this.response);
    }
  };
  xhr.send(data);
}

Here is my usual code comment strategy:

  • Always describe what a class or function does.
  • Describe each required parameter or properties of an object.
  • What the function returns.
  • Try to organize the code into sections and describe each accordingly. For example, section A gets the data, section B sends the data to the server, section C displays the server response.
  • You can also leave “TO DO” notes, reminding yourself and others of what needs to be done instead of guessing.

 

6. ASK FOR HELP!

No one is perfect, and no one knows everything on this planet. Rather than spending a lot of time trying to solve things by yourself, it might be faster to just ask your colleagues for help. If not, here is a list of websites that you can fire questions at.

13 Websites To Get Help With Programming

 

7. CAPTAIN OBVIOUS TO THE RESCUE

Well, have are some obvious things that will obviously help speed up your programming… If you have not done these already.

  • Choose a good code editor – One that will help you to automatically complete code and highlight errors.
  • Keep the handy reference manual open – Not just for a beginner. Even this code ninja keeps a browser window open for searching things like “Javascript Web Audio API”.
  • A good keyboard – If you are getting finger cramps from typing on a f**ked up small keyboard, it is time to upgrade and get a decent one. Here is my list of recommended keyboards.

 

 

8. TOUCH-TYPING

Still need to look down at the keyboard while typing? Here is how we code ninjas speed type – By touch-typing with eyes closed.

 

9. IDENTIFY THE BOTTLENECK

Sometimes, it is not the coding that is slow. Out of my personal experience, I used to work in a bad environment… Where I am torn in between multiple projects, and always in meetings instead of doing actual programming work. So identify what is slowing you down:

  • Too much useless user input?
  • Spending too much time on meetings?
  • Don’t have a solid plan?
  • Spent too much time waiting for client approval?
  • Too much time on updating your bosses?
  • Fixing broken code instead of actual development?

Try to eliminate these bottlenecks, and give yourself more time for development.

 

 

EXTRA) THE BOTTOM LINE

“I choose a lazy person to do a hard job. Because a lazy person will find an easy way to do it.”

– Bill Gates

Yep. The bottom line of how to code faster is to be the laziest programmer in the world. 😆 Find ways to achieve best results with the least amount of code. Package everything into libraries and reuse them. Use the code that other people have created, plug-and-play with existing solutions, not program from scratch.

 

EXTRA) DON’T BEAT YOURSELF

There are just times where things will not go your way. For example, I once had an employer who expected me to know everything straight from the start. Just because I am a senior web developer. Their expectations were that I pick up a new programming language, 2 different frameworks, and their libraries all in a single month… While given very little guidance.

As you can guess, a code ninja is not some super evil genius who can learn how to make a nuclear missile overnight. That only happens in superhero movies. Let’s just say that I did not stay very long in that company, given the out-of-proportion expectations. Everyone has a different set of talents versus expectations. No need to beat yourself up when you land in the wrong place. Just move on, and find somewhere else that fits.

 

CLOSING

MORE SPEED, BUT KEEP QUALITY IN MIND.

While some speedy coding is good, but it is not always the best way to do things. Several companies that I have worked with before loved to push for faster programming and shorten the development time. Time is money now, right? But to me, that is just short-sighted.

As I have mentioned above, a well-designed system in the first place will save you more time and money in the long run. A rushed project often resulted in more missing pieces and bugs. You will probably end up spending more time and money on trying to fix the broken pieces instead. So if you are hard-pressed for time, do try to negotiate for more time instead – There is only so much a programmer can do within a fixed time frame.

Thank you for reading, and we have come to the end of this guide. I hope this has given you some ideas on how to speed up your coding. If you have more tips to share, please feel free to share them in the comments below. Good luck with your projects!

Leave a Comment

Your email address will not be published. Required fields are marked *