In this post I want to present the same task, solved four times in four different languages.
As in other similar posts before I beg to consider that I am not equally good in all four languages. Furthermore the size and elegance of each solution is strongly influenced by the choice of framework. I tried to choose the most popular framework for every language or that I have the most experience with.
The amount of lines, not considering comments, blanks or import statements, is fairly similar in all four cases. However there are a couple of differences, some suttle, some very aparent.
Notice how the Haskell solution is the only one that doesn’t require filtering the articles for empty values. This is silently handled by the monad implementation of the scraper, with Maybe behind the scenes.
From all four solutions the Python solution is the least satisfying for me. This is largely due to the fact that BeautifulSoup does not provide easy nesting of criteria as in the other solutions. This leads to a lot of manual error checking boilerplate (see all the ifs in extract). Even worse the list flattening list comprehension in the return statement, this will scale horribly with more complicated scraping demands. Python also has a jQuery like library, so using it probably would have let to similar code like in the Go version, which uses goquery, but I wanted to use BeautifulSoup because of its popularity within the Python community.