Cuidado com os tigres
June 15, 2008
Mais uma excelente talk do Steve Yegge.

Scala, now, is the tiger that’s going to kill Java. Because their [type-talisman] argument now has become a paradox, similar to the Paul Graham Blub Paradox thing, right? Because they’re like, “Well, we need static typing in order to engineer good systems. It’s simply not possible otherwise.”
The Scala people come in and they go: “Your type system suuuuuucks. It’s not sound. It’s not safe. It’s not complete. You’re casting your way around it. It doesn’t actually prevent this large class of bugs. How many times have you written
catch (NullPointerException x) ...in Java? Our type system doesn’t allow [things like] that.”Our type system does what you said your type system was doing.
So, therefore, you should be using it! ∴
And the Java people look at it and go: “Wehellll… (cough cough)… I mean, yeah, I mean… (*ahem*)” (running finger under collar, as if sweating profusely) They say, “Welllll… you know… it’s awfully… cummmmmbersome… I…”
“We can actually get around the problems in practice that you guys say your type system is solving through Good Engineering Practices.”
(laughter begins to grow)
HA!!! (I point accusingly at the audience, and there’s more laughter)
Yeah.
So Scala is creating a real problem for [Java's] static typing camp now. Because their last little bastion of why they’re using it, the whole tigers argument, they’re like, “Ah, well… we… we keep shotguns in our house.” [This is what they've been reduced to.]
OK? Yeeeeahhhh…
So back to dynamic languages!
Haskell $
April 14, 2008
Note: I know you will look away as soon as you see f x. Please don’t. You can see some interesting things in this post.
I was on the train with João and I was delighted to see my old friend $. I also miss composite (.) but $ is really the coolest shortcut Haskell gives a developer. So what is $?
It’s defined as:
f ($) x = f x
What does it does?
Prelude> let f x = map (succ) $ filter ( < 5 ) x Prelude> f [4,5,7] [5] Prelude> let f = zipWith ($) Prelude> f [succ,id] [5,4] [6,4]
Ulisses gave me the weird example. The first one was created by myself. In the first one we filter a list for numbers that are inferior to five and then we apply succ function to it. That is, we add one. :P Without $ we would have
Prelude> let f x = map (succ) (filter ( < 5 ) x) Prelude> f [4,5,7] [5]
So we got the parenthesis off and that always great to help make the code more readable. At least I simply love this symbol. Ulisses sample is quite more complex. First off all because it is in point-free/point-less notation. zipWith is a function that receives two lists and applies then function provided pair by pair. Like if I want to add [1,2,3] and [3,2,1] I can:
Prelude> zipWith (+) [1,2,3] [3,2,1] [4,4,4]
Ain’t it cool? So in this function we simply apply function that goes in the first list (id and succ) to the numbers in the second. Looks easy like this doesn’t it? ;) If it doesn’t just to read it and digest it and you’ll figure it out easily.
Let code the same samples in Ruby. Unfortunately zipWith (should I commit it? :P) doesn’t exist in ruby I’ll have to work with another sample using plain zip (it’s the same as zipWith (\a b -> [a]++[b])).
irb(main):001:0> [1,2,3].zip([3,2,1]) => [[1, 3], [2, 2], [3, 1]]
Well ruby handles this pretty well without $. We just need to do:
irb(main):002:0> [1,2,3].zip [3,2,1]
Because it’s object oriented this kind of issues don’t exist in Ruby. There are no expressions with large number of parenthesis as well. despite this I must agree that the Haskell version is far more readable than the ruby one:
irb(main):003:0> [4,5,7].select {
|i| i < 5
}.map { |i| i.succ }
=> [5]
But I still miss $.I miss coding in Haskell. It’s just plain fun.
I hope that I have helped you see why languages like Haskell and Scheme do matter, and others like Python and Ruby can be both useful and fun to work with!

Qual deve ser a linguagem de programação que serve de introdução ao seu curso superior de informática? Para mim a resposta não podia ser mais evidente: Haskell.
Pelo que sei no ISEP a primeira coisa que se aprende é Java, o que acho chocante. Afinal o paradigma de programação orientada aos objectos é vastíssimo e ensinar alguém a programar em Java sem estes conhecimentos por trás parece-me de uma irresponsabilidade incrível. Isto após uma reestruturação que ocorreu o ano passado! Pode-se alegar que o ISEP tenta formar profissionais que sejam absorvidos o mais rapidamente possível pelas empresas, que não se pretende formar investigadores. Mas, na minha opinião pessoal, existem coisas que são base para um licenciado em informática. Têm que conhecer os paradigmas de programação que existem pelas valias que eles oferecem e não pelo facto da sua sintaxe ser mais ou menos acessível. Como me parece evidente que qualquer informático deve saber estruturas de dados e algoritmia. São as ferramentas base com que trabalhamos diariamente e por muito que as empresas queiram monos lá a trabalhar a “chapar” código têm que existir algo que diferencie esse mono de um pedreiro. Senão para que o canudo?

Mas e porque Haskell?
- É uma linguagem funcional. Os problemas são entendidos como problemas matemáticos, o que permite aos alunos quebrar com a pre-formatada ideia que programar é deve ser seguindo o paradigma imperativo.
- A maneira de pensar nesta linguagem é diferente. Dijkstra disse que “It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”. Aposto que ele diria o oposto sobre Haskell. É difícil ensinar mal alunos que começam por aprender/gostar de Haskell.
- Ao aprender os vários paradigmas o aluno torna-se mais versátil. Começando por Haskell certamente que não vai ver todos os problemas de uma forma imperativa. Esta forma diferente de pensar vai-lhe permitir, no futuro, a mais valia de saber escolher o método mais apropriado para resolver um problema que se depare no futuro. Pode na altura não usar Haskell mas vai-se lembrar dos mecanismos que aprendeu e da forma, correcta, que aprendeu para resolver problemas.
- As outras vantagens do Haskell: Esquema de recursividade extremamente simples, Strongly Typed, Lazy Evaluation, Elegância do código.
Atrevo-me até a dizer que podem dizer mal do Haskell em tudo que quiserem menos que é mau como ferramenta de ensino. Para isso, é simplesmente divinal.
Se quiserem ver uma melhor resposta a esta pergunta Why Haskell podem ler este artigo no Good Math, Bad Math. E caso queiram espreitar um pouco de código podem visitar (e rir-se um bocado com) este The Evolution of a Haskell Programmer.
Ruby 1.9
November 29, 2007
De qualquer forma, até para tirar as ideias das aberrações que têm acontecido na minha universidade (mais uma vez), achei relevante o post que ele fez sobre a performance do Ruby 1.9. Aconselho a leitura. Fica, como resumo, os resultados obtido comparando a função de fibbonacci para os primeiros 36 números.
Ruby 1.8.6: 158.869s
Python 2.5.1: 31.507s
Ruby 1.9.0: 11.934s
DB2 Express C for Mac
September 25, 2007
I attended a conference by Vítor Rodrigues on DB2 pureXML approach on University of Minho last Wednesday. I was quite please to see that DB2 Express C was available for free and that, as far as I’m concerned, all features where available. You might not know this but most of my colleagues use Mac, so the main downfall for the presentation was the fact that no Mac version was available. Well, according to Antonio Cangiano that about to change. IBM is working on some beta version of DB2 for Mac, and it’s not just the client. It’s the whole thing. You can check for details here.
Another thing worthy of mention, the post Cangiano made about Haskell. It’s called Haskell Eye for the Ruby Guy and, in a certain way, represents that topic introduced here some days ago. Definitely worth the time you will spend reading it.
The ever growing software complexity requires the power of high level abstractions and the functional paradigm which helps us adopt a more declarative programming style where the side effects are marginalized.
Life on the rails
September 23, 2007
I found Ruby in a talk with one of my friends. We were talking about how a problem that can be solved in Haskell in one line of code, could take hundreds to do so in Java or C#. It was obvious that, for some specific problems, Haskell was simpler and adequate.
Want a sample? Code permutation with n levels in C.
perms xs 0 = [[]]
perms xs n = [ p : ps | p <- xs, ps <- perms xs (n - 1)]
And like this he introduced me to Ruby on Rails. I was very thrilled to see a language that is dynamic, object oriented and adequate for web developing. I immediately thought about learning it, I just love learning new languages.
Today I checking my feeds and found a post about seven reasons to switch back to PHP (from Ruby).
It seems Ruby is like Haskell: the code looks greats and promises a lot, but it still doesn’t get where imperative languages do. (I’m still going to learn it, I just can’t resist it)
For now I’m waiting for a language that joins all that is good from imperative, functional, logic and object oriented paradigms.
If you know such programming language leave it as a comment.
|
PHP $61,000 |
|
|
Ajax $76,000 |
|
|
Ruby $70,000 |
|
|
Java $77,000 |
|
|
C# $78,000 |
|
|
Haskell $52,000 |




