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

"Language X is a write-only language" seems to be code for "it doesn't look like C."

I've also heard Forth and Lisp described this way. And yet I find both readable since I have experience using them. I wonder if APL is similar: It's only unreadable to people who don't know the language. Well of course it is.



APL is different from Forth and Lisp, in that the 'write-only' reputation is supported by it's programmers.

Take the famous 'game of life' APL example:

``` life ← {⊃1 ⍵ ∨.∧ 3 4 = +/ +⌿ ¯1 0 1 ∘.⊖ ¯1 0 1 ⌽¨ ⊂⍵} ```

It's quite logical, when you walk through it.[0] But it's harder to read 'back to front', which is what code readability is about.

[0] https://www.youtube.com/watch?v=a9xAKttWgP4


I would also recommend Conor Hoekstra's version of that video for a bit more explanation:

https://www.youtube.com/watch?v=pMslgySQ8nc&t=45s&ab_channel...

And he even shows how you can animate it in the editor window.


I can say confidently I couldn’t figure out what a line of APL code did 2 hours after writing it myself. I had to write comments at almost 5:1 ratio.

In other languages it’s easier to communicate “why” you are doing something, while in APL it’s the “how” that’s easiest.


C isn't very readable either which is why commenting is encouraged. But the Obfuscated C Contest is a competition whereas APL is literally the punchline for illegibility.


As I asked in another thread about APL readability few weeks ago[1], would you be surprised to learn this is valid Dyalog APL?

    result←findMax data

    max←0
    :For i :In data
        :If i>max
            max←i
        :EndIf
    :EndFor

    result←max
then

          findMax 5 1 2 3 5 6 3 1
 
    6
Writing it more neatly as findMax←⌈/ isn't mandatory anymore than `reduce(max, numbers)` is mandatory in Python.

[1] https://news.ycombinator.com/item?id=28092097


The terseness of “vintage” APL is what makes it hard to read and reason about. This example highlights how a little less terse code can be much more readable.

But I remember what confused me the most was trying not to use loops to sum arrays and using vector ops like +/A


I'm not surprised at all. Good/bad, un/readable code can be produced in any language. Ruby fans crowed about its beauty then created incomprehensible DSLs of awkward Yoda code. But norms and values do differ between language communities, and APL is not exactly noted for a strict emphasis on readability.


As one who took APL as an "introduction to programming" course in college: APL practically encouraged unreadable implementations. Students would literally and frequently challenge others with "what does this program do?" with the intent of eliciting "I have no idea, it's unreadable."

Forth and Lisp were odd, like a native English speaker learning Russian or Korean. APL is like writing a novel directly into encrypted form.


I think readability has as much to do with the language culture and the writer's taste as language features. I've definitely read Lisp code which is approaching unreadable due to excessive use of macros, for instance.




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

Search: