What advice (tips, techniques, gotchas, et cetera) do you have for someone who is porting a code library from one language to another, or rewriting it to work in a different compiler, environment?
Every platform (language and system libraries) has its own persona. The way a Ruby programmer designs their API takes advantage of the unique features and culture that make Ruby what it is. This is distinctly different than the way a C or C++ developer would design their API, which is in turn different from the way a Java or C# developer would do it.
You want to take the ideas from the original platform, and mold them into the concepts that make the new platform what it is. Nothing feels less natural than using a library designed in a completely different manner than the other libraries in the platform. There's a number of programming platforms that are actually well designed, and elegant. You want to leverage those strengths for your port.
Know the native capabilities of both your "to" and "from" language/framework.
I spent time rewriting the entire library in Objective-C only to realize that my code was largely redundant. (By the way, I did a poor job and was getting inaccurate results. That's when I took a step back and realized my mistake.)
Several tens of lines of conversion methods were replaceable with six or so lines of native framework code.
If this is a critical project (porting often is), write a complete test plan (ideally with unit tests in the target language) BEFORE porting each piece of code and the entire system.
There is no way in the world that the porting will be 100% accurate in the first try, so you need to make sure in advance that you're catching everything.
If possible, execute the same plan for the original code because there are no guarantees that it was written correctly, and, in fact, having an equivalent behavior may depend on an incorrect implementation.