Skip to content

A few programming tips (Part3)

October 3, 2012

As I continue to code (a few points crossed my mind from yesterday), there were a few practices that I do when coding to make things a little easier and to keep things in order: –

1) If you are going to leave code half finished to complete the next day, its best not to leave it exactly half finished as I know its a pain to remember what you did the day before. Best thing to do is to write a comment //TODO: do something here, this allows you when searching through the code if your computer does close down or someone closes your application to refer back using the search on your code. Its a reminder basically!

2) If you make changes to one bit of code that is common to all pages, do make the changes for all, if not you may forget that this bit of code was added to all changes, hence why you can keep for changes using Source Control to make sure those changes are made.

3) If you don’t know the exact indices of your collection which you are looping through, use foreach (Item i in Collection), rather than for(int i=0; i < collection.Count; i++)
Also if you are using similar code where one uses the foreach statement, it is best to keep the foreach statement inside one condition, and not to surround the whole conditional checks like so:-

if (this condition)


foreach(item i in collection)


// Similar block of code

Using item i





//Similar block of code with slight changes


Don’t put the foreach inside the whole lot, it keeps code separate, and easier to maintain!


From → Uncategorized

Leave a Comment

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: