the lack of a native type system means that your classes and methods can’t be certain of the type of data they’re being passed, which forces you into a position of defensive programming
Well, in my view Perl does never force me into any position, but, depending on the task, defensive programming is recommended.
Using objects as a surrogate for a type system is just a thin layer. For safety, this only helps if the classes do the appropriate validations on object creation. For example, Venus::Number accepts any value, so my classes and methods still can't be certain of the type of data they're being passed:
use 5.028;
use warnings;
use Venus::Number;
use File::Temp;
my $n;
# These two come with warnings
say Venus::Number->new($n); # ''
say Venus::Number->new($n,$n); # 0
$n = 1;
say Venus::Number->new($n); # 1
$n = "abc";
say Venus::Number->new($n); # abc
$n = [3,2,1];
say Venus::Number->new($n); # ARRAY(0x...)
say Venus::Number->new($n)->abs; # 94653281131368
$n = File::Temp->new;
say Venus::Number->new($n); # /tmp/ER2Mi14BOz
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|