4 ms·
> The density of WTF's in this file is huge. Who can make sense of the following lines without any explanation? format([$M|T], {{_,M,_},_}=Dt, Acc) ->
by Deestan 18y ago
> The density of WTF's in this file is huge. Who can make sense of the following lines without any explanation?
format([$M|T], {{_,M,_},_}=Dt, Acc) ->
format(T, Dt, [smonth(M)|Acc]);
I assume you mean "Who with zero programming experience can make sense[...]". No argument there.
I know Erlang quite well, and personally I find the dh_date.erl code obvious and beautiful.
- swombat 18y agoNo, I mean who with zero Erlang programming experience. Over time, I have programmed in: BASIC, Pascal, C, C++, PHP, Perl, Java, Javascript, Ruby - and that's the languages I actually did stuff in. I am familiar with Python and Lisp as well. And yet this code is not obvious to me. Of course it's clear to someone who "knows Erlang quite well". But the Ruby code is clear to someone who "doesn't know Ruby at all", that's the difference I was pointing out.
- cx01 18y agoIf you have experience in Python then it's clear that the Ruby code won't be hard to understand, because those languages are similar. The Erlang code makes use of pattern-matching, which is mostly used in functional languages. So I think someone with experience in Haskell or O'Caml wouldn't have problems understanding the Erlang code.
- felixmar 18y agoRecursion also takes a while getting used to if you don't have a math background. Another issue is the frequent use of abbreviations in functional languages as seen in the Erlang example. A bit more verbosity in function and variable naming is useful to make the true abstractions more clear. On the other hand swombat's Ruby examples which use mapping, filtering etc. would be more elegant in many functional languages.
- eru 18y agoYes. You do not see naked recursion very often in, say, Haskell. Most of the time you use the built-in combinators or roll your own.
- jrockway 18y ago> Of course it's clear to someone who "knows Erlang quite well". But the Ruby code is clear to someone who "doesn't know Ruby at all", that's the difference I was pointing out. In the Ruby example, you name your identifiers "project", "all_users", "select", and "recent_joiners". Even without looking the code, it's pretty obvious what you are doing here -- selecting the users who have recently joined a project. The code doesn't matter, all the clarity comes from the identifiers. In the Erlang example, you use the identifiers M, T, smonth, Dt, and Acc. It is a bit harder to reason about, because there is no context and your variable names don't mean anything. (Although I can guess that M is a month and Dt is a date.) Any conclusions you draw from this about Ruby and Erlang are wrong -- the conclusions are about identifier naming. I could just as easily write Ruby that looks like: rj = p.users.find { |u| u.join_t(p) > now - 2592000 } Not as easy to read, is it?
- swombat 18y agoThat's not quite true. Identifiers are one thing, but language clarity helps too. For instance, in PHP you might have written: $recent_joiners = new Array(); foreach ($user in $project.all_users) { if ($project.join_date($user) > ONE_MONTH_AGO) { $recent_joiners.push($user); } } That's using fairly clear identifiers, but because of all the boilerplate code noise and the less clear language constructs, it looks less readable. Also, this requires a lot more specific meta-programming (like the ONE_MONTH_AGO constant), whereas the example I pasted uses vanilla Rails.
- jrockway 18y agoThis is a pain to type in (which is why you shouldn't use PHP), but it's not at all hard to read.