in reply to Datatypes. A Perl T-SQL comparison
Data conversions seem to be very easy in Perl. So why then do other languages struggle so much with them.Because they have different requirements. Perl's datatypes are flexible, but they come with a price. It takes longer to get to the value (more pointers to walk), and it consumes a lot of memory (IIRC, the overhead of a string that has never been used in numeric context is 24 bytes; that's 24 bytes more than the data it's holding, it's even more if the string has been used in numeric context). It's also easier to get the 'wrong' typed value in them.
T-SQL is a language geared to query databases. A VARCHAR takes more space than an INT (except perhaps very small VARCHARs, because it needs to record the size somewhere. An INT takes 4 bytes (or 8, but a fixed amount) - nothing more, nothing less. An INT variable will only store an INT - no checking whether it's a number or a string (and hence, no bits needed to record this - or spending time figure out what it is). Database variables are lean: that way, you can pack more of them in a page, which needs your cache expires less often, which means you can access your data faster.
It also means you need less disk space (and no, disk space isn't cheap. Sure, it's cheap if you buy a disk for you PC to store your porn collection on - but it's not if you're using disk cabinets without single points of failure), and hence, less tapes.
There are pick-up trucks, and there sports cars, and there are tiny fuel economical cars. There's a market for all of them. It's the same with variables.
|
|---|