Thursday, July 19, 2007

Object Oriented-ness

Object Oriented Programming is a religion! But to be a true follower, one must truly understand its whats and, most importantly, its whys. It is easy to follow something blindly; but to truly understand the reason behind it is the true path to bliss. Anyway, enough with the gibberish. Now I'll serve the techila.

Most design pattens stem from the following basic OOPs principles, which if remembered, simplify a coder's daily life to a great extent -

1. Encapsulate what varies

By encapsulating what varies, you can make your application more flexible and easy to change.

2. Code to an interface rather than an implementation

Coding to an interface makes your software easier to extend by reducing dependencies between different parts of your application. In simpler words, you can change the implementation of a particular module without having to change the rest.

3. Each class in your application should have only one reason to change

Cohesion measures the degree of connectivity among the elements of a single module, class or object. The higher the cohesion of your software, the more well-defined and related the responsibilities or each individual class in your application. Each class should have a very specific set of closely related actions it performs making it easy to change, without changing the other classes.

4. Classes are about behaviour and functionality

Books can be written about this (and I'm sure there are lots.) But just a short ending note here - OOP simplifies design by relating code to real life. Just as your brain isolates one physical object from another based on its unique attributes and behaviour, OOP enables us to cleanly break our big complex code into smaller manageable modules.

P.S.: Most of these principles are picked up from the highly recommended book - O'Reilly's Head First Object Oriented Analysis and Design.

Wednesday, July 18, 2007

Crazy compilers

"When you try to delete a derived class object through a base class pointer and the base class has a nonvirtual destructor, the results are undefined. That means compilers may generate code to do whatever they like: reformat your disk, send suggestive mail to your boss, fax source code to your competitors, whatever. (What often happens at runtime is that the derived class's destructor is never called.)"

-Scott Meyer in Effective C++


Moral of the Story :
The next time your email client's sent folder shows a funny email to your boss that you don't remember sending him, be sure to check your code for non-virtual destructors! :-)

Saturday, June 30, 2007

Importance of Custom Error Pages

Custom Error Pages are static/dynamic pages which a commercial site deploys in case of an error (404 - page not found error/ database error / etc). A site may be designed beautifully with colourful themes and user-friendly navigation tabs but it must be ensured that a page, like the one which follows, does not come up on screen in case the site breaks.

A custom error page would have been less embarrassing here for marvel.com

Taking the example of Microsoft's ASP.NET, displaying the custom error page 'error.html' is as easy as modifying the Application_Error event (which gets called in case of an unhandled error occurring in the application) in global.asax :


protected void Application_Error(object sender, EventArgs e)
{
   Response.Redirect("error.html");
}


Ofcourse, this is not the only way to implement custom errors in ASP.NET, but in my humble opinion, is the easiest. Also, error logging can be done by including the relevant logging code in the same event before the Redirect statement.

This would ensure that the look and feel of your site remains consistent, even at the time of a crucial error.

Tuesday, June 26, 2007

Blog 101 - Making your own blog

Since I spent a considerable amount of time making this blog, I thought why not share my experience and the wisdom gained along the way. So here is a step by step tutorial to making your own blog.

1. What is a blog and why should you have one?

A blog is your own public/private diary on the internet where you can share your thoughts and express yourself. Its like a newspaper article; actually its much better. Blogs are considered a great source of public opinion; be it for technical knowledge, restaurant reviews, personal rantings, and what not. And globalization means that you can be read the world over.
e
If you have anything you want to get off your chest, a blog is the perfect place to do so. Lets face it, how many of us get an opportunity to get something published in a newspaper?!

2. How do I make one of these so called blogs?

If you have loads of money and technical curiosity, you can buy some space on the internet and set up your blog there (in which case skip this point). But if the following words make you scratch your head - DNS, domain name, FTP, SQL - then you are better off registering yourself on one of the many free blog hosting websites on the internet and get blogging in a matter of minutes. Here are some I've tried myself :

a. Blogger - The website where this very blog is hosted. I personally found it the best free hosting site on the internet. Earlier versions of blogger lacked the ability to tag your posts but that shortcoming is long gone. The biggest advantage, perhaps, is the freedom over the blog template using CSS. The current interface of my blog could not have been achieved elsewhere.

b. LiveJournal - Pretty similar to blogger. This site does not provide too much creative control over the layout of your blog which made it a big no-no for me, but what it does offer is the ability to get automatic updates from your other LiveJournal blog buddies. And since the LiveJournal community is a pretty big one, this site is recommended if you are of those who don't want to manually mess around with the layout but just want to make buddies with your blog and easily keep track of them.

c. Wordpress - Perhaps the most popular commercial blog hosting service does offer free hosting too. They don't offer the freedom of Blogger or the network of bloggers like LiveJournal but what sets them apart is the ability to create non-blog-post pages like the "About Me" page.

The ones above are only 3 of the thousands of free hosting sites on the internet. These days almost every portal lets you have your own blog on their site.

3. What do I do next?

After choosing the hosting site, the next step would be to choose a URL of your blog. (Like I chose 'techilasunrise' - since I wanted to make a tech blog - on Blogger making the blog URL http://techilasunrise.blogspot.com) This sounds easy but since there could be millions of people who have already tried to choose your URL before you, you'll probably have to compromise somewhere. (another hosting site/variation to the existing URL/completely new URL)

When you've chosen the URL of your site, you'll probably be asked for the name of your blog and given the option to choose an existing template for it. Then thats it, you are done.

4. How do I get a unique look for my blog?

If you are like me, you would not be satisfied with the default template of your blog. Lets face it, I'm sure there are MANY bloggers out there who have chosen the same one. To give a little zing to your blog you may do the following :

a. Choose a nice header image for your blog :
Many templates come with an option to easily choose your own header image. That is the easiest method to make your blog look unique. You can crop one of own personal images to fit your blog or choose one from the internet (provided you are not infringing on any copyrights). If you want to upload an image on the internet to use as your header, I would recommend doing it on your own blog on any of the free image hosting sites on the internet such as Flickr. Personally, I used Google Pages to do so.

b. Change the color scheme :
Sometimes choosing the right color makes all the difference. For my own blog, since I decided to choose the name 'Techila Sunrise' which is similar to the tequila + orange juice cocktail 'Tequila Sunrise', I went with a predominantly orange color scheme.

Here is a little trick I applied. Given below is the color wheel :


As you can see, its named quite aptly. My blog uses the orange and blue colours freely. Another glance at the color wheel will make you realize that those 2 are located opposite each other. Such opposite located choice of colors is called the 'Complementary Color Scheme'. Try mixing the other such colors and you will realize that it works quite well. (By the way, colours have their own significance - Orange signifies enthusiasm, creativity and energy; whereas Blue represents intelligence; and Black signifies elegance.)

5. How to make people read your blog?

This is probably the hardest part, since there is no hard and fast rule for it but do remember "People are attracted to the presentation but it is the content which makes them stay". So, be creative and most importantly, be original.

Monday, June 25, 2007

Welcome

Hello and welcome to my blog.

My name is Nitin Sagar. I am a passout of IIT Bombay (Computer Science and Engineering, B.Tech., 2002-'06). I am currently employed with GlobalLogic, Noida, India where I have a designation of Associate Architect. The 2 previous statements (more specifically the year of passing out and the designation) are self-contradictory but then so is life. :)

Anyway, this blog is meant as a (future) public repository of my technical hoo haa. Keep coming by to see what I am currently ranting about.

P.S.: This blog is self-designed including the color schemes, graphics and the CSS template. Just one of the things I do. :)