February 18, 2008

char vs varchar

I recently took a databases class here at my school, and this argument came up rather heatedly in the class.  The teacher really likes the idea of a char while a few students see no point in it and that varchar are a lot better.  This came up during the group's presentation to the class on how they were going to design their database.  It really got me thinking which one is better since they both had good arguments behind it.  First, why varchar?

The students' arguments were the fact that everyone in industry uses it now.  Not only that everyone uses varchar, it is very convenient to use varchar.  If you're sure that something is within a certain amount of characters, why not just use a varchar and not wasting diskspace?  Say, if you are creating a field for first names, why not just do a varchar(50)?  That way, if a person's name is only 3 characters, the varchar will contract to that size, then you wouldn't have to waste the other 47 bytes.  It seems that it would be pointless to use a char(50), since it will be padded until the 50th byte is filled with nothing.  What about the argument for the other side from the teacher's point of view?

 

His argument is totally on the side of the engineering process.  We know that many people want software development to be an engineering field, but there are so many aspects to it that makes it not truely engineering.  With this in mind, his point is that you need to know what you are putting inside of the database.  In other engineering fields, when a building is being built, the engineers know exactly how much weight the building can safely handle.  They know exactly how much concrete they need to keep something up, or they would know exactly what the outcome will be when they take certain steps during production.  That is fairly untrue in the software arena.

If you just slap a varchar into the database into every textfield, then where is the engineering process?  His argument is that this is the type of attitude that prevents a true establishment of the software engineering field.  If you do not care about the information and data you are using, there are no good reasons to make this into a software engineering field.

I personally find that there's merit to both arguments.  Although, I find that the teacher's argument is slightly stronger and seems more motivated than that of the students.  However, the students do have a strong backing of the industry…or do they?  I find myself using varchars for things that have a wider range of size variability while using char for something that has a lot less variability.  What are your thoughts?

Filed under Databases, Web Development by A.K.

Spread the Word!

Permalink Print Comment

Leave a Comment