[SP-pm] SaoPaulo-pm Digest, Vol 71, Issue 49

Blabos de Blebe blabos at gmail.com
Fri Aug 20 06:44:25 PDT 2010


Bom dia,

Thiago, eu concordo com a sua idéia, mas discordo dos argumentos.

Ao compararmos a sintaxe de C e Perl vemos que a sintaxe não é nem
mais fácil, nem mais difícil. É idêntica. Bem como se compararmos com
PHP, java, entre outros. Considerem:

<code>
...
for (i = 0; i < 10; i++) {
    printf("Number: %d\n", i);
}
...
</code>

<code>
...
for ($i = 0; $i < 10; $i++) {
    printf("Number: %d\n", $i);
}
...
</code>

Esses dois trechos de código são sintaticamente idênticos. Vocês
poderiam me dizer quais são as duas linguagens usadas, olhando apenas
esse trecho? O primeiro que acertar as duas ganha uma cerveja no
próximo ES que eu for.

Vejam, não dá para comparar Perl e C por causa da sintaxe. São
idênticas. Isso não tem influência no seu estilo de código. É como
dizer que inglês é mais fácil que português porque não tem sigils,
digo, acentos...

Agora compare com os modos e tempos verbais por exemplo, com várias
formas de concordar o verbo. Vemos que há coisas que conseguimos
expressar em português, mas não em inglês.

Dizer que a sintaxe de Perl é um lixo, que é muito diferente de C, que
a de java é melhor ou que a sintaxe de C++ rulez, pra mim é besteira
mastigada. Pena que quem está chegando agora em programação engole
essas coisas.

Eu compararia por exemplo a sintaxe de Perl com a de Lisp, ou a de C
com a de prolog, se eu quisesse tirar alguma diferença. O resto é
masturbação.

Perl é mais legal (pra mim) do que C por causa das estruturas de dados
builtins, boa documentação, Encontros Sociais, opção de notação pós ou
pré fixada, reference counting, etc...

Se antes da variável vai um $ ou % não interessa, digito 3 caracteres
de Ctrl+SPACE...

Abraços


On Fri, Aug 20, 2010 at 10:03 AM,  <thiagoglauco em ticursos.net> wrote:
> Quoting Blabos de Blebe <blabos em gmail.com>:
>
>> Crianças, crianças, acalmem-se.
>>
>> Linguagem imperativa é quase tudo igual. Muda só o label do token...
>>
>> Exceto por python (eu acho), você pode tornar código em qualquer
>> linguagem tão obscuro quanto se queira, basta ser porco. E olha que
>> parafraseando um amigo meu, tem programador que é tão porco que não
>> serve nem pra torresmo. Mas estão aí fuçando bit...
>>
>  Eu achava que não estava brigando com ninguem!!!
>>
>>
>> 2010/8/20 Pinguim Azul <bluepenguin em gmail.com>:
>>>
>>> 2010/8/20 Thiago Glauco Sanchez <thiagoglauco em ticursos.net>:
>>>>
>>>> /*Duzentas linhas depois*/
>>>> sun = is_sun;
>>>> /*Imagina aqui, duzentas linhas de código depois... você vai pensar: sun
>>>> é
>>>> uma função de alguma biblioteca... ou é uma variável? */
>>>> /*E sim... isso compila!!*/
>>>
>>> Se você usar -Werror isso não compila não.
>>>
>>> O seu ponto é que Perl pode ser mais legível que C mal-escrito? Até
>>> aí, C é mais legível que Perl mal-escrito.
>
> Não... mesmo que o C bem escrito. Meus exemplos é não foram bons.
> Veja...
>
> Vou pegar um exemplo do Kernighan - C ANSI, pg 13.
>
> #include <stdio.h>
>
> main(){
>  int fahr;
>  for(fahr = 0; fahr <=300; fahr = fahr + 20){
>     printf("%3d %6.1f\n", fahr,(5.0/9.0) * (fahr - 32));
> }
> }
>
> OK... pretty easy!!!
>
> for (my $fahr = 0; $fahr <= 300; $fahr += 20){
>     printf "%3d %6.1f\n", $fahr, 5/9 * ($fahr - 32)
> }
>
> melhorando ambos:
>
> #include <stdio.h>
>
> main(){
>  int fahr;
>  for(fahr = 0; fahr <=300; fahr += 20) printf("%3d %6.1f\n", fahr,(5.0/9.0)
> * (fahr - 32));
> }
>
>
>
> for (my $fahr = 0; $fahr <= 300; $fahr += 20) printf "%3d %6.1f\n", $fahr,
> 5/9 * ($fahr - 32);
>
> A estrutura do Perl é semelhante a estrutura de idiomas reais, inclusive
> mais flexivel. Apenas este é o meu ponto. Não quero entrar no mérito que
> Perl é melhor que C ou vice-versa. São linguagens com paradigmas e histórias
> diferentes, criadas em contextos diferentes e ambas são importantes e
> necessárias no mundo Unix/Linux.
>
> Meu argumento é: O Perl não tem um sintaxe estranha, e sim uma sintaxe
> otimizada para compreensão humana e praticidade do programador.
>
> Algumas empresas usam o Perl como linguagem para prototipos antes de criar a
> versão final em C para testar a ideia e ver sua viabilidade comercial e
> depois criam uma versão final em C ou Java, por que é mais rápido criar
> programas em Perl do que em C ou Java e não sou apenas eu que penso assim.
>
> Permitam que extraia um pedaço de texto do livro "The art of unix
> programming" que seria uma opinião imparcial:
>
> 14.4.1 C
> Despite the memory-management problem, there are some application niches for
> which C is still king. Programs that require maximum speed, have real-time
> require-
> ments, or are tightly coupled to the OS kernel are good candidates for C.
> ...
>
> 14.4.4 Perl
> Perl is shell on steroids <<<DISCORDO DO AUTOR AQUI>>>. It was specifically
> designed to replace awk(1), and expanded
> to replace shell as the ?glue? for mixed-language script programming. It was
> first re-
> leased in 1987.
>    Perl?s strongest point is its extremely powerful built-in facilities for
> pattern-directed
> processing of textual, line-oriented data formats; it is unsurpassed at
> this. It also in-
> cludes far stronger data structures than shell, including dynamic arrays of
> mixed ele-
> ment types and a ?hash? or ?dictionary? type that supports convenient and
> fast lookup
> of name-value pairs.
>    Additionally, Perl includes a rather complete and well-thought-out
> internal binding
> of virtually the entire Unix API, drastically reducing the need for C and
> making
> it suitable for jobs like simple TCP/IP clients and even servers. Another
> strong
> advantage of Perl is that a large and vigorous open-source community has
> grown up around it. Its home on the net is the Comprehensive Perl Archive
> Network
> <http://www.cpan.org>. Dedicated Perl hackers have written hundreds of
> freely reusable Perl modules for many different programming tasks. These
> include
> everything from structure-walking of directory trees through X toolkits for
> GUI building, through excellent canned facilities for supporting HTTP robots
> and CGI
> programming.
> ...
>
>
>
> 14.4.4.1. A Small Perl Case Study: blq
>
> The blq script is a tool for querying block lists (lists of Internet sites
> that have been identified as habitual sources of unsolicited bulk email, aka
> spam). You can find current sources at the blq project page
> <http://www.unicom.com/sw/blq/>.
>
> blq is a good example of a small Perl script, illustrating both the
> strengths and weaknesses of the language. It makes intensive use of
> regular-expression matching. On the other hand, the Net::DNS Perl extension
> module it uses has to be conditionally included >>>> isso acontece com
> bibliotecas de qualquer linguagem <<<<, because it is not guaranteed to be
> present in any given Perl installation.
>
> blq is exceptionally clean and disciplined as Perl code goes, and I
> recommend it as an example of good style (the other Perl tools referenced
> from the blq project page are good examples as well). But parts of the code
> are unreadable unless you are familiar with very specific Perl idioms?the
> very first line of code, $0 =~ s!.*/!!;, is an example. While all languages
> have some of this kind of opacity, Perl has it worse than most.
>
> Tcl and Python are both good for small scripts of this type, but both lack
> the Perl convenience features for regular-expression matching that blq uses
> heavily; an implementation in either would have been reasonable, but
> probably less compact and expressive. An Emacs Lisp implementation would
> have been even faster to write and more compact than the Perl one, but
> probably painfully slow to use.
>
> 14.4.4.2. A Large Perl Case Study: keeper
>
> keeper is the tool used to file incoming packages and maintain both FTP and
> WWW index files for the huge Linux free-software archives at ibiblio. You
> can find sources and documentation in the search tools subdirectory of the
> ibiblio archive <http://www.ibiblio.org>.
>
> keeper is a good example of a medium-to-large interactive Perl application.
> The command-line interface is line-oriented and patterned after a
> specialized shell or directory editor; note the embedded help facilities.
> The working parts make heavy use of file and directory handling, pattern
> matching, and pattern-directed editing. Note the ease with which keeper
> generates Web pages and electronic-mail notifications from programmatic
> templates. Note also the use of a canned Perl module to automate walking
> various functions over directory trees.
>
> At about 3300 lines, this application is probably pushing the size and
> complexity limit of what one should attempt in a single Perl program.
> Nevertheless, most of it was written in a period of six days. In C, C++ or
> Java it would have taken a minimum of six weeks and been extremely difficult
> to debug or modify after the fact. It is way too large for pure Tcl. A
> Python version would probably be structurally cleaner, more readable, and
> more maintainable?but also more verbose (especially near the
> pattern-matching parts). An Emacs Lisp mode could readily do the job, but
> Emacs is not well suited for use over a telnet link that is often slowed to
> a crawl by server congestion....
>
>
>  Embora eu discorde da opinião do autor que Perl tenha uma sintaxe estranha,
> que é o que estou tentando provar aqui... é muito mais fácil e rápido
> programar em Perl por que a estrutura do Perl é mais próxima da estrutura de
> um idioma real. Possui prefixos que indicam os tipos de token (@ $ %). Outra
> coisa são os castings de tipo... a real pain in the nuts para iniciantes em
> programação... Para iniciantes é muito mais simples usar uma linguagem que
> faça isso automaticamente. Isto também aproxima mais a linguagem do nível
> humano. Do contrário desenvolvimento em Perl não seria tão mais rápido que
> em C ou Java!!!
>
>
>
>>>
>>> --
>>> Ricardo Bittencourt
>>> http://www.ricbit.com
>>> _______________________________________________
>>> SaoPaulo-pm mailing list
>>> SaoPaulo-pm em pm.org
>>> http://mail.pm.org/mailman/listinfo/saopaulo-pm
>>>
>> _______________________________________________
>> SaoPaulo-pm mailing list
>> SaoPaulo-pm em pm.org
>> http://mail.pm.org/mailman/listinfo/saopaulo-pm
>>
>
>
>
> _______________________________________________
> SaoPaulo-pm mailing list
> SaoPaulo-pm em pm.org
> http://mail.pm.org/mailman/listinfo/saopaulo-pm
>


More information about the SaoPaulo-pm mailing list