Skip to content

A few more programming tips (lost count!)

November 9, 2012

Today, I noticed a few important things when programming especially when I am involving with lots of data being filtered and checked etc.

As I had been merging two different pages of code together to form a new set, I knew it was going to be taking a lot of time, so if you have two computers ideally you can check one page on one computer screen with your current computer screen, and you can then check line by line of the code changes and merging into a new page of code! It saved a bit of time. Also keep reference of where you are in the line of code you are altering otherwise you lose track!

In C# if you are using NHibernate, NHibernate won’t check at compile time of the data types when being queried so you go to make sure you are always passing in the correct data type, for instance I passed in a long, when on the database it is suppse to be short, make sure all parameters of the query are correct.

If you are looping through data, don’t use double looping unless you necessarily have to, and keep two seperate lists for storing the initial data, and the filtered data. I had been inclined to do double loop with everything I do, but sometimes it is easier to loop through one thing and then seperate the filtering on another loop. Will explain further.

Always use exception handling especially from what I have said, it saves a bit of time going through all the code on where it has gone wrong and it gives a meaningful error for the user or you may set an exception type error thrown back at you on the screen.

Just recently I found out that this doesn’t work: –

string date = DateTime.Today.Subtract(TimeSpan.FromDays(days)).ToString();

But this does?

string date = DateTime.Today.AddDays(-days).ToString();

Tell me why if you know the answer, the first one just gives todays date.

Ok gotto go!

Advertisements

From → Uncategorized

2 Comments
  1. Says don’t worry
    Erey think U be order

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: