DEV Community

kazashim kuzasuwat
kazashim kuzasuwat

Posted on

3 Rules That Helped me write better Code

I have been coding for over 5 years now and over the years i have learnt a lot and still learning.
When i started my journey in software development ‘Coding’ i made mistakes which i have learnt from, and still learning. Now one of my focuses has been on reading and learning a lot. I reached a point where i have learnt so much that i realized how bad some of my early code is, So i tried to find ways to improve the. So i started researching on ways and ideas to help me improve my coding skills and how to write better code

Write code that is self explanatory

My code where never organised and i comment almost everywhere on my code because my code is hard to read and understand. So i use this guide to help me avoid over-reliance on comments and to put comments in their place and where they are necessary.
i made my code more expressive instead of depending on comment to functions, variable etc.
Example this is more clear

$sms_body = array(
    'api_key' => $api_key,
    'to' => $destination,
    'from' => $from,
    'sms' => $sms,
    'unicode' => $unicode,
);
Enter fullscreen mode Exit fullscreen mode

than this, which requires a comment to explain the code

// Create SMS Body for request
$sms = array(
    'api_key' => $api_key,
    'to' => $destination,
    'from' => $from,
    'sms' => $sms,
    'unicode' => $unicode,
);

Enter fullscreen mode Exit fullscreen mode

dont just go overhead with long variable or function names either try to go for clarity and understanding.

Learn to collaborate

One major thing i came across is collaborating with other people on a shared code base. I am a fan of the open source. It took me some time to get used to it but it had the most impact on my effectiveness in writing better code.
Collaborating with others opened my mind to a whole world of learning especially on GitHub Opensource. I became better at writing better code by also contributing to other peoples work and seeing how others get to write there code and studding them.

Stick to the language or languages you are comfortable with.

There are many good Languages, PHP, Java, Python etc. Choose whichever you like best, and stick to it. Don’t confuse yourself with every new technology that comes around learn to grow and be better at what you already know.
Note: That dose not stop you from trying to understanding how other languages work. but find you base and stick to it.

Conclusion

This is not a perfect rule but its something that has helped me in becoming a better coder and I’ve never encountered a programmer who just doesn’t care. I am sure this few Rules will help someone staring out in the coding world.

Top comments (0)