Sunday 25 September 2011

From Resistance to Revolt

After several attempts over the last years, finally last month I managed to find for download the 2 CDs that make up the whole discography of one of my favorite hardcore bands of the 90's, Manifesto.

One million thanks to this blog for making them both available for download here

  • Un mundo que ganar, unas cadenas que perder (A world to be won, some chains to be broken)

  • De la Resistencia a la Revolución (From Resistance to Revolt).


Manifesto was a socialist hardcore band from Barcelona, active I think roughly between 1994 and 1999. Most of their work should be classified as what at the time we called New School Hardcore (I've been so cut off from that scene in the last decade that I don't know if this term is still much in use), something in the vein of Earth Crisis, but their best songs (well, at least my total favorites) are some very fast tracks that appeared in their 7 inch "El arte de la insurrección", rather reminiscents of Man Lifting Banner. These songs also have some of their best lyrics.

Some of their uncompromising socialist (of course we're talking about Marxism/Communism..., not about socialdemocracy) statements are now more relevant and up to date than ever, even when I rather disagree with all the "class fight" stuff (just because on the contrary, it seems like a pretty outdated concept in our world of Megacorporations, outsourcings...)

My favorite song in terms of sound is also my favorite one in terms of lyrics, "En este Sistema/In this System"
Here's my broken translation from Spanish:

Free Market, economic anarchy, cut after cut. Accumulate is the new Bible. Production that ignores human needs. Profit is their only sacred law. Health System, Education System, social services. Always questiones, always under attack. We have no control over what we create. We can't decide what to use it for. Judges, parliament, structures designed in this System. Army, Police, created to protect their profits. In this System we ever lose.

As you can see, in our current Europe, where all sort of funding cuts are being conducted, those lyrics seem more relevant than ever, and make us realize how the foundations of our Western civization (universal health system, education system) seem to crumble.



A fun note now, the cover for this CD seems a bit odd for such a political band. I mean,Casa Milá is a superb building, but neither the building nor the architect have any political significance, so how does it match with the Socialist ideology of the band?. Well, it's pretty fun, one of the band members told us back in time that there was a huge demonstration due to pass by the building, so they hired a photographer to take a pic from one of the buildings across the street. The thing is that they got too late and the demonstration had already passed... but anyway they took the picture of the empty street and used it for the cover :-)

Lyrics for "De la Resistencia a la Revolución":



Saturday 24 September 2011

Destructuring Assignment

I've been keen of Rhino since the first time I knew about it, many years ago. At that time JavaScript was not by far the popular language that it's now, and being able to run a JavaScript shell and do some of your normal coding tasks with it was not in most people's agenda (for example just think that 95% of the WSH samples that you find on the net are VB instead of JavaScript).

Today I paid a visit to their site to see if there was something new, and to my delight I found version 1.7R3 there. I immediately jumped to the "What's new" section, and from there to the JavaScript 1.8 section. And there I found one of those brilliant ideas that once you come across them think how it is that humanity has lived for so long without them :-)
Changes in destructuring for..in

I've known the concept of destructuring assignment since the times I used to do some Python coding, it's a simple and powerful idea that I though only applied to function returns and swapping values

var [a, b] = function(){
return ["val1", "val2"];
};


so when I found this destructuring for..in thing it really caught my eye. I was not completely sure of what it mean, so I've done a couple of tests, and it's amazing, you can write code that elegant like this:


var ar = ["a", "b", "c"];
for (var [i,v] in ar){
print (i + ": " + v );
}

var ob = {
name: "Iyan",
age: 30
};
for (var [k,v] in ob){
print (k + ": " + v );
}


If you change "print" for "console.log" and try it in firebug you'll see that it works fine for objects (second sample) but not for arrays (first sample), which appears odd to me as this seems to be part of JavaScript 1.8 and modern versions of Firefox seem to implement it...

Update, 2012/11/25 With the functional style additions to ES5, both cases above can be easily rewritten with the new forEach method in the Array object:

var ar = ["a", "b", "c"];
ar.forEach(function(item, index){
console.log (index + ": " + item );
});
 
var ob = {
name: "Iyan",
age: 30
};
Object.keys(ob).forEach(function(key){
console.log(key + " : " + ob[key]);
});

Sunday 4 September 2011

Passing Anonymous Types as parameters

It's been a long while since my last C# post, so time for a short one.
Some days ago, I'm not sure why, it came back to my mind a question done by a colleague some months ago "hey, I can't pass Anonymous Types to another method?" and my simple answer, "no, you can't".

Well, my answer was rather simplified and outdated, what I really meant was that you can't pass Anonymous types around in a useful way. As the type is anonymous, when you pass it to another method, all you can put in the signature is Object, so in order to get access to any of its properties you would have to use Reflection, and that's verbose and slow.

public static void PrintPersonAnonymous(object p)
{
PropertyInfo propName = p.GetType().GetProperty("Name");
string name = (string)(propName.GetValue(p, null));
Console.WriteLine(name);
}

PrintPersonAnonymous(new
{
Name = "Iyan",
Age = 40
});


Hopefully, with C# 4.0 things are much better. You can declare the parameter as dynamic in the method signature, and then you can access its properties normally. The only problem is that the access is still done via Reflection, but it's the compiler who generates the code instead of you.

public static void PrintPersonDynamic(dynamic p)
{
string name = p.Name;
Console.WriteLine(name);
}

PrintPersonDynamic(new
{
Name = "Iyan",
Age = 40
});



Of course, we all know that dealing with Dynamic objects can be pretty fast if we're using objects that take care themselves of the property access - method invocation by implementing IDynamicMetaObjectProvider, like for example ExpandoObject does.

With what I've just said, an idea comes to mind, converting an anonymous type into a ExpandoObject, something that is pretty trivial (probably the most interesting thing here is that we can get access to a Property of the ExpandoObject using its string name by leveraging that it implements IDictionary<String,Object>)


public static dynamic AnonymousToDynamic(object ob)
{
IDictionary d = new ExpandoObject();
foreach(PropertyInfo property in ob.GetType().GetProperties())
{
d[property.Name] = property.GetValue(ob, null);
}
return d as dynamic;
}


This way we can convert our anonymous object to an ExpandoObject to improve performance.

The source code

Ah, while writing this I found this post where they explain a rather different approach to this same problem.