Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Order of words is not that relevant, in English I can say instead of the above:

"take each line of code [map ... xs] and replace it with [\x -> ...] a number of spaces equal to half the maximum line width [replicate (div (n - length x) 2) ' '] prepended to it [... + x]"

All languages have passive voice and other tools so you can make the order of words be whatever you'd want for customizable emphasis while keeping meaning the same.

Sure the order for arguments for `map` may not be the most intuitive, but that doesn't make things harder. See ReasonML for an example of functional programming with regular C-like syntax.

Now, if you want to see hard to read functional code, look into code abusing point free style (I'm not even sure there is a fine way to use it at all...), plus mind bending types (usually to satisfy some monadic style abstractions), plus over-currying stuff all over the place.

But the snippet above is only unreadable for people who stubbornly refuse to invest a couple hours of their time into learning a new notation for things! Heck, you can even translate it almost 1-to-1 to modern Javascript, or even add an extra function name and some more sensible variable names to make things more readable while keeping it functional:

    function alignCenter(lines) {
      let width = Math.max(...lines.map(ln => ln.length));
      let getPadding = len => ' '.repeat(Math.max(0, (width - len) / 2));
      return lines.map(ln => getPadding(ln.length) + ln);
    }
...the above is more like something I'd actually let pass code review in real life :)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: