Editor's Note: This article was originally published in May 2004. It has been edited for publication here.
Translating Code Between Languages
A couple of days ago I was wasting some time in an IRC chat about Delphi programming when someone came in and exclaimed his love for Castalia. Intrigued, and perhaps fishing for a compliment, I asked what he had found so noteworthy. He described a use for Castalia that had never crossed my mind. I thought it was a great idea, and so I'm sharing it with everyone else.
It's a fact that there are more Delphi users outside of the United States than in the United States. I believe that the majority are in countries where English is not the native language. Since the Delphi user community is fairly tightly knit, and there are lots of components, libraries, and sample code on the web, in newsgroups, and elsewhere, it's no surprise that there is a large body of code available that is written in languages other than English.
Of course, the code is written in Delphi, but our code is also written in English, and I don't mean comments. Consider this example:
function TPokupatel.PoschitatVozrost: Integer; var Vozrost: TDateTime; begin Vozrost := Now - DenRozdenia; Result := Trunc(Vozrost) div 365; end;
Now, what does that code do? If you speak Russian, it's quite obvious what it does. If you do not, then it's pretty difficult to figure out, although the magic number 365 might offer a clue. Let's translate it from Russian into English:
function TCustomer.CalculateAge: Integer; var
Age: TDateTime; begin Age := Now - BirthDate; Result := Trunc(Age) div 365; end;
Isn't that easier to read for those of us who don't speak Russian?
My IRC chat mate found himself in exactly this situation. He had a library of code that he wanted to use, but it was written by someone whose native language was German, and who had written the code in German... or at least had given all of the classes, methods, and variables German names. I'm not sure how he translated them, perhaps using BabelFish, but he pointed out that once he knew what was meant by a certain class, method, or variable name, he was able to use Castalia's Rename Class, Rename Method, and Rename Local Variable refactorings to quickly and easily change the names to something that he was able to read easily.
I was amused by this, and was very pleased to see a use of Castalia that had never crossed my mind - and I've been in this situation! Hopefully this will help to narrow the gap among Delphi developers of varying nationalities, and will open more resources to those of us who don't speak every language there is.

