How to write clean & efficient code
Sounds nice but hard, right? Clean? Efficient? But is it as hard as it sounds?
No. It’s NOT! So simple. There are just few routine rules one must follow. Are people writing so good software smarter or wiser than you? Hell NO! They just follow the rules!
Lets take a look.
Do not repeat yourself.It’s the most common mistake one can do before realizing the usage of a variable. Variables can prevent you from repeating your self. The moment that you catch your self writing a statement for the second time, stop right there and wrap that statement on a variable. Then call it everywhere you like.
Variables are just the root of the tree.You could even catch yourself repeating a procedure again and again. The moment you do wrap that procedure on a function. And the moment you catch your self repeating a sequence of procedures wrap that on an object. Then think about how you can extend those objects to create more complicated structures of your procedures.
Be aware of what you’re writing.
Keep it stupid simple. I love watching blogs of big web platforms who are exposing a lot of their how and why to the web. A lot of times i can see how these people doing certain stuff. And by 99% of the times i am being amazed of how simple those stuff are.
I am sure you all have been in the situation when you are starting to solve a problem and in the end you are up with a so much complex solution that you would say, “It can’t been done”. Well the problem it’s not that it can’t be done. It’s that you have come up with a really complex solution. There’s have to be another way.
Look back at your problem again. Make sure you’ve really understand it and when you are certain about it try again but simpler this time.
Now here come’s the most important one. Read the fucking manual dude. Not just browse it. Read it from the beginning to the end.
I am sure there a lot of useful answers over Quora and Stackoverflow but you can’t find a more accurate answer than the one on the original documentation the authors have wrote for you. If you’re writing PHP read the docs, if you’re authoring HTML read the specs and if you’re playing with Bootstrap take a look at the examples.
Be wise and know what you don’t know!
“I know that! Are we done yet?”
Well yeah that’s all i had to say it but no we are not done. There are a tons of other rules, principles and code mentors you should follow in order to get somewhere. Once you master those rules and learn how to apply them in your daily programming life and not only, you will rock!
Do not expect hot links or further reading references. Google them!