5 Programming Rules You Should Already Know
Posted by Fibonacci on August 9, 2008
It never hurts to remind you these small recipes aimed at programming novices:
1. Keep it simple. As in everything in life there are many ways to solve the same problem, but not like in life, in programming it is better to choose the simplest solution. The benefits of that are: code maintainability, easy to explain to others, easy to understand what you did with your code months ago.
2. Use design patterns. Design patterns can speed up the development process by providing tested, proven development paradigms. Effective software design requires considering issues that may not become visible until later in the implementation. Reusing design patterns helps to prevent subtle issues that can cause major problems, and it also improves code readability for coders and architects who are familiar with the patterns.
3. Comments. If in order to understand one’s code is has to be as green as Hulk, he probably didn’t follow the first tip. In many cases more self explanatory variables will do the trick and keep the code on a readable level. There are times when comments serve a purpose though. Algorithms can be hard to grasp and yet impossible to simplify through further abstractions. In such cases, you can explain yourself with comments. The rule of thumb for a good comment – it has to be an answer to “Why?” rather than “What?”.
4. High cohesion and Low coupling. Assign responsibility so that coupling remains low and cohesion high. Coupling is a measure of how strongly one element is connected to, has knowledge of, or relies on other elements. An element with low (or weak) coupling is not dependent on too many other elements. Cohesion is a measure of how strictly related and focused the responsibilities of an element are. An element with highly related responsibilities and which does not do a tremendous amount of work has high cohesion.
5. Don’t write deeply nested code. Nested code is code containing case/if/receive statements within other case/if/receive statements. It is bad programming style to write deeply nested code – the code has a tendency to drift across the page to the right and soon becomes unreadable. Try to limit most of your code to a maximum of two levels of indentation. This can be achieved by dividing the code into shorter functions.
I would like to hear from you about your experience and other tips.
See “Linux News” on your Google homepage
Salon1 said
Good post. From a Systems Engineering perspective, comments are often underratted and essential. I like the “why” emphasis you suggested. However, I believe a goal a programmer should always be striving for is to write their code such that comments are not neccessary (e.g., self-explanatory variable names, etc.). Another pet peave I have related to point 1 is programmers that try to see how much functionality they can put in a single line or statement as a demonstration of their ability. This also makes it hard to debug and very hard to modify. I would rather see a single simple straight forward execution per line.
Michael Tim said
I love your site!
_____________________
Experiencing a slow PC recently? Fix it now!
5 programming rules @ Adrian Nițescu said
[...] found on a website 5 programming rules, which I share with [...]
TrustedGenerics said
I would actually go with salon1 here… comments are important in a major project
Aceite de Rosas Damascenas said
Once even more studying any piece of writing, and additionally dealing with it again having my friend, I have hit in to the suitable final result that your chosen feeling is undoubtedly, in actual fact, incorrect. Rose bushes, a projects anyone submitted in an individual’s textual content, are the most beneficial projects on the planet. Maybe you’ve received all roses actually that you saw, perhaps you have had smelled some Went up by, or simply smelled came about in Bulgaria. Zero! I did not view you own! Well listen, because you never have, don’t have fun them.
que es el acne said
Wow, amazing blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your website is magnificent, let alone the content! que es el acne
Angkor said
ytEGKUuJ Buy Ambien
Richard Taverner said
1 comment for line no even space untill comments and comments…. Your comment about something, i suggest too be it more long as possible Ur1: hxxp://yourwebsitecom (don’t even use the stadard format or you will be detected from anti-spam)
nosfer323 said
nice one
Willian Benko said
That is a great article!
Joevann Dattes said
Hi thanks for information ,actually I’m looking for this information I’m facing some problem related to this matter.
bundesliga stream said
cheersy, I totally love this blog and I only wanna say thank you for this website
Chung Adickes said
Very good blog! Do you have any suggestions for aspiring writers? I’m planning to start my own site soon but I’m a little lost on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There are so many choices out there that I’m totally overwhelmed .. Any ideas? Thank you!
Enalydayles said
Hey great article man it helped me a lot !
Multiple Streams of Income said
I wanted to post you that tiny remark to say thanks a lot over again just for the nice secrets you have featured in this case. It was really seriously open-handed with you to grant publicly just what many individuals might have offered for an ebook to generate some dough for themselves, mostly now that you might have tried it in case you desired. These secrets as well served to be a good way to fully grasp that other people online have the identical fervor much like my personal own to know the truth more regarding this matter.
upcoming mmorpgs said
I really need to look into this more, thanks for article.
http://daily-portal.com/ said
Title…
This is my Excerpt…
Ebo Ndut said
Ebo Ndut What would happen if he only sucked a few drops for example? What about if he was thirsty and drank a whole pint? Would Dracula die or would he be saved? How much blood would it take to turn Dracula into a little angel?…
in Bram Stoker’s Dracula? If you’re not gonna help then don’t bother… I didn’t finish the book in time and I have an essay to write now. Thanks so much for your help
…
adesotiastyok said
http://184.154.132.242/~coltsdig/index.php?action=profile;u=73003
Brersqueelp said
all gooooooooooooooooood
my spirit animal said
Thanks for giving your ideas listed here. The other thing is that each time a problem appears with a personal computer motherboard, people today should not consider the risk regarding repairing this themselves because if it is not done correctly it can lead to permanent damage to all the laptop. It is almost always safe just to approach a dealer of that laptop for your repair of motherboard. They’ve technicians that have an competence in dealing with laptop computer motherboard troubles and can carry out the right analysis and carry out repairs.
articlesblog said
Finally I Have found the necessary info! Even the Ukrainian students prefer to read the blogs, based on WordPress, because it opens the mobile opportunities. Though while the reading this post in Opera mobile I have noticed that the blog structure was not strict as from PC it is � please check !
articlesblog said
Lviv (Ukraine), students want to read your blog – it helps to smile when we are in college study trip through the pages of the blog ! The only question – is the graphics … is not so vivid mobile gadgets
Auto Approved Scrapebox Link said
Great goods from you, man. 5 Programming Rules You Should Already Know Lists I have understand your stuff previous to and you’re just too magnificent. I actually like what you’ve acquired here, certainly like what you are saying and the way in which you say it. You make it enjoyable and you still take care of to keep it smart. I can’t wait to read far more from you. This is really a great 5 Programming Rules You Should Already Know Lists informations.
Load Central Philippines said
http://loadcentralph.net – Your 1-stop reloading station. Buying eload has not been this easy!
Homemade Herbal Lotion, Herbal Lotion, Homemade Lotion said
5 Programming Rules You Should Already Know Lists I was recommended this website by my cousin. I’m not sure whether this post is written by him as nobody else know such detailed about my trouble. You are amazing! Thanks! your article about 5 Programming Rules You Should Already Know Lists Best Regards Nick Rolf
Tom "wieszak na torebkę" Kal said
Hi, I visited yor article in SEO reason, I confess, but I found quite interesting content. Thanks a lot !