From: Peter Kwangjun Suk Date: 2003-01-24T04:59:42+09:00 Subject: Re: emulating C preprocessor's #if On Fri, 24 Jan 2003 04:40:38 +0900 Joel VanderWerf wrote: > Peter Kwangjun Suk wrote: > > On Fri, 24 Jan 2003 03:36:04 +0900 > > Joel VanderWerf wrote: > > > >>Usually, when writing ruby code, I don't worry about conditional > >>compilation, and just use a run-time test. > > > > What about using the Factory pattern, and instantiating an object of a platform-specific subclass? > > Thanks, but I was avoiding any extra objects or method calls because the > code is fairly performance critical. (But then maybe I should just be > using C anyway, rather than try to write C in Ruby.) If you do it right, you can instantiate only once. Also, another thing you should do is to code for maintainability, *then* profile once it runs correctly. I have used profilers all through my career, and rarely have I ever been *not surprised* in some way. Also, there's the 80/20 rule. So when I code up front for performance, I end up writing difficult to maintain code in sections that didn't really need it. And no, you shouldn't try to write C in Ruby. That's just the flip side of trying to write an OO program in C. Play to your language's strengths. If you post your code, I'll be happy to look at it. It might make a great case study for Refactoring vs performance. --Peter Kwangjun Suk