Discussion
opera

AI Getting Lost in Translation?

Dave Mark on September 20, 2008

This discussion topic was introduced by Dave Mark, designer at Intrinsic Algorithm. Can you learn techniques and algorithms and apply them easily in other languages? Let us know and post a comment below.

This is what Alex would look like as an opera singer

For a while, my mother was a semi-professional opera singer. As she would practice, she would sing in various languages that were not familiar to me — German and Italian being predominant. She would also make me watch various operas on video or when they would come on TV. When I expressed that I was somewhat bemused by the fact that I couldn’t understand what the singers were saying, she pointed out that the story was generally written out in the program. For those of you who haven’t had the pleasure of experiencing this process, it’s worse than sub-titles in that there is no synchronization between what you can understand and what they are actually doing. (Also, a darkened theater is less than conducive to reading along.)

At one point, I had discovered that some of the operas had been translated to English. I thought this was a perfectly acceptable solution to the problem… until my mother told me that “it’s just not the same”. Since my mother, despite being able to pronounce the German and Italian words as she sang, was not even remotely familiar with either language, I didn’t see how she could make the claim that they “just weren’t the same.” I suppose someone told her. Regardless, my position was that if I could understand the mildly adulterated version, it was far more valuable to me than not being able to comprehend the perfect original.

Twenty-five years later, I can see what she was talking about. Being reasonably adept in Spanish and having some French and German under my belt, I can see how there are certain things that just wouldn’t be able to make the jump from one language to another — at least not gracefully. Many idiomatic expressions are pretty dicey to translate. What’s more, when you are in a song or poem format and you really have your heart set on rhyming, good luck trying to keep that rhyme going in the new language. You can still get the point across but, without the rhyme, it won’t be as “elegant”.

Not My Native Tongue

That being said, I was recently privy to a conversation where a student in an introductory course on AI was being taught iterative deepening search in, of all things, Scheme. Now I don’t know enough about Scheme to fall one way or another… just as I don’t know enough about Italian to say whether or not the Verdi’s Aida is decent in its original language. (Of course, I don’t know enough Aida to tell you whether it is decent in English either.) However, in a game programming world dominated by C++, I would question the merits of teaching in anything other than C++.

“Oh, I remember how to do that… but I learned it in Scheme. How would I do this in C++?”

From a practical standpoint, the student is learning two things at the same time — the algorithm AND how to do it in Scheme. If you were to then ask the student to program you an iterative deepening search in your game, he now has to go through an extra layer of translation in order to do so. He has to say “Oh, I remember how to do that… but I learned it in Scheme. How would I do this in C++?” In essence, he now needs to look down at his program during the performance.

Idiomatic Inconsistency

“It may be in a language you can understand… but it is just not the same content.”

On the other hand, there is just some stuff that you can’t pull off in other languages. What if you have access to some really nifty code, complete with complicated, upper end data structures that has been written in C++ (as is most of the code in books, for example) but the project requires you to script it in Lua or Python? While the scripting languages of today are getting more and more powerful, there are just some things that you either can’t do well in them or can’t do as quickly in them. (In fact, there are some things you simply can’t do at all.) So, while the original code may have been a thing of elegance and beauty, you now have something that kinda resembles it and may accomplish something of the same function… but its not as good as the original. At that point, just like the translated opera, it may be in a language you can understand (and even sing along with) but it is just not the same content.

Sharing Ideas vs. Sharing Code

The reason that I find this important is that the #2 item on last week’s poll, “What’s Holding Back Game AI?” was “Insufficient Code Sharing & Reuse”. In a way, this also spins out of my column from a few weeks back, “Programming, Pictures, Presentations or Prose?” where I talked about the best way of sharing knowledge and concepts. We are all used to sharing those via papers, lectures, message boards or what-not. However, it’s that sticky bit about sharing code that could generate problems — if not now, then possibly later.

“While I can certainly share an idea with him, this prevents me from sharing my code with him.”

For example, my brother is diligently working on a game project of his own. While he is a very good programmer, he swears entirely by VB. When he has asked me to help him by doing some AI work, I have had to turn him down. I simply don’t want to do it in VB despite the fact that I’m fluent in it. I’ll do VB for business apps, but not for my AI programming. There is too much of my existing code or stuff that I would cull from the likes of AI Game Programming Wisdom books that is written in C++. While I can certainly share an idea with him, this prevents me from sharing my code with him.

To his credit, though, one of the knocks on C++ is that it is stagnating while other things are moving forward. Because so much of our code base — and the associated knowledge — is lodged in C++, however, we may be left behind. I don’t know. I’m not playing Prophet here (I did the whole biblical thing 2 weeks ago), just pointing out that we are good and entrenched right now.

As another example, many of us veterans have pointed people in the direction of Craig Reynolds’ page on Steering Behaviors For Autonomous Characters, the original code that generated the cool little web examples was in Java. Sure, I could look at it… but even if I was fluent in Java, I wouldn’t be able to simply drop it into my own code. That has been remedied recently by creating C++ implementations of them as OpenSteer. Now, I can use those bits and pieces in my own code… unless, of course, I’m working for my brother in VB.

Linked lists in Opera

Transcending Language?

So is there a way that we can write our material so that it goes beyond the specifics of languages? I’m not so sure. Steve McConnell did a great job of removing some of the specifics of language in his perennial favorite style manual, “Code Complete“. In many places he gave examples that worked well in any language. In others, he simply gave short examples in many of the standard languages. However, I can’t see either one of those approaches working for either teaching or exchanging ideas. While you can explain the idea behind the iterative deepening search in English or even pseudo-code, you still have to teach people the appropriate data structures in order to create it… and data structures often have that prickly little bit about being very language-dependant.

So how much of this is a problem? Is there a way of getting beyond this divide? Should there be standards in teaching game AI such that what is taught is immediately applicable without modification in the production world (e.g. no Scheme)? Should all code-sharing in books be done in C++ and/or Lua? (It is already, but that may need to be enforced down the road.) Or, in a really whacked out idea, does the game world need to find a new home outside of C++?

Or should we all just bring little flashlights and try to follow along with the libretto in the dark of the opera house?

Discussion 10 Comments

Kevin Dill on September 22nd, 2008

I'd have to agree that if you can't carry concepts like iterative deepening (which isn't all that complex an idea, after all) across from one language to another, you need more help than I can give you. Most of my work in graduate school was in LISP (the grown-up version of Scheme), and yet I didn't have any trouble working in C++ when I graduated. With that said, I have heard rumblings at more than one school about dropping C++ from the curriculum entirely and using C# or Java instead, and that does alarm me. Among other things, you can't teach students how to use pointers in a language which doesn't support them - and in my mind, that's a critical part of understanding at a gut level what is going on underneath the covers.

Dave Mark on September 22nd, 2008

I agree that most of us [I]can[/I] make the jump from language to language, but it is unfortunate when we have to. A little history of my language chain. I originally started in BASIC on old Apple ]['s, in high school I was taught Pascal (and FORTRAN for some reason). That was my intro to structured language and still use a lot of the ideas that my excellent teacher forced into my brain. That was in '85-'86. I learned VB in '95, SQL in '96, HTML in '97, PHP in '02, and C++ in '03. I have often gone through extended periods where I may use all 5 of those in one day. I hate switching mindsets (usually just related to the syntax) back and forth. I want to just "think in _____". However, I think Kevin hit on an example that expresses the point I was trying to make - something like pointers in C++. You just can't do that in other languages. I have entire data structures that are based on an STL vector of structs that have, as one member, a pointer to an object. Could I replicate that in another language? I suppose I could eventually... but [I]how[/I] I do it depends largely on what language I am translating to. And that is where some of the "elegance" might disappear. Also, I don't want to make it seem like I'm trashing Scheme. As I said the column, I don't know enough about it to say one way or the other. It is just unfortunate that we don't all speak the same language (so to speak) across areas like game development, academic AI and financial institutions. (Some of whom are probably still using COBOL!) That way, the teaching languages could match all of the possible job markets and do away with the necessity for translation.

flammifer on September 22nd, 2008

[QUOTE]I agree that most of us can make the jump from language to language, but it is unfortunate when we have to.[/QUOTE] I look at it the other way around: the main reason I try out various languages is to get used to switching from one to the other, and understanding the differences. When I started Python, I was essentially writing C++ in Python; it took me more than a year to be familiar enough with the idioms and the easier ways of doing complicated things (I cringe when I look back at my own code, that sometimes could have been ten times shorter). Even studying a bit of scheme (basic stuff only) taught me about Python, if only by pulling my mind a bit further away from C++. Some time back I worked on the AI of a game that used a home-made scripting language; it took me quite a while to get used to it's own way of doing things; looking back again there are probably quite a few things that could have been done differently had we started up with a good knowledge of the "idiomatic" way of doing things (most of the team was unfamiliar with that language). So I recommend trying out various languages, if only for better flexibility of mind. You may be writing C++ in Python, or Fortran in C++, and not know it yet.

Noah Adler on September 22nd, 2008

I have some friends from various places around the world. Sometimes they speak to each other over the phone, and freely intermix languages, picking and choosing whichever words make sense to them at the given moment. Especially some of my Arabic speaking friends seem to intermix Arabic and English extremely freely and fluently. To my mind, once it's understood that certain languages work better for certain domains, it becomes a pretty logical conclusion that being able to mix and match as freely as possible is the way forward. Traditionally polyglot programming has been quite painful from a technical perspective, not to mention the significant amount of extra study required. However, platforms like .NET are making strides in reducing the pain of interop. I can't help but look optimistically forward to the day when we can mix programming languages as naturally as my friends mix Arabic and English. I can't imagine a Computer Science curriculum which couldn't be improved by placing more emphasis on language theory fundamentals. Even thinking about EBNFs is foreign to a lot of people, and there's really no excuse for that. If such formalisms were introduced and internalized to students earlier, by teaching DSL design and construction for instance, I can only think the state of the science would be improved.

Dave Mark on September 22nd, 2008

[quote=Noah Adler;5023]To my mind, once it's understood that certain languages work better for certain domains, it becomes a pretty logical conclusion that being able to mix and match as freely as possible is the way forward. Traditionally polyglot programming has been quite painful from a technical perspective, not to mention the significant amount of extra study required. However, platforms like .NET are making strides in reducing the pain of interop. I can't help but look optimistically forward to the day when we can mix programming languages as naturally as my friends mix Arabic and English.[/quote] I agree that mix-and-match may be a good approach, but, as you mentioned, there is a severe technological hurdle. Right now, .NET is about as close as you can get, but you have to take a bit of a performance hit to do it. You have to wonder, however... if the answer is combining languages into one environment, then why not combine languages into... uh... [I]one language[/I]? I know that sounds silly, but is it feasible to have ONE language that encompasses all possible needs? If not, why not?

zoombapup on September 22nd, 2008

Have you considered switching to the "universal language" mime? :) Sorry, couldnt resist!

Dave Mark on September 22nd, 2008

[quote=zoombapup;5028]Have you considered switching to the "universal language" mime? :)[/quote] As long as it supports the development of NNs, GAs and pathfinding, what else is there?

Jare on September 23rd, 2008

[QUOTE=Dave Mark;5026]I know that sounds silly, but is it feasible to have ONE language that encompasses all possible needs? If not, why not?[/QUOTE] There's a running theory that any sufficiently complex application will contain a half-assed LISP interpreter, so there you go. :) Really, some of the choices of different languages are direct opposites. I hate when in C++ I have to type so much decoration, repeat function signatures in the declaration and definition, etc. But then I go all the way to Python and the language is so dynamic that many times I can't figure out what a class looks like unless the author put extra effort in making it so. Even in C# I often miss having a plain old header file with the class declaration and nothing else. A language that supports every possibility is at the mercy of the specific idioms and standards of the programmer using it, so that's not much help. In any case, back to the original post... plug and play code is hard not just due to language, but also to the primitives and libraries that the code relies on. I recently downloaded Alex's GameAI++ and what hit me right away were those abstractions for Delegates, Typelists and whatnot. And that's just the framework, when you start looking into specific algorithms or subsystems like an obstacle avoidance system, there's all the math, physics and etc that make plug-and-play code a utopia.

Dave Mark on September 23rd, 2008

[quote=Jare;5039]I hate when in C++ I have to type so much decoration, repeat function signatures in the declaration and definition, etc. [/quote] [URL="http://www.wholetomato.com/"]Visual Assist[/URL] rules. Download the trial and in 2 days you will be hooked. In a week, you won't want to go back. After a month, you will no longer be able to go back since you will be doing [I]everything[/I] with the intellisense, shortcuts, automatic refactoring tools, etc.

Jare on September 23rd, 2008

[QUOTE=Dave Mark;5043][URL="http://www.wholetomato.com/"]Visual Assist[/URL] rules.[/QUOTE] Well I use it at work but at home I get by without it no problem. Then again I do very little C++ at home, and MSDev has much better tools for C# than for C++. To me Visual Assist is basically Shift+Alt+O (find files in the project), Alt+G (go to declaration/definition), Alt+O (switch to/fom .h and .cpp) and an Intellisense that works well in large projects. It's great but it doesn't change the nature of the language, and has its own share of bugs.

If you'd like to add a comment or question on this page, simply log-in to the site. You can create an account from the sign-up page if necessary... It takes less than a minute!