More Thoughts About FXRuby API Changes
Per the last few posts, I’m thinking a lot about potential API changes for the upcoming release of “FXRuby”:http://www.fxruby.org/ 1.6.
When Jeroen began developing “FOX”:http://www.fox-toolkit.com/ way back when, most of the available C++ compilers didn’t have great support for C++ namespaces. As a result, FOX classes ended up with an “FX” prefix to avoid name clashes. That is of course of little concern to Rubyists, as the @Module@ construct provides (among other things) a way of maintaining separate namespaces for different code libraries. Despite this, the FXRuby classes followed the standard FOX naming conventions, and so we end up with the visually jarring situation that the fully-qualified name for FOX’s button class is @Fox::FXButton@.
So one of the major changes that I’m considering for FXRuby 1.6 is renaming the classes by removing the “FX” prefix from the existing class names and method names. @Fox::FXButton@ becomes @Fox::Button@, @Fox::FXLabel@ becomes @Fox::Label@, and so on. There’s no technical reason to make such a change, but it would be more aesthetically pleasing. One disadvantage of this change would be that the FOX and FXRuby class names would no longer quite match up (although it wouldn’t be much of a brain twister to convert between the two). A more significant disadvantage is that it would break a lot of existing code. This problem could probably be alleviated by using @const_missing@, e.g.
module Fox
def self.constmissing(classid)
name = "FX" + classid.tos
if constdefined? name
constget(name)
else
super
end
end
end
Another change that I’m considering is switching from CamelCase method names to method names with underscores, so that @beginWaitCursor@ becomes @beginwaitcursor@. As with the proposed change for the class name, the potential for code breakage could be alleviated by the careful use of @method_missing@, with something along the lines of:
class FXObject
def methodmissing(methodid, args)
camelcase = methodid.tos
while camelcase =~ /([^_])(.)(.*)/
camelcase = $1 + $2.upcase + $3
end
if respondto? camelcase
self.send(camelcase.tosym, *args)
else
super
end
end
end
Note that this idea was “inspired” by Richard Dale’s work on Ruby/Qt.
You’re currently reading “More Thoughts About FXRuby API Changes”, an entry on Lovable Lyle
- Published:
- 02.15.06 / 4pm
- Category:
- FXRuby
- Tags:
- Post Navigation:
- « The Final Countdown
The Continuing Saga of the Heated Mouse »

Comments are closed
Comments are currently closed on this entry.