I recently began work on a Twitter library for Ruby, some already exist -which I didn’t consider, I wanted to develop a library of my own design which took a very object-oriented approach to accessing Twitter, mostly for practice. Because I wanted an intuitive, and for the lack of a better word, ‘logical’ implementation, I decided to use nested classes.
Ruby nested classes are child classes which are defined within a parent class. Unbeknownst to me, Ruby has some interesting quirks when using nested classes. Take for example, a typical class:
class A
attr_accessor :var
def initialize
@var = "something interesting"
end
def tellme
puts @var
end
end
Nothing peculiar here, but lets say we want a child class – for all intents and purposes, a namespace, which doesnt inherit from its parent but does exist inside it:
class A
attr_accessor :var
def initialize
@var = "something interesting"
end
def say
puts @var
end
class B
def tellme
puts @var
end
end
end
What we’re doing here is creating a parent class, A; inside that class we have another class B which is a part-of class A, but is not an inherited child. This is an important distinction, because an inherited child would have their own instance variables – what we have here is a class, A which ‘owns’ B. In theory, B should have access to A’s variables.
Heres a usage example, which you might expect to work:
In theory, we should have the same output, ‘something interesting‘ from calling the tellme method on each class, but no. Instead the child will throw an exception, why? because the instance variable is not visible – it is outside its variable scope. To reiterate: nested classes are outside the variable scope of their parent class.
This is true of class variables and constants. Nested children of a parent class simply do not have access to their parents, unless you provide that functionality programmatically:
class A
attr_accessor :b, :var
def initialize
@var = "something interesting"
@b = B.new(self)
end
def say
puts @var
end
class B
def initialize(theparent)
@parent = theparent
end
def tellme
puts @parent.var
end
end
end
a = A.new
a.tellme
a.b.tellme
This is the solution I ended up using, hopefully this post will have helped you avoid some of the frustration I went through trying to figure it out.
I’m still awaiting approval to the iPhone Developer Program so that I can actually test the app on an actual iPod and iPhone but in the meantime, heres a sneak of what the BinaryClock will look like:
To my great shame I haven’t been updating this blog anywhere near as often as I had once before. Unfortunately I’ve been busy with other more important things, the one of most significance is co-founding The National College of Ireland Computing Society (NCICS) in addition to my usual roles at Atamia and QHC Consulting.
That wont be true for very long as I’ve just ordered a Mac Pro and will be starting iPhone App Development in the very near future… as soon as the Mac Pro arrives in all its 8 Core, 8 GB, Quad Screen, Aluminium glory. Of course I dont need a Mac to design an iPhone App, so I’ll leave you with some tantalizing sneak peaks of some of the Apps I will be developing and with any luck releasing later this year:
DevDays 2009 is Ireland’s first iPhone developers’ workshop, hosted by Digital Circle, in conjunction with the Digital Media Forum and Create Ireland. Catering for everyone from complete novices to experienced hands looking for some extra advice, this free event gives attendees the chance to meet iPhone developers and interact with official Apple engineers.
Microsoft research are developing Kodu (previously Boku), a visual games programming environment.
Kodu is a programming environment which is designed to be accessible by children and adults alike, where you can create games on the Xbox using just the controller.
The core of the Kodu project is the programming user interface. The language is simple and entirely icon-based. Programs are composed of pages, which are broken down into rules, which are further divided into conditions and actions. Conditions are evaluated simultaneously.
Although Kodu is aimed at developing a programming environment for games programming, I think the project presents great promise for human-computer-interaction. Thirty years with computers has given us many technological achievments: wireless communication, gigahertz processors, almost inexaustable amounts of storage, but one thing computer technology has left by the way side is human interface. The interface between the computer and humans is vital, its the way we interact with a device which defines its importance – I personally believe this is why the Apple iPhone is so incredibly popular, it got the human-computer-interface just right. I’d go so far to say even that above all other technologies today, interfaces are where we are going to see the most progress and the most profound changes in our lives.
I believe that this is the way of the future, its projects like this where programming will become mainstream, and with our modern world the way it is – and unlikely to change anytime soon, everyone will at some point want to or be required to do some programming in the future. Text based syntax and grammar restrictive languages such as C++, Java etc require a wealth of knowledge before you can concieve of working with code.
If we could all move to a visual programming medium, where intuition and perception are the rules of the game, computer programming could definitely become a mainstream activity.
Background image of a snarling wolf, starburst background behind it.
Two lines of text, one at the top and one at the bottom
????
PROFIT!!
So I created an object-oriented PHP script which you can use to customise your own Courage Wolf images for… profit? or forums, blogs and/or random internet stuff -whichever comes first.
Its just a basic GD script using PHP, but I needed to brush up on my PHP skills.
The Microsoft Imagine Cup 2009 competition is in full swing, with entries now being accepted for the Software Design Competition. Shameless Plug: I will be participating in team SmartGate.
Students will have until May 20, 2009 to submit their round one application, which consists essentially of a project proposal in which you must document how your team’s entry can use technology to enable a sustainable environment.
To qualify for entry to Round One of the Ireland Software Design Invitational each team must ensure they supply the following:
1. Have registered their team at http://imaginecup.com/Registration/Default.aspx
2. Email the Software Design Template fully completed in all sections – Concept, Application Overview, Architecture Design.
3. Email Sample Code that demonstrates the most compelling part of your application in working form.
4. Please supply extra documentation if the code requires set-up or additional understanding.
If you haven’t registered, I’d strongly suggest you do so immediately. Hopefully we’ll see you there!
GamaSutra reports that AMD has released a toolkit for game developers to develop games which are social-issues oriented. The toolkit, ‘Let the Games Begin: A Toolkit 4 Making Social Issue Games’ proposes to enable game developers games on subjects such as energy consumption, poverty, health, and environment issues.