begin quoting Andrew Lentvorski as of Mon, Aug 22, 2005 at 01:06:27PM -0700: > Stewart Stremler wrote: > >This does seem to be my impression of a lot of code lately. But then, > >I loathe #ifdefs in code. I'm just funny that way. > > You are not alone. Heh.
> One of the best articles I ever read was in C/C++ User's Journal talking > about portable code and how to get rid of #ifdef's. The big one was to > isolate the API to a single file which gets selected at *compile* time > by the *build* system. This is the way I was taught (or learned, by listening to old farts rant and rave) to handle (platform-)dependency issues. Identify, extract, and isolate. > However, the "Aha!" moment was discussing some String function which was > present in Windows but not in Linux (or vice versa). "Look, if you are > going to have to write a substitute function for *one* OS, use it on > *all* the OS's (ie. ignore the native one on Windows). The gain in This tends to get back into the "All the source you need to make it work in one package" approach. As opposed to the "Never adopt or rewrite a function that you could instead reuse from someone else's library". (I suspect the latter approach comes from the 'Code duplication is evil, and must be eradicated!' meme.) > being consistent across all the different build types, removing build > specific code, testing the custom function everywhere and having > everybody use the same code path far outweighs the efficiency gain of > using the native function. Just comment *why* you are ignoring the > native function so the next schmuck doesn't try to put it back in." GST (GNU Smalltalk) does this for some of the output functions. I'm not sure it's really helped that much. -Stewart "Not alone anymore in a cold and uncaring universe!" Stremler
pgpw9HKtCzlnZ.pgp
Description: PGP signature
-- [email protected] http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list
