Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Griping about Typing

by maverick (Curate)
on Apr 19, 2002 at 14:47 UTC ( [id://160564] : note . print w/replies, xml ) Need Help??

in reply to Griping about Typing

Perhaps all things can peacefully co-exist when you apply the rule of 'right tool for the job'...

Pro - "Gimme my $foo!!!!"

How much memory is consumed by the standard $foo? Let's assume it's 20bytes (since I really don't know), so for my little

for (my $i=0; $i < 10; $i++) {
I'm wasting 19 bytes...assuming that $i could be a short.

Ram is cheap; processors are powerful. For my Perl app on a server, who cares that $foo took up 20 bytes? That trade is worth my time to not have to go through the reasoning process for a strong typed variable...

  • what am I gonna store? and integer.
  • only positives? ya.
  • what's the biggest value? 10
ah! unsigned short foo;

And those 19 wasted bytes are worth it to be able to stay focused on the larger goal.

Here's another problem with strong typing...what is the maximum value you can put in an unsigned int?

The correct answer is: depends. Depends on what kind of hardware you're using. ick! On a x86 and int is 4 bytes, or is it 2? I forget. It could be 3.5 on a SPARC for all I know...and that leads to major portability issues.

Con -- "Hey, where's the SIMM slot on this Palm III?"

Consider this scenerio. I've got my (slightly dusty) Palm III or some other such hand held device. Even if there is a Perl intepreter for it, I would be very hesitant to use it. Why? My Palm has 8meg of memory, for apps and run time execution. If I have $foo,$baz,$bar,$qux and they are all unsigned short counters of some sort, I've wasted 76 bytes. Can I afford to do that on a Palm that has 2 meg of free space? I don't think that I can.

I guess you can sum it up by saying, that your choice of tool must be driven by your requirements and environment. Sometimes strong typing is a must...sometimes it isn't and just gets in the way.

All things have their place. :)
/me sits in lotus position; "Ohhhhmmmmm...."

OmG! They killed tilly! You *bleep*!!