Monday, October 21, 2013

Defining Pi

Sometimes, when working in Scheme, I'm surprised that pi is not defined. I'd define it myself, but to what precision? My current method is to exploit Euler's identity to get the basic precision supported by log. Is there a cleaner way to initialise this?

 (define pi (imag-part (log -1)))

Monday, October 14, 2013

Information Hiding

(I'm not going to talk about steganography.) There's an idea in object oriented design that suggests that information hiding is part of the success of encapsulation. Having worked in OO languages that do not have the notion of private/public interfaces (Smalltalk is a great example) the way Java or C++ do, I am sometimes skeptical of the benefits of this. I believe I see a point in programmatically specifying your level of abstraction and sticking to it. You worked hard to make the abstraction layer, and it would be useful to be able to see it used, and perhaps know where it was misused or bypassed. On the other hand, I think enforcement of this leads to a huge level of headaches, and changing the interface after the design is daunting, since the compiler will likely throw a fit. In conclusion, since it interferes with redesign and rethinking, for me it's a misfeature.

I always thought it was silly if you have the source to 'hide' the implementation. The pointer to implementation pattern in C++ is the ultimate expression of this fetish, trying to move the guts out of the header (since there is a weird amount of required information in the header files) and into the source, where I guess it can be compiled and hidden in object code. Here I disagree with both the sentiment and the technique.