How language gives your brain a break
newsoffice.mit.edu
newsoffice.mit.edu
if condition:
#...a lot of code...
value = process()
return value
else:
#...return error information (e.g. in a web app)
return error_information
I always try to write something like this instead if not condition:
return error_information
#...a lot of code...
value = process()
return value
This make reading and understanding the code much easier since things that belong together are close together. This seems trivial but there is a lot of code that is written like the first block and therefore harder to understand. Sometimes, small things can make a large difference.That said, I am probably a bit over-sensitive to this kind of problem as a German, since we also have the habit of holding back the vital information in a sentence until the very last word.
This advice is especially helpful when coding complex conditionals in business logic. (but small enough so you don't need/want a generic rules engine and rules DSL for that.)
dog.bite(man)
or
bite(dog, man)
Another one is the Liskov substitution principle and hyponym substitution. Or polymorphism and word sense disambiguation. There's also a scope thing with co-reference resolution and global variables.
To the follow-up commenters discussing OOP syntax versus function-orientation, I always refer to the monkey quote, which seems relevant here:
The problem with object-oriented languages is they've got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle. - Joe Armstrong
for (init; test; increment)
body-statement
and their ilk. Though the evaluation is out of order, (test, body-statement then increment), certain related things are kept together.It also explains why infix notations (and 2D math notation) are effective: they physically clump semantically near things.
Postfix notations with no parentheses are absolutely the worst; you don't know what goes with what at a glance:
1 2 + 3 4 + 5 6 + * 7 8 / - *
If my eyes land on, say, the inner * , it's not immediately clear what the left operand is.Prefix with parenthesization lets us fold and indent the darn thing for a 2D visualization:
(* (+ 1 2) (- (* (+ 3 4) (+ 5 6)) (/ 7 8)))
^__ orig. distance__^
The (- ...) expression jumps down and gets indented. Thus it is visually lined up with its sibling, and near the connecting operator: (* (+ 1 2)
(- (* (+ 3 4) (+ 5 6)) (/ 7 8)))
We recursively apply this: (* (+ 1 2)
(- (* (+ 3 4)
(+ 5 6))
(/ 7 8)))
(* (+ 1 2)
(- (* <---
... reduced distance, and visual alignment
(/ <--- * + 1 2
- * + 3 4
+ 5 6
/ 7 8
Postfix can be indented similarly 1 2 +
3 4 +
5 6 + *
7 8 / - *
Or parentheses less infix 1+2
* 3+4
* 5+6
- 7/8(1) John threw out the old trash sitting in the kitchen. (2) John threw the old trash sitting in the kitchen out.
Yes, (1) is easier to parse (and I prefer it) but (2) is less ambiguous: (1) could equally well mean that John threw the trash out while he was sitting in the kitchen.
I also find the title of the post a little confusing. I thought the article would be about how learning languages helps your brain recover.
And yes the article seems to be more about language patterns that give your brain a break than language in general.
edit: Apparently that's an old wives tale, the preposition one.
If we consider put-up-with as a verb that just so happens to be a compound verb-postposition-postposition _unit_ then the sentence "That's the kind of grammar prescription which we will not put up with" actually ends in a verb. If you see what I mean. Does this make sense? I'm just punting this intuitively.
I'm trying to think of an actual case where a bare adpositional word terminates a sentence... which is not in question form... and I can only think poetic uses... and after having Googled a bit... verb+prep or phrasal verb or question are the only examples I've _come across_. :)
s/which/that/
Sorry, but that drives me crazy. I think your "verb+prep" gives the game away, as that is very common idiom. What about this: "That's the store we got the candy from." Perhaps a sentence using "where" would be more stylish, but you can't very well throw out a prescription of grammar just to immediately replace it with one of style.I like your example. Never mind about style. I can riff on that: "There's the table we put the apple on.", "Here's the bag I keep my laptop in." And so on. Nice!
"I shot an elephant in my pajamas... how he got into my pajamas I'll never know."
Not a grammar expert and may be wrong, but I think technically it's unambiguous because you do actually need the while to make John the subject of the verb 'sitting' in that sentence.
Of course you're right that in practice, especially in speech, it could be taken either way and is thus definitely ambiguous. One could argue that's all that matters, I certainly would, but just to be pedantic I thought I'd point this out ;-)
A somewhat related example is center embedding structures, which are grammatical but usually quite difficult to parse once you get a few levels deep:
Neither is ambiguous, "the old trash sitting in the kitchen" is unambiguously the direct object in #1; to make "sitting in the kitchen" apply to the subject (John) rather than being part of the phrase identifying the direct object, you'd need either to relocate it and set it off with commas ("John, sitting in the kitchen, threw out the old trash"), or add a "while" ("John threw out the old trash while sitting in the kitchen").
YMMV, but for German (I'm not a native speaker, although fluent) you can't figure out the meaning of the sentence until the very end.
The authors' even acknowledge this:
>German, which has some notoriously indirect sentence constructions, is far less optimized, according to the analysis.
>And the researchers also discovered that “head-final” languages such as Japanese, Korean, and Turkish, where the head word comes last, show less length minimization than is typical.
German, Japanese, Turkish seem like quite a big chunk of languages (population-wise), so I wonder if initial statements are not too English-specific.
- Mark Twain
From the article: "among languages. Italian appears to be highly optimized for short sentences" - oddly, though, a lot of more 'literary' Italian tends to long, florid phrases that I would consider run-ons in English. "Rhetoric" has been a thing there for thousands of years, after all, after they borrowed it from the Greeks.
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.433...
(a lot of articles provide summaries, eg http://www.scientificamerican.com/article/fast-talkers/)
They cite three others:
http://www.researchgate.net/profile/John_Locke5/publication/...
http://www1.icsi.berkeley.edu/~steveng/2000/PDF/UninvitedGue...
I can't find access to the third one without digging since it's published in conference proceedings from 1961, but there's a talk with access (wow!): http://www.helsinki.fi/speechsciences/history/snds/Karlgren....
Further citation-following yields more books I cannot get a hold of (see the citations in the papers if you want to digg).
Recursion in Language (p. 138):
Our mental stacking power is perhaps slightly stronger in
language. The grammatical structure of all languages involves
setting up quite elaborate push-down stacks, though, to be sure,
the difficulty of understanding a sentence increases sharply with
the number of pushes onto the stack. The proverbial German
phenomenon of the "verb-at-the-end", about which Droll tales of
absentminded professors who would begin a sentence, ramble on for
an entire lecture, and then finish up by rattling off a string of
verbs by which their audience, for whom the stack had long since
lost its coherence, would be totally nonplussed, are told, is an
excellent example of linguistic pushing and popping. The
confusion among the audience out-of-order popping from the stack
onto which the professor's verbs been pushed, is amusing to
imagine, could engender. But in normal ken German, such deep
stacks almost never occur-in fact, native speaker of German often
unconsciously violate certain conventions which force verb to go
to the end, in order to avoid the mental effort of keeping track
of the stack. Every language has constructions which involve
stacks, though usually of a less spectacular nature than German.
But there are always of rephrasing sentences so that the depth of
stacking is minimal.
Here is an example of such a (grammatical) beast: Der Mechaniker,
auf den wir wegen dem Unfall,
den wir,
bevor wir die Stadt,
die im Norden liegt,
erreichen konnten,
hatten,
gewartet haben,
ist endlich angekommen.
This can’t really be translated to English: The mechanist,
for whom because of the accident,
which,
before the city,
which lies in the North,
we could reach,
we had,
we have waited for,
has finally arrived.The buildings the money the tourists the songs the people the city the mechanic the accident affected was late to contains sing attracts spend paid for are also a big draw.
Abstract: Explaining the variation between human languages and the constraints on that variation is a core goal of linguistics. In the last 20 y, it has been claimed that many striking universals of cross-linguistic variation follow from a hypothetical principle that dependency length—the distance between syntactically related words in a sentence—is minimized. Various models of human sentence production and comprehension predict that long dependencies are difficult or inefficient to process; minimizing dependency length thus enables effective communication without incurring processing difficulty. However, despite widespread application of this idea in theoretical, empirical, and practical work, there is not yet large-scale evidence that dependency length is actually minimized in real utterances across many languages; previous work has focused either on a small number of languages or on limited kinds of data about each language. Here, using parsed corpora of 37 diverse languages, we show that overall dependency lengths for all languages are shorter than conservative random baselines. The results strongly suggest that dependency length minimization is a universal quantitative property of human languages and support explanations of linguistic variation in terms of general properties of human information processing.