Programming Lessons

After implementing a 2D registration scheme in a substantially long bash script,  a refreshment of  good programming style seems necessary:

1. If…else… is a pig, especially if the switch is passed as a function argument. If there is a lot of if-else with similar structure, it’s time to refactor the code.

2. Sloppy variable naming will eventually come back to haunt you. That’s why namespace is so important in big projects. If you can’t use find…replace-all for a variable, even if it’s protect in local scopes, time to consider redefine the variables and separate their meanings.

3. Always test driven, and there is no escape. Even if you cheap out initially, Murphy’s law will eventually bend you down to your knees. So why not do it from the outright.

4. Parallelize the function structures and logical flows of similar objects as much as possible, even if this may sometimes mean a couple of extra function calls at the beginning or end of the main units.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: