|No such thing as a small change|
20 tips to avoid pitfalls while Programming Perlby greengaroo (Hermit)
|on Aug 30, 2012 at 16:59 UTC||Need Help??|
This post is a follow-up on my previous meditation entitled: 20 most important Perl Best Practices. Your replies in that thread made me realize that my list was wrong and I was not really achieving my goal. I meditated on it and I came up with new ideas.
Let me re-state the premise of my endeavour, my mission if you will: To create a list of 20 tips for Perl developers to avoid common pitfalls.
I came up with 15 so far. I would appreciate if you take a look at my new list and comment. Maybe 15 is enough, maybe 20 is too much. We'll see.
Here's the list:
1) Keep in mind software is a mean to an end (most of the time), it's not the product. The software must comply with the requirements and not the other way around. However, sometimes, requirements are questionable. So stick to the priorities AKA "most important features".
2) Keep in mind you will not be the last developper to look at your code. Make sure your successor will not hate you!
3) Keep it DRY! Don't Repeat Yourself! This leads to mistakes and bugs. Learn Object-Oriented programming if you have to!
4) Don't reinvent the wheel! Search on CPAN.org, Google, and ask your colleages about utility functions you may need. If you think about something, probably others thought about it before you.
5) Be consistent with the input and output of functions or methods, be consistent with the code style, with your naming convention, etc. In other words, be consistent.
6) Raise a flag, when creating if-elsif blocks without an else. Double-check that you don't need an else. In doubts put one that would provide an error message.
7) Be mindful when using internal variables such as $_, @_, $1, $2, etc. These variables could possibly lead to strange problems.
8) Don't pass big structures directly as an argument to a subroutine or method, use references instead. You never know how big your structure could become and it would use a lot of memory.
9) Leave a comment when doing something that is not obvious to understand.
10) If you choose to create unit test scripts to cover your code, maintain it!
11) Very long one-liners could be hard to read. Keep it short or avoid it for readability purpose.
12) Take space! It's free! You don't have to pack your code in small blocks, let it breathe, so others can appreciate reading it!
13) You are not alone! Do code reviews on your code and participate in others. This is an easy way for others to give you hints on what you are doing wrong as well as a good opportunity to see how other people are doing it.
14) Don't get stuck on a bug for too long! If you can't figure it out, try to follow these steps:
15) Visit PerlMonks.org daily!
Thank you all!