domingo, setembro 18, 2016

Coding Languages vs. Natural Languages: “Story of Your Life and Others” by Ted Chiang



Published 2010.

"You're used to thinking of refraction in terms of cause and effect: reaching the water's surface is the cause, and the change in direction is the effect. But Fermat's Principle sounds weird because it describes light's behavior in goal-oriented terms. It sounds like a commandment to a light beam: 'Thou shalt minimize or maximize the time taken to reach thy destination.' ... It's an old question in the philosophy of physics. People have been talking about it since Fermat first formulated it in the 1600's; Planck wrote volumes about it. The thing is, while the common formulation of physical laws is causal, a variational principle like Fermat's is purposive, almost teleological... let's say the goal of a ray of light is to take the fastest path. How does the light go about doing that? ... the light has to examine the possible paths and compute how long each one would take... And to do that, ... the ray of light has to know just where its destination is. If the destination were somewhere else, the fastest path would be different... And computing how long a given path takes also requires information about what lies along that path, like where the water's surface is... And the light ray has to know all that ahead of time, before it starts moving ... The light can't start traveling in any old direction and make course corrections later on, because the path resulting from such behavior wouldn't be the fastest possible one. The light has to do all its computations at the very beginning."

“When humans thought about physical laws, they preferred to work with them in their causal formulation. I could understand that: the physical attributes that humans found intuitive, like kinetic energy or acceleration, were all properties of an object at a given moment in time. And these were conducive to a chronological, causal interpretation of events: one moment growing out of another, causes and effects created a chain reaction that grew from past to future.' 'In contrast, the physical attributes that the heptapods found intuitive, like "action" or those other things defined by integrals, were meaningful only over a period of time. And these were conducive to a teleological interpretation of events: by viewing events over a period of time, one recognized that there was a requirement that had to be satisfied, a goal of minimizing or maximizing. And one had to know the initial and final states to meet that goal; one needed knowledge of the effects before the causes could be initiated.”

In “Story of Your Life” short-story


Are you familiar with the Sapir-Whorf hypothesis? Back in the day when I was in college I remember writing a paper on applying this language paradigm to coding. It was so long ago I don’t really remember what I wrote, but I still remember agreeing with the fact that coding could also be a fitting subject to the Sapir-Whorf wisdom… Thinking it over once again, and being a “more mature human being” (meaning: “being advanced in years”), I still think we can draw some parallels between natural and programming languages. For starters, the way both types of languages are built allow coders to adapt and shift their ways of thinking more fluidly as they learn new programming languages than as they learn new spoken languages. It is that diversity that allowed me to both grow individually as a programmer and further advanced my own tastes when it came to choosing my favourite programming languages. I think Sapir-Whorf is much more readily applied to coding, because the “language” is the reality. Within the formal system of the language, the concepts and entities I use (variables, functions, classes, modules, whatever) aren’t depicting the “real stuff” somewhere else, they are the real stuff. As I said, I’m no longer professionally active when it comes to coding, but the mental constructs regarding coding are still there. When I was reading “Story of Your Life” short-story, my thoughts kept coming back to the possibility of having Language Relativity applied to coding. When I was actively coding, it was always interesting (in a Sapir-Whorf sort of way), how the language changed the way I did code. At the time I was coding in n-languages (C/C++, Java, VB, etc.), meaning I was always hopping from one language to another. I remember a particular time when I had to shift from C++ to Lisp (I think) and this fact alone made me notice something that I hadn’t really noticed.

In Lisp, when I pulled something out into a separate function, this made the current function more self-contained, more one idea. In C++, I only had to pull something out into a separate function if I needed the same functionality in multiple places. Actually, it’s even worse than that in C++. For stuff that is less than six or so lines, I was able to maintain it in several functions. Or, if I was using some Literate Programming tool a la Knuth, I’d just use the same chunk of code in multiple places. The notable exception in C++ is when I want to use something as a loop conditional, I may have bothered to break it out into its own function:

while (incrementCounter( cntr, min, max, dimensions ) ) {
    // body of loop here
}
In C++ I can do something like this:
unsigned int choice = random() % length;
void* currentChoice = options[ choice ];
    // yes, I know I can memcpy(), but that's not as obvious
for ( unsigned int ii=choice+1; ii < length; ++ii ) {
    options[ ii-1 ] = options[ ii ];
}
--length;

Any Lisp coder worth his or her salt, would never consider keeping that code inline. He or she’d put it in another function. This is one of the things I meant when I said coding changes the way one thinks about programming stuff. Lisp and C++ are very different. Because of those differences, when I was coding in Lisp, I didn’t have to worry too much over trivialities like I did with C++ (e.g., argument lists, pre-declaring stuff in the header file with the same signature as that implementation file, should I need a method or a function, how many compilation units will I need to compile the program, etc.).

Can we apply the same principle to human languages? Chiang has never been one of mine favourite authors. That’s not a bad thing. Sometimes I just need something to have a writer move up a rung or two. My previous iterations with Chiang were not all that successful, but this story, and the way he intertwined it with the characters’ personal history just made my day. This a good example of superior SF. I don’t remember it winning any prizes, but maybe it did, and I’m just being mean…I’ve been told his style his Borgesian. I’m not sure I agree with that. If by “Borgesian” one means that elusive quality of having a distinct voice, then maybe Chiang is Borgesian. His style is so distinct that his name has become an adjective, "Borgesian". I apply the term Borgesian to stuff that plays with my perceptions of the day-to-day reality. Borges usually did this by thwarting my notions of time and space, obscuring the boundaries of fact, fiction, and philosophy, or fusing artistic invention with make-believe judgments. Other elements of the Borgesian style are subtler, and include a parsimony of language, a wide range of interests, and a dry, very dry humor. Borges is superb and inimitable. Is Chiang also superb and inimitable? Not sure.  What I know is that collection of stories just made think about stuff. This my favourite kind of SF.

Next to the breathtaking complexity implied by the idea of the Heptapod languages (A, spoken and B, written) themselves is the razor sharp characterisation of the linguist Dr. Louise Banks, in whose existence her daughter’s life is slyly reflected (and amplified). Truly a wonderfully deft combination of mirrors. A 5-star short story. Another collection vying to be one of the prime candidates to be placed in my 2016 best-of-the-best list.


SF = Speculative Fiction.

Sem comentários: