February 27, 2008

Cape Town Open Education Declaration

Basically I already wrote about this in another blog, it didn't seem to get much attention...

Anyway, now I have my own blog and I can post whatever I want (:D) I'll express some thoughts I have bouncing in my mind...

What is this declaration about?

It's a list of items about the usage of free resources in the education field.

Full declaration text can be found here. Among other things that I'd like to mention from the inititative we can highlight:

  • Promote the usage of free resources such as course materials with open licenses, class programs, textbooks, games, software and other material which support learning and knowledge sharing..

  • Promote the usage of free technologies which facilitate a collaborative and flexible learning, sharing teaching experiences which help educators benefit from their pair's ideas..

A lot of times I see myself discussing about WHY free software works. The people with whom I discuss (in a constructive way, of course) sometimes think "hey, I'm trying to make an idealist stubborn change his mind", might be, I really don't know. What I do know is that using open source and free software (which by the way, are very different) and free license schemes (i.e. non-software material distributed under licenses which allow sharing, modifying and redistributing it, e.g. Creative Commons) allow to build a more agile and flexible interchange, useful for the community and for future generations.

From the educational point of view (which I'm interested in today) It's important to see how this 'sharing' influences our student's education.
Once (a few hours ago...) a friend of mine (which is also an educator that I deeply respect) told me "If you don't let the students write and become authors, they won't read whatever you write, no matter what it is". This is a great point, What would happen if we extend this notion to education and knowledge?

I think that leaving that expositor-like role while we teach is crucial if want to change the way knowledge is transmitted.

Promoting the idea of free resources and not privative (I repeat, I'm not talking exclusively about software) collaborate in building a different type of mind openness.

To close this post, I hope you could understand what I wanted to say, and feel free to go deeper inside free teaching resources.

Here I leave some interesting links about topics which I have just mentioned and others that I haven't.

Open education initiatives: A list of Cape Town - related inititatives.

Creative Commons.

Free Software in Wikipedia: Some history and explanation of the term.

Free Software Foundation: That.

Pagina de R. Stallman

PS: Please note that English is not my primary language, feel free to read the original Spanish version of this post here.


February 21, 2008

RFC: Traits for PHP

Reading PHP-internals list (http://news.php.net/php.internals) I found that Stefan Marr sent a very interesting patch.
It's an implementation of Traits for PHP.

But what does Traits stand for?

Traits are basically Behavioral Blocks which group functionality (they group methods / functions indeed).

Depending on which programming language we are keen on we are used to dealing with interfaces, making our object hierarchies implement these interfaces. For example:

Interface TheInterface
   public void method1();
   public int method2();

interface TheOtherInterface
   public void methodA();
   public int methodB();

class TheClass implements TheInterface, TheOtherInterface
   /* Here all methods corresponing to both interfaces
     * should be implemented

But what happens with object hierarchies? Sometimes we have to choose between an elegant OO design, loyal to all the OOP concepts that we know (wtf?) like Encapsulation, Inheritance, Abstraction, Polymorphism (I really don't remember anything about these, I only know how to apply them..) that adequately represents the problem we want to model, OR, make a very nice and reusable code, not paying (too much) attention to best practices and principles of OOP...

So we have class hierarchies where classes extend other classes, creating complex families, with parent and child clases with inherit some of their parents' methods, with different access permissions (protected, private, final, sealed, etcetera, depending on the programming language...)

But sometimes, we have functionalities we would like all the class families to enjoy, for example: If we want all the families to know how to cook an asado, wherever they were born since they live in Argentina like me:

Let's consider this example:

We have a (not very useful) hierarchy, which models families of different origins. All the families have a surname and know how to procreate.
So families know how to cook different types of food, depending on their origin. The italian know how to cook pasta, risotto and canoli, japanese are expert sushi cookers and sake drinkers. We, the argentinean, know how to cook asado, drink mate and going to the cancha (soccer stadium), but not me... I don't go to the cancha.

It would be great if any family living in Argentina know how to cook asado and drink mate... So we can build a small "package", or Trait with different abilities, for example:

trait ArgentineanFood
   public void cookAsado(){
     // code to cook asado...
   public void drinkMate(){
     // code to drink mate...

So we could have a class like:

class ItalianFamily
   use ArgentineanFood;
   public void cookRisotto(){...}
   public void cookPasta(){...}
   public void cookCanoli(){...}

And easily have an italian family which knows how to cook and consume argentinean food, weird uh?? (I have to say that most of the Argentinean population has italian origins...)

I like to think that this is a way of crossing the hierarchy in an horizontal way, I try to explain this on the class diagram (click to enlarge):

Traits for PHP

There are lots of details to deal with. For example name conflicts. What happens if two traits have methods with the same name? who resolves this?

In this first implementation there is no conflict solving. In fact, traits are "flattened" inside the code of the class. The decision of which trait wins the conflict is left as a programmer decision.
We could do things like:

class Talker {
    use A { !smallTalk }
    use B { !bigTalk }

Where the Talker class has methods from traits A and B but exludes the method smallTalk from trait A and bigtalk from trait B. We can also rename trait methods while using it in a class.

One advantage we can find in this implementation is that it hasn't any runtime penalty, since its like a formal way to copy n' paste code.

I recommend you read what this guy Steffan wrote, everything for the PHP implementation is clearly explained.

Ok, so I quit writing not to bore you. I hope you could understand everything I wanted to share.


Further reading
Read here.
more on traits here.
Or you can read Nathanael Schäarli's Thesis.