Good coding habits
Good coding habits
I have been writing nodejs and front end for over 3 years. At some point — it all stops working. Code gets stupidly lengthy and multi branched. You want to fix a simple route to filter the data. You try to find the appropriate route where you can plug the new feature inside — and it becomes a mess. Because you did not give due thinking into writing it the first time, now it is not modular enough and any new feature is only going to make it difficult to manage.
All my projects have expired due to my bad coding habits. Only because I complicated real simple things.
For example
Forms never followed their natural submit. I always interrupted them using prevent defaults () in javascript.
Excessive ajax to make meaningless interactions.
Doing multiple things on a single html page.
Building front end before the backend.
Coding preceded with no thinking.
Mongoose using multiple functions under 1 statement to make myself look cool [ to no one ] : — e.g findOneAndUpdate with { upsert: true } option embedded.
If you are failing in building a proper functioning product — read this article carefully.
1 — Draw your plan
If you have an idea, or a multi billion dollar proposal, or your life depends on it. I would suggest WAIT. Absorb this idea. Let it settle in your head 2 to 3 days.
All websites are complicated and thorough planning makes these complicated things, Simple. For example, every time I built a product it needed a Sign Up functionality.
Sign Up page is the entry point where you get your earnings. It is meant to work properly for your product to churn properly.
Sign Up, is not alone. It needs a Sign in Form. And Sign in is not alone. It needs a forgot Password Form. And forgot Password, needs a method to send you 4 digits verification code. This is not it. You got to make a separate Premium portion — where people signing up should be able to pay you.
If you get to hitting keyboards out of the box, you get stuck and finally lose track of why you started it.
I strongly suggest, if you want to deliver a quality product, make a sober sign up system. That gets money into your account in the fewest possible clicks.
Draw your plan on a white blank paper. Write down the exact hierarchy of actions needed to build the system. Use good hand writing that is referable a month later.
Very few people have made a good sign up / in system. Facebook did it right and it blew up. Apple did it right, on there Macs. Google did it right on OAUTH [ Sign in with Google ] and finally managed to earn. Good platforms make you sign up right up, as you reach their landing page, in the fewest clicks and reward you with a system built on scalable architecture.
If you get sign in / up / payment methods right, you have completed 20 to 30 % of your product.
2 — Simple is the best approach
Do not make CRUD (Create, Read, Update and Delete) process difficult. Stick to CRUD methods to manage data in database.
Do not start writing the front end at the start. Design front end, but code back end first.
Keep the excitement alive. Make small achieveable milestones to cross everyday.
In today's hype, almost everyone is skipping the basic guidelines. Repeatedly compromising the quality and later developing a habit of writing bad code.
Coding is not a skill, if it is not written thoughtfully. It turns into a mess, which you do not want to see happening with your product in the future.
3 — Do not jumble up the File System
You must have seen a pile of files belonging to developers’ project directory. Each method falls into a separate file. Model Schemas go elsewhere. Configurations are pulled out in a separate file. And so much of baseline code — that could have fallen into 1 x file, shifts to a number of files.
This is wrong approach.
Multiple files cause excessive confusion. Specially, when you are an amateur or a novice developer.
Write everything in 1 file.
For example I am writing nodejs: —
My html files are “.hbs” files and they go at one place in “views” directory.
My backend file is one “index.js” file and it resides at only one place.
There is nothing that is out of my reach when I am handling backend. The images need a DELETE route? I search “image” and all of it is here right in front of me. Layered, beautifully placed with its neighbouring routes.
Repeatedly looking at same lines of codes, keeps things familiar. And slowly, the entire layout, wires itself to our natural way of thinking.
If a code breaks or a route malfunctions, I have only 1 file to fix. There are no back and forth jumps to find the bug. No getting familiar with the code first. And it is all now easy. Next cool addition, next middleware authentication or building a nice Cart, that works without bugs, becomes as clean as the rest of your back end.
Conclusion
Writing clean code, giving simple routes, doing one-thing-at-one-time approach and understanding before getting into building — are all things that is keeping writing code fun, for me.
If you do not love what you are building, you might find some customers but you won’t be able to maintain its quality.
Slowly, things will start breaking apart, and you will be wanting to give up. At that point — you will need to rewrite all the bad lines of code. You might dump existing code and restart.
I seriously wish, in my early days somebody could have lectured me on it, "it has to be simple and linear to Work". I would not have wasted past 3 years of building crazy stupid projects.
Be very conscious of your decisions while you are building it. Slowly you will build trust over your project and it will get easier to improve or refine. Embedding new features will become easier. And you will at once know; if your customers are asking too much or they indeed need it.
Non-Surah