### comment on

 Need Help??
Strong typing can be useful at runtime too. For instance, here's a semi strong typing thing implemented with objects.
```package Quantity;

...
;

sub new {
my \$proto = shift;
my \$quantity = shift;
my \$unit = shift;

bless {quantity => \$quantity, unit => \$unit},
ref(\$proto)||\$proto;
}

my \$self = shift;
my \$target = shift;

croak "Oi! You can't add \$\$self{unit}s to \$\$target{unit}s!"
unless \$\$self{unit} eq \$\$target{unit};
\$self->new(\$self->{quantity + \$target->{quantity},
\$self->{unit});
}
Ooh looky, useful strong typing:
```  \$a = Quantity->new(10, 'apple');
\$b = Quantity->new(20, 'orange');

...

\$c = \$a + \$b; # dies "Oi! you can't add apples to oranges!"
Note that the above example can be (and has been) useful extended to do dimensional analysis (is this a valid calculation), derived units (metres / seconds -> m/sec). Further possible extensions include upcasting (10 oranges + 20 apples = 30 fruit) and deferred calculations (10 EUR + 10 USD = new Sum(10 EUR, 10 USD), we'll worry about completing the calculation when we know what units we want the answer in, however 10 EUR * 10 USD = die "Meaningless calculation, don't be so bloody silly!")

Strong typing does have it's uses. And not just in the 'making the compiler go quickly' sense. Replacing your dimensionless numbers with strongly typed quantities can be a really powerful tool for helping to track down calculation errors (no more pesky mile/kilometre confusion whilst doing calculations in orbital mechanics mister rocket scientist...). And that's even before you take into account the possible benefits of deferred calculation that can be easily hung on the side of such a system.

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2020-10-26 19:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My favourite web site is:

Results (252 votes). Check out past polls.

Notices?