Aliás, o que explode o meu cérebro é a frase <i>"These rules look complicated, but usually they will do what
you want."</i>, a respeito do "given/when", também em L<perlsyn> ;)<br clear="all"><br>ABS()<br><br>
<br><br><div class="gmail_quote">2011/2/14 Stanislaw Pusep <span dir="ltr"><<a href="mailto:creaktive@gmail.com">creaktive@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Ehehe, vou tentar contextualizar a minha lembrança... Tomo como exemplo a "tabela-verdade" do operador ~~ ("smart matching", L<perlsyn>):<br clear="all"><br><span style="font-family: courier new,monospace;"> $a $b Type of Match Implied Matching Code</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ====== ===== ===================== =============</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Any undef undefined !defined $a</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Any Object invokes ~~ overloading on $object, or dies</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Hash CodeRef sub truth for each key[1] !grep { !$b->($_) } keys %$a</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> Array CodeRef sub truth for each elt[1] !grep { !$b->($_) } @$a</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Any CodeRef scalar sub truth $b->($a)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Hash Hash hash keys identical (every key is found in both hashes)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> Array Hash hash slice existence grep { exists $b->{$_} } @$a</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Regex Hash hash key grep grep /$a/, keys %$b</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> undef Hash always false (undef can't be a key)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Any Hash hash entry existence exists $b->{$a}</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Hash Array hash slice existence grep { exists $a->{$_} } @$b</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> Array Array arrays are comparable[2]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Regex Array array grep grep /$a/, @$b</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> undef Array array contains undef grep !defined, @$b</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Any Array match against an array element[3]</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> grep $a ~~ $_, @$b</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> Hash Regex hash key grep grep /$b/, keys %$a</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Array Regex array grep grep /$b/, @$a</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> Any Regex pattern match $a =~ /$b/</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Object Any invokes ~~ overloading on $object, or falls back:</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> Any Num numeric equality $a == $b</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Num numish[4] numeric equality $a == $b</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> undef Any undefined !defined($b)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Any Any string equality $a eq $b</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 1 - empty hashes or arrays will match.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 2 - that is, each element smart-matches the element of same index in the</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> other array. [3]</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> 3 - If a circular reference is found, we fall back to referential equality.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> 4 - either a real number, or a string that looks like a number</span><br style="font-family: courier new,monospace;"><br>Olha, não sei quanto aos outros participantes da lista, mas eu simplesmente não consigo me ater a todos esses detalhes <br>
:(<br>Então nunca uso esse operador que me confunde (<b>PARA MIM</b>, é um "<i>Undefined Behavior</i>"), preferindo fazer "à moda antiga" (última coluna). Enfim, sou desses caras que enchem qqer operação de ()'s, tipo: ((($x / $y) - $z) > 0).<br>
Enfim, o que quero dizer é que o Perl tem um imenso <b>potencial</b> de produzir código cheio de <i>Pseudo-undefined Behavior</i>; por que ninguém tem obrigação de saber todas as faces de todos os operadores; isso sem contar as L<perlvar>.<div>
<div></div><div class="h5"><br>
<br>ABS()<br><br>
<br><br><div class="gmail_quote">2011/2/14 Blabos de Blebe <span dir="ltr"><<a href="mailto:blabos@gmail.com" target="_blank">blabos@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Oras, isso me lembra<br>
<br>
<a href="http://www.ioccc.org/1987/wall.c" target="_blank">http://www.ioccc.org/1987/wall.c</a><br>
<br>
Uma coisa é você usar isso em um golf, outra é usar em código de produção.<br>
<br>
Tem gente que empeteca o código com meia dúzia de regexp e se ahca 'O<br>
Hackerzão'.<br>
<br>
A maior parte dos bugs (com os quais estou lidando agora, por<br>
exemplo), teria sido evitada se fossem respeitados os padrões mínimos<br>
de boas práticas. Coisa que qualquer estagiário *deveria* sair da<br>
escolinha sabendo.<br>
<br>
Abraços<br>
<br>
2011/2/14 Stanislaw Pusep <<a href="mailto:creaktive@gmail.com" target="_blank">creaktive@gmail.com</a>>:<br>
<div><div></div><div>> Não sei pq, mas lembrei da seguinte sintaxe, compilável em Perl:<br>
><br>
> -f>@+?*<.-&'_:$#/%!<br>
><br>
> ABS()<br>
><br>
><br>
><br>
> 2011/2/14 Blabos de Blebe <<a href="mailto:blabos@gmail.com" target="_blank">blabos@gmail.com</a>><br>
>><br>
>> Bom dia,<br>
>><br>
>> Sem querer entrar em flames, ou no mérito da discussão, que tomo<br>
>> apenas como exemplo.<br>
>><br>
>> A thread abaixo é uma discussão que está acontecendo na principal<br>
>> lista de C++ brasileira, sobre undefined behavior.<br>
>><br>
>><br>
>> <a href="http://groups.google.com/group/ccppbrasil/browse_thread/thread/9b9a7be45917095e#" target="_blank">http://groups.google.com/group/ccppbrasil/browse_thread/thread/9b9a7be45917095e#</a><br>
>><br>
>> Notem como o Undefined behavior deste exemplo em particular pode ser<br>
>> resolvido com 'codificação elegante'. Ok, o assunto era outro e foi só<br>
>> um exemplo rápido, mas levantou a discussão que está acontecendo até<br>
>> agora.<br>
>><br>
>> A maioria dos 'Undefined Behaviors' das linguagens de programação que<br>
>> conheço (não são muitos) são casos específicos, incomuns, bem<br>
>> documentados, bem avisados, normalmente abertos por 'depender da<br>
>> implementação' e invocados por código porco de programadores meia-boca<br>
>> (não que este caso de *exemplo* seja um).<br>
>><br>
>> É claro, nenhuma linguagem é perfeita (exceto lisp), mas elas possuem<br>
>> especificações, mais abrangentes ou menos abrangentes. Por isso, não<br>
>> importa a linguagem, ou você se aprofunda e aprende, ou mais cedo ou<br>
>> mais tarte, vai acabar caindo em alguma dessas asrmadilhas.<br>
>><br>
>> Na minha opinião, C tem mais armadilhas e/ou hacks que precisam de um<br>
>> pouco mais de conhecimento de arquitetura de computadores para escapar<br>
>> do que Perl, enquanto Perl tem outros tipos de armadilhas.<br>
>><br>
>> Entenda armadilha aqui como "algo que eu imaginava de um jeito, mas<br>
>> aconteceu de outro", independente da expectativa ser razoável ou não.<br>
>><br>
>> O negócio é que como Perl é mais fácil de lidar do que C, você alcança<br>
>> as armadilhas de Perl mais cedo do que conseguiria caminhar em C para<br>
>> alcançar as suas, logo, Perl parece mais imprevisível.<br>
>><br>
>> Abraços<br>
>> =begin disclaimer<br>
>> Sao Paulo Perl Mongers: <a href="http://sao-paulo.pm.org/" target="_blank">http://sao-paulo.pm.org/</a><br>
>> SaoPaulo-pm mailing list: <a href="mailto:SaoPaulo-pm@pm.org" target="_blank">SaoPaulo-pm@pm.org</a><br>
>> L<<a href="http://mail.pm.org/mailman/listinfo/saopaulo-pm" target="_blank">http://mail.pm.org/mailman/listinfo/saopaulo-pm</a>><br>
>> =end disclaimer<br>
><br>
><br>
> =begin disclaimer<br>
> Sao Paulo Perl Mongers: <a href="http://sao-paulo.pm.org/" target="_blank">http://sao-paulo.pm.org/</a><br>
> SaoPaulo-pm mailing list: <a href="mailto:SaoPaulo-pm@pm.org" target="_blank">SaoPaulo-pm@pm.org</a><br>
> L<<a href="http://mail.pm.org/mailman/listinfo/saopaulo-pm" target="_blank">http://mail.pm.org/mailman/listinfo/saopaulo-pm</a>><br>
> =end disclaimer<br>
><br>
><br>
=begin disclaimer<br>
Sao Paulo Perl Mongers: <a href="http://sao-paulo.pm.org/" target="_blank">http://sao-paulo.pm.org/</a><br>
SaoPaulo-pm mailing list: <a href="mailto:SaoPaulo-pm@pm.org" target="_blank">SaoPaulo-pm@pm.org</a><br>
L<<a href="http://mail.pm.org/mailman/listinfo/saopaulo-pm" target="_blank">http://mail.pm.org/mailman/listinfo/saopaulo-pm</a>><br>
=end disclaimer<br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>