Jean Paul Satre once said, "Hell is other people." Perhaps if he were a programmer, he would have said, "Hell is other people's code." I'm currently helping a friend with some C++ he's doing for an assignment. Said friend is a Windows programmer, whose knowledge of Linux/Unix is "it exists and is weird". I can't blame him: who would willingly leave the world of comfortable integrated development environments with decent debuggers and a rich, built-in (if proprietary) library that keeps you from needing to know most of the standard language? That last one is particularly nice in C++, where I can't even keep such things straight in the standard library.
So he comes to me today with his latest assignment, which he's written and has working on his Windows box, but now needs to port to a Unix box. Now, let me pause for a minute here and say that the school has not made his life easy: the Unix box he's working on is an DEC/Compaq Alpha box from about 2000 or so. uname -a returns "OSF1 creek.uh.edu V5.1 1885 alpha". It's C++ compiler is equally antiquated: "Compaq C++ V6.5-014 for Compaq Tru64 UNIX V5.1A (Rev. 1885) Compiler Driver V6.5-014 (cxx) cxx Driver". Its support for the STL is spotty: there's no support for character streams that don't involve I/O directly. He doesn't know make, either. So let's just say that the deck is very much stacked against the guy, and it's no wonder that our university's program produces grads that cling tenaciously to Windows or Java, as using this box could scar a person for life (which it has on multiple occasions: I have to play *nix apologist to get people to play on Linux or Mac).
Now, I've been telling him to write Unix code on a *nix of some nature
1. However, he insists on writing in Visual Studio, then moving files over to the target box
2. This leads to obvious compatibility issues.
After a while of auditing his code, to see why it won't build on my box (uname -a gives "Linux thephotoman-laptop 2.6.28-11-generic #41-Ubuntu SMP Wed Apr 8 04:38:53 UTC 2009 i686 GNU/Linux"), I see things like atoi() being undeclared. I look, and there is no reference to the cstdlib header. Obviously Visual Studio and Compaq C++ are both letting him off easy
3. He's also using compilers that let him get away with a main function without a return value (standard C++ dictates that main() return an int). This leads to me getting in touch with my Pulp Fiction side.
I also see that he's hardcoded a file path in his program. It reads "C:\input2.txt". We'll not touch what's wrong with that in Windows, but obviously it won't work on a *nix box
4.
So now, at an hour that most humans would consider ungodly, he's downloading and installing VMWare Player and an Ubuntu image
5. Tomorrow, I'll walk him through GDB and following forks.
1. Usually, I prefer either Darwin 9.x or Linux 2.6.2x on 686. The former has my favorite text editor, Smultron, and the latter actually has a full set of working tools. Apple appears to have broken GDB on Darwin, and I can't seem to figure out how to compile GNU's version on the platform. If anyone has tips, I'd appreciate it.
2. I don't blame him for writing code on other boxen. vi and emacs are equally unusable on that system.
3. To his credit, he did figure out -lm on his own. That tripped me up the first time. He's not a bad coder, he just fails at Unix.
4. Again, I have some fail here as well: he sent me a copy of the file that was Unix-safe. I didn't see it until after I'd fixed the copy I'd been looking at.
5. Presumably, he'll also use Jim's First Time Script to get the dev tools6, which aren't a part of the default installation. Yes, I'm pimping my own little side project.
6. Interestingly, this includes vim. Don't ask me why.