Skip to content

A Few Programming Tips (Part 4)

October 5, 2012

Here are some more programming tips accumulated in thought over this week: –

1) I may of showed you how to do paging when you are going through pages in a DataTable, if you completely switch the data category on the code I have written, this line of code is an additional change. record = ((pageNumber – 1) * pageSize);

2) If you are writing realms of code, especially large if and else blocks, try and put “try catch” statements that capture most of the code that is likely to fail, it will help you in the long run.

3) If you have large blocks of duplicated code, I know it is best to reduce it, but if you can’t don’t try to manually check the duplicated code of the original, just copy and paste so you know if something goes wrong, you can change the original, and the duplicated code will behave the same! A clone as to speak!

4) Here is an important one which I may or may not of written. Apologies if I have already quoted this.

<?xml version=”1.0″ encoding=”utf-8″ ?>
<hibernate-mapping xmlns=”urn:nhibernate-mapping-2.2″
  <class name=”Project.Portal.Session.PortalSession” table=”Sessions”>
    <id name=”SessionID” column=”SessionID” type=”String”>
    <property name=”StartTime” type=”DateTime” />
    <property name=”EndTime” type=”DateTime” />
    <property name=”SessionLength” column=”SessionLength” type=”long” />

    <property name=”UserID” type=”long” />

    <many-to-one name=”Subscriber” class=”Project.Portal.Subscription.User”
             column=”UserID” lazy=”false” cascade=”none” />

If is a subset of my NHibernate mapping for storing session data, notice that I have referenced two different project paths for referencing different classes Project.Portal.Session.PortalSession for the parent tag, and Project.Portal.Subscription.User for the many to one tag, this is so far from what I know the only way to reference two different classes in the same relational mapping file.

5) From above, use the many to one mapping if you are to use joins in NHibernate!

6) If you made a lot of changes, try to check it all into source control, that way you know that it is securely kept in record!



From → Uncategorized

  1. Rich Day permalink

    Item 3 – couldn’t you just write a function and call that from two places? You should *never* have duplicated code anywhere.

    • Yes you are right, I was going to say that in my blog. You can have a function in a separate class, and call it.

      Was going to say for my scenario the code is in two seperate aspx pages, but you can create a class that has the function!

      Thanks for pointing it out!

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: