I am a programmer, an inventor, a creator of ideas and a dreamer. What are you?

Solution: Nested Classes & Variable Scope (Ruby)

Posted: December 20th, 2009 | Author: Spoofy | Filed under: Articles, Programming | Tags: , , , | Comments Off

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:

parent = A.new
parent.tellme

child = A::B.new
child.tellme

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.


BinaryClock for iPhone almost complete

Posted: July 10th, 2009 | Author: Spoofy | Filed under: Programming, Uncategorized, iPhone Apps | Tags: , , | Comments Off

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:

binaryclockiphone


Progressing onto iPhone Development

Posted: June 14th, 2009 | Author: Spoofy | Filed under: Programming, Website | Tags: , , , , , | 1 Comment »

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:

iPhone-Apps

* Concept utilises an image by Buster Brenson


DevDays 2009 iPhone Developer Workshop

Posted: April 18th, 2009 | Author: Spoofy | Filed under: Events, Programming, Technology, Things to do | Tags: , , , , , , , | Comments Off
iphone3g_trioimage courtesy of Apple

[SiliconRepublic] reports that On the 23rd and 24th of April, Digital Circle, in conjunction with the Digital Media Forum and Create Ireland, are holding Ireland’s first iPhone developers’ workshop in both Dublin and Belfast.

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.

read more at [devdays] via [siliconrepublic]


Microsoft Kodu makes programming visual

Posted: February 8th, 2009 | Author: Spoofy | Filed under: Programming | Tags: , , , | Comments Off
programming_ui
Image courtesy of Microsoft Research

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.

You can find out more about Kodu at [Microsoft Research]


Make Courage Wolf Speak!

Posted: February 7th, 2009 | Author: Spoofy | Filed under: Internet, Programming, Stuff | Tags: , , , | Comments Off
Courage Wolf

Courage Wolf (YouTube, Kyle Brady’s Blog) is an internet meme which follows the formula:

  1. Background image of a snarling wolf, starburst background behind it.
  2. Two lines of text, one at the top and one at the bottom
  3. ????
  4. 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.

Make your own [Courage Wolf images] or [download the script]


Imagine Cup 2009

Posted: February 3rd, 2009 | Author: Spoofy | Filed under: Competition, Programming | Tags: , , , , , | Comments Off

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!

Update: there is also an Imagine Cup twitter account: http://www.twitter.com/ImagineCup


AMD releases socially responsible SDK

Posted: January 29th, 2009 | Author: Spoofy | Filed under: Games, Programming, Social Responsibility | Tags: , | Comments Off

toolkitGamaSutra 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.

You can find more about the toolkit at the Games for Change (G4C) website there is also an interactive flash version of the toolkit available.