loading...

re: Haskell/Python/Go web scraper comparison completed VIEW POST

FULL DISCUSSION
 

I find lines to be far less relevant than characters when comparing the lengths of programs written in different languages/styles.

Haskell Go Python
As Written 2199 1621 1235
Strip Comments and Imports 1535 1402 1088
Strip Blank Lines and Indentation 1395 1257 1016

There's not a huge difference here, but this comparison is less favorable to Haskell than the line count.

Some metrics that are actually interesting to me when comparing implementations are:

  • How long did each take to write initially?
  • How correct were they after the initial implementation?
  • How long did it take to debug until they worked correctly?
  • How much time would it take to explain to a new dev with no experience in the language?
  • How long would it take to review a change by that new dev and feel confident in its correctness?
 

You make a good point. I neglected the importance of line length.

I think a lot of the reason my Haskell has such long lines is that the workarounds that purify non-pure things tend to involve a lot of helpers like runReq and defaultHttpConfig, which don't add as much semantic complexity as an equivalent increase in characters would normally suggest.

I'd say one of the reasons I value line count is that it affects how much code (semantically) I can fit on the screen at once, which is a big factor in how easily I can read and maintain it. Counting by characters also makes it seem better to use very short variable names, which can hurt readability as much as verbosity can, whereas if you count by lines, identifier length isn't a factor (unless it makes you wrap).

Though I have to say that for most of the metrics you mention, Haskell would be disadvantaged just because it's difficult to learn and I'm not a master of it yet. Writing the Haskell version took me a couple hours, but a more seasoned Haskeller could surely have written it as fast as I wrote the others. And I of course spent a few hours just struggling with Haskell package management (I do every time I touch Haskell for anything). As far as writing time, the time to find libraries and read documentation on ones I wasn't already familiar with was also a big factor for both Haskell and Go.

Line count (or character count) on the other hand is less dependent on how experienced I am with the language.

As for the last metric, though, I think Haskell would win on that even despite my lesser experience because it encodes the most information into the type system. With Python I'd have to do the most testing, with Go I'd have to worry about nil and pointers and other gotchas, and with Haskell, if it type checks, I can almost be certain it works.

Code of Conduct Report abuse