Friday, April 30, 2010

Most Common Bad Practices in Writing Code Loops

When writing applications, in any high level programming language, a sizable amount of the code written involve the loop construct. Walking through an array or hash, counting, incrementing values, decrementing values, listeners and a lot other functionality rely on the need to loop. And, loops are the most dangerous places of all basic programming language control structures. It directly affects reliability and performance as a whole. It is where you end up eating all CPU and memory resources alike. It is also where you might end up destroying an entire array of stored data. For this reason, that we should be very careful in choosing the right way to write code in this area.

Here are some of the most common code loop BAD practices that should be avoided. It should be useful for both programming beginners and professionals alike.

1. Nested Loops
2. Unyielding infinite loops or noops
3. Execution of methods from external resource objects in every iteration.
4. Retention of initialized object every iteration that's no longer needed.
5. Buffering huge data in-memory within the loop.
6. Looping infinitely within a child process thread.
7. Exiting a loop without releasing the memory buffers used by the loop.
8. Using an expensive method call within your loop expressions
  • Related Links Widget for Blogspot

No comments: