6 ms·
I'm a little suspect if this analogy goes beyond "theoretical understanding without practical experience is worthless". You could draw a similar analogy between
by VMG 15y ago
I'm a little suspect if this analogy goes beyond "theoretical understanding without practical experience is worthless". You could draw a similar analogy between architects who know everything about architecture but don't know how to design proper buildings because they have no experience. Or painter who knows everything about technique but can't paint a horse and so on.
It is easy to find differences between good writing and good code: Uniformity in code is good, while uniformity in prose is bad. In writing, a large vocabulary is an advantage, it's difficult to see if that is the case in language. In programming, proper abstractions are essential while I can't really see the equivalent of that in writing.
As far as analogies go, I can't see how this one is much better than others.
- regularfry 15y agoUniformity in code is bad - it tells you that there's a common concern or pattern which should be factored out. Uniformity in code style is essential, the same way it is for prose.
- VMG 15y agoIs it? In prose you say "first he rushed to the exit door, then he leaped down the stairs, finally he ran to get the train" while in programming it is better to write socket.close(); window.close(); file.close()
- vorg 15y agoBetter prose is: "He rushed to the exit, leaped down the stairs, and ran for the train." Better programming is to factor out the action: [socket, window, file]*.close()
- jamesbritt 15y agoIndeed. Programming is more like writing math than natural language.
- SlyShy 15y agoJust curious, is that taken from an actual language? Because I've wanted a feature like that for ages.
- scythe 15y agoIt exists in Ruby: [socket, window, file].each{|item| item.close()} http://codepad.org/GqNp94Iw http://codepad.org/GqNp94Iw It sort-of exists in Lisp-inspired languages (anything from Arc to Lua to Io) with appropriate boilerplate, for example: function apply(tbl, func) for key, val in ipairs(tbl) do func(val) end end apply({socket, window, file}, function (item) item.close() end) http://codepad.org/SNWO1Y6K http://codepad.org/SNWO1Y6K
- btilly 15y agoIt also exists with slightly different boilerplate in Perl: $_.close() for $socket, $window, $file;
- getsat 15y agoYou can also: [socket, window, file].map(&:close) That just sends the :close message to each object in the set and returns a set of the results of each object evaluating that message. Yay, Smalltalk.
- gliese1337 15y agoIt'll work in JavaScript, too: [socket,window,file].forEach(function(o){o['close']();});
- michaelhoney 15y agoAnd all of these ways are longer and less clear than the original. Better to write code like Hemingway than like Proust.
- gredman 15y agoI believe it exists in Cω via "generalized member access" without recourse to map/foreach-type constructs.
- shasta 15y agoAnalogies are like shopping carts: if you push them too far they don't work well and you have to lubricate them.
- brudgers 15y agoand similes often have a wobbly wheel to begin with. It's one way the may be distinguished from analogies.
- deleted 15y ago[deleted]
- michaeldhopkins 15y agoComparing declarative prose in past tense and instructions doesn't work. "Rush to the exit doors, then leap down the stairs, then finally run to get the train." Humans need first/then/finally or else we might execute instructions concurrently ("Boil water. Dice an onion.") Although, these words are unnecessary if a the beginning a human is told, "follow these instructions in order," as a compiler is told to read files. "Finally" is the signal to stop executing after the last statement, compilers use EOF, close tags etc to achieve the same thing. So, the analogy is quite precise if imperative sentences and code are compared and the whole prose text is compared to the code plus the compiler.
- regularfry 15y agoYou don't want to write one paragraph like a romance novel, another like a patent application then a third like an advert.
- VMG 15y agoSome artists do. Writing is an art, and breaking rules in art is not the same as breaking rules in programming. If not, you just say "consistency is good" which also applies to architecture, painting and so on.