Dynamic Languages - Leitura de Código /ou: DLs e suas crenças

Posted: 14 de jan. de 2008 | . David Lojudice Sobrinho | tags:

Pesquisando sobre BDD (Behaviour-Driven Development), encontrei o Specter, um framework para .NET que utiliza Boo, uma Dynamic Languages (DL) criada por um brasileiro. O Specter é uma casca para o framework NUnit, pois, como está escrito no site deles:

Technologically this is similar to test driven development (TDD), however the shift in nomenclature removes the psychological barrier of writing "tests" for code that does not exist.
Ok. Eu até simpatizei com o tal Specter. Mas o que me deixou assustado é até onde a crença de que as DLs fazem com que o código fonte pareça com linguagem natural.

O pessoal do Specter acha que o código abaixo poderia ser lido e validado pelo usuário/cliente que está fazendo o requisito:


import Specter.Framework



import Bender



context "At Bender's bar":



_bar as duck #our subject is defined in the setup block below



setup:

subject _bar = Bender.MiniBar()



#one-liner shorthand

specify { _bar.DrinkOneBeer() }.Must.Not.Throw()



specify "If I drink 5 beers then I owe 5 bucks":

for i in range(5):

_bar.DrinkOneBeer()

_bar.Balance.Must.Equal(-5)



specify "If I drink more than ten beers then I get drunk":

for i in range(10):

_bar.DrinkOneBeer()

{ _bar.DrinkOneBeer() }.Must.Throw()


Você só tem uma oportunidade de entender esse código. Porque se não entender de primeira, seu usuário também não vai entender. E ele não tem que saber programar para entender.

Selecionei algumas páginas de referências sobre algumas DLs. Entre lá e veja quão intuitivo é o código. Mas novamente: Só é intuitiva se for de primeira lida. Assim como você lê este post. Se não for de primeira....

Ruby - http://www.ruby-lang.org/en/documentation/quickstart/3/

Groovy - http://groovy.codehaus.org/Differences+from+Python

Python - http://www.rexx.com/~dkuhlman/python_101/python_101.html

Boo - http://boo.codehaus.org/Language+Guide


Para quem também não engoliu direito essa historia de linguagem dinâmica, vale ler este post (longo, em inglês):
I thought I had become inured to it. And yet it still takes me by surprise whenever I come across further evidence of the near total absence of critical thinking in the software development arena. The notion of "evidence" seems to be considered naive and outdated by most programmers. It seems you can make just about any claim that you want and the programming public will eat it up and then later regurgitate it as if it were a self-evident truth. There appears to be no difference between truth and marketing. Research, reason and rationality have given way to bluster, bravado and bull.

0 comentários: