5 ms·
Japanese Programming Syntax
- ahhrrr 16y agoEven though Japanese is traditionally written vertically, right to left, modern Japanese is just as valid written horizontally, top down. Latin characters are never written vertically – so code wouldn't be either.
- zerosanity 16y agoThis exact same line of thinking went through my head a few days ago. Since I'm starting to toy with learning Japanese I wondered how a programming language with a SOV ordered syntax would look like. I guess now I know.
- merloen 16y agoStack-based languages like forth have a SOV (postfix) order. An interesting property of postfix languages is that the order of evaluation of functions is identical to the order of the function names in the source code: Functional (prefix, C) f3(f1("") f2("")) OO (infix, Java) "".f1().f3("".f2()) Stack-based (postfix, Forth) "" f1 "" f2 f3
- DarkShikari 16y agorainGear.grab(); rainGear.wear(); Isn't this just Java? (see also http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom...)
- IgorPartola 16y agoGood point. Functional programming => verb(subject, object). OOP => subject.verb(object). English => subject verb object (is this some Lisp-like construct?).
- deleted 16y ago[deleted]
- masklinn 16y agoThe whole thing really feels a lot like Smalltalk. Some things don't work as well (can't use `;` for the contexts), but apart from that, a smalltalk-like language works well: (weather is: #(#rain? #drizzle?)) ifTrue: [ 'rain gear' haveObject: [ grab wear ] 'door' openObject; walkThrough ] ifFalse: [ 'house' stayIn ]
- mechanical_fish 16y agoI've always marveled at the number of synonyms in Ruby. collect() and map() are the same thing, there are a bunch of ways to make lambdas, etc. We should start the urban legend that each of these synonyms has a different degree of politeness. your_lovely_array.collect { |awesomeness| awesomeness.aspect } my_worthless_array.map { |x| x.thing } Bonus points for anyone who can get this meme propagating on Stack Overflow.
- billybob 16y agoI have heard speculation that the abundance of synonyms may originate with the Japanese language. I was told that in Japanese (which I don't speak), you might use a different word for "one" when saying "one cat" versus "one house" or "one country," and that the word choice would be made based on which one "sounds best" in that context. IF that's true (can anyone confirm?), it might have seemed fitting to Matz that using "collect" vs "map" would be an aesthetic choice for the programmer.
- masklinn 16y agoIt probably has more to do with these words (or syntaxes) meaning the same thing in the various languages Matz got inspiration from (Perl and FP languages use `map`, Smalltalk uses `collect`). One of the personality traits Ruby got from Perl was being a grab-bag of a bunch of stuff.
- JMStewy 16y agoThis is true, and it's not unique to Japanese (Chinese does it too). But I'm not sure the existence of this specific feature in the language supports any particular generalizations about a "Japanese mindset." To English speakers, using different counters for different classes of nouns is a pretty strange feature, but I'd imagine no stranger than the Japanese might consider our plurals. Japanese (and Chinese) don't inflect nouns for plural agreement at all. From there, imagine how English's seemingly random collection of irregular plurals must seem (feet, oxen, halves, deer, women, mice, children, dice, larvae, alumni, bacteria, etc). I wonder what features of English-origin programming syntax they might link to this bizarre collection of special cases :).
- rwmj 16y agoAll good except the very final example. If it was really going to be written right to left, top to bottom, then that would only make sense if whole characters were used, roughly equivalent to words in the made-up language, not equivalent to single English letters. Something like this: ( weather WxRAIN == ? etc. (Also I moved == after the object since it's going to be postfix in Japanese). But in any case I highly doubt that any language invented for a computer (ie. recently) would be written top to bottom. Just about every computer in Japan is using left to right.
- mmastrac 16y agoThat's probably because the cultures that developed TTY displays developed them so that the cursor moved from left-to-right, top-to-bottom. If the Japanese had the same position as the western world, our TTYs would probably a direction that more closely matched their language.
- mijnpc 16y agodon't they have any programming languages in japan? perhaps in japanese?
- probablyrobots 16y agothe conditional syntax he describes does exist in many mainstream programming languages (x==y) ? a : b
- peti 16y agoMoreover, using an arrow operator, the OP almost wrote a Prolog expression: ( X==Y -> A ; B)
- masklinn 16y agoNo. You can't put statements in this, only expressions. It's a limited special case instead of a generic tool (and putting a sequence of conditionals and actions is not going to look good, though I'm sure you can coerce them into it using the "," operator, as long as you don't need to have an iteration as well). There are languages which have pretty much exactly what he describes (Smalltalk for instance), but "many mainstream languages" don't.