A recent meditation asked how to translate a piece of code into English. While the code in question was reasonably well explained in the comments, I feel that the desire behind the question needs to be addressed, in part because it tends to lead to myths about Perl being only suitable for obfuscation.

When we look at natural languages, we can find several instances where things don't translate well. A few examples:

Whenever people learn a new language, the ultimate goal is being able to think in that language. Translating in your head is a crutch for people who have only started learning. That's an important first step, of course, but one can't remain that way.

Likewise, I see no reason to criticize a language because you can't think of a way to translate code into your native language. In the long run, insisting on a direct English translation is likely to inhibit growth.


"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Replies are listed 'Best First'.
Re: On Translating Code
by GrandFather (Saint) on May 03, 2007 at 23:58 UTC

    I'm not sure the analogy is helpfull. It's a good analogy when comparing abilities of different programming languages, but much less helpful comparing a "natural" language with a "programming" language or even a "mathematical" language.

    The issue is more to do with different levels of expression - natural languages at one level, programming languages at another and mathematical languages at another level where the progression to each level represents a general increase in terseness. Sure, there are programming languages that attempt to look like natural languages and some programming languages are terse to the point of looking like mathematics (APL springs to mind), but generally there is a fairly clear distinction between the expressiveness per symbol for each of the levels.

    It's not clear to me though that everyone who is fluent in a programming language "thinks" in the language. When you (presuming Perl fluency here) encounter something like /wibble/ do you think "m//" or do you think "match"? It is clear that not all programming language use equivalent constructs and that your analogy applies exactly between programming languages. Consider the equivalent of "m//" in languages such as C or Pascal for example.

    The virtue in "translating" a chunk of code into a natural language is in being able to express and examine how the code works. If you can't do that then there are real problems for maintainers.

    In fact I'd consider programming languages much more akin to a form of implicit compression of ideas expressed in a natural language, rather than a translation. Sure, you can express concepts in a programming language that many people are not familiar with, but that's not due to the representation, it's because they are simply unfamiliar concepts. Writing a story to convey a concept is a different thing than decompressing an expression to a more verbose form. I think the issue with the meditation that stimulated this meditation was more to do with an understanding gap due to lack of suitable concepts than any issue with decompressing the Perl representation into an English representation - as can be seen in some of the OP's follow up questions to various of the replies (see Unusual coding arrangements in Perl).

    Direct translation of Perl (or other language of your choice) into English aids propagation of knowledge and assists growth in understanding the application of the many idioms used in the language. If you can't translate a technique into English you can't convey a it to anyone else who hasn't your understanding of the technique and you will inhibit their growth in understanding and proficiency.

    In summary, succinct does not have to mean obscure, but a lack of appropriate knowledge will make anything obscure. Translation is often essential to understanding - few non-natural languages facilitate bootstrapping understanding.


    DWIM is Perl's answer to Gödel
Re: On Translating Code
by halley (Prior) on May 04, 2007 at 13:35 UTC

    I'm not sure where you jumped from "expressing the intent of code in English" to "there's probably some Perl idioms that are as esoteric to translate as Japanese honorifics." There's a lot of functionally useful translation that can be used, and I don't know if the meditation you mentioned was concerned that such a translation had to be round-trip (in allowing the English version to be a unique equivalent for a given bit of Perl).

    As an aside, y'all is singular, all y'all is plural. ;)

    --
    [ e d @ h a l l e y . c c ]