Sunday, 21 June 2015

OrderBy vs Max

Some days ago I came across a piece of code by one colleague that caught me quite by surprise. He told me it was a performance improvement, and while in that case it was rather unnecessary and made the code less straight forward, it's good to have it in mind for other occasions. The idea is pretty basic, but I had never though about it before.

The example was in C# and Linq To Objects, so I'll stick to it, but it would be the same with JavaScript and underscore.js or whatever.

So we have a collections of City objects like these:

public class City
{
 public string Name {get; set;}
 public int Population {get; set;}
}

var cities = new List(){
   new City(){
    Name = "Xixon",
    Population = 275000
   },
   new City(){
    Name = "Berlin",
    Population = 4000000
   },
   new City(){
    Name = "Toulouse",
    Population = 1250000
   },
   new City(){
    Name = "Paris",
    Population = 12000000
   }
  };

and we want to get the most populated city. So I would just do this:

biggestCity = cities.OrderByDescending(city => city.Population).First();

while my colleage had written this:

var maxPopulation = cities.Max(city => city.Population);
var biggestCity = cities.First(city => city.Population == maxPopulation);

In the first code, regardless of the sorting algorithm used by OrderBy, we can say that you are finding the Max element n times (each time in a smaller collection), while in the second example you are finding that Max only once. Depending on the Sorting algorithm the first case will usually be O(n*log n), while the second case is O(n). As explained here, apart from the speed improvements, with the OrderBy approach you'll run into an Out of Memory exception if your collection is huge enough.

Saturday, 13 June 2015

The void Operator in JavaScript

The other day, while checking the source of underscore.js (I already mentioned time ago that it was a really beautiful code to learn from) it came to my attention some code like this:

return obj == null ? void 0 : obj[key];

That void operator, what is it useful for? (both in general and in this particular case). Checking in MDN, for this particular use you'll find this:

The void operator is often used merely to obtain the undefined primitive value, usually using "void(0)" (which is equivalent to "void 0"). In these cases, the global variable undefined can be used instead (assuming it has not been assigned to a non-default value).

So it's being used to safely assign the undefined value. "safely" means that when we use undefined this way: obj = undefined; you are using the undefined global property, that by default points to the undefined value, but that someone could have changed assigning it another value and breaking your code!

However, if you run this code in firebug:

var a = undefined;
undefined
a === undefined;
true
undefined = "xxx";
"xxx"
a === undefined;
true

You'll see that indeed the attempt to change the value of the undefined property has not worked! As usual, MDN has the explanation:

undefined is a property of the global object, i.e. it is a variable in global scope. The initial value of undefined is the primitive value undefined.
In modern browsers (JavaScript 1.8.5 / Firefox 4+), undefined is a non-configurable, non-writable property per the ECMAScript 5 specification. Even when this is not the case, avoid overriding it.

The reference for the void operator mentions another use case that really confused me:

When using an immediately-invoked function expression, void can be used to force the function keyword to be treated as an expression instead of a declaration.

So they propose creating IIFS's like this: void function(){}();
I see no use at all in creating an IIFE like that. I pretty much prefer the "normal style":
(function(){}());
or
(function(){})();
Using void adds nothing other than confusion and it looks to me as if we were in another language declaring that the function returns nothing.

Trying to understand if I were missing something with this I checked what seems to be the seminal article about IIFE's. There the author mentions some other utterly confusing ways to declare a IIFE, like these:

// If you don't care about the return value, or the possibility of making
// your code slightly harder to read, you can save a byte by just prefixing
// the function with a unary operator.
!function(){ /* code */ }();
~function(){ /* code */ }();
-function(){ /* code */ }();
+function(){ /* code */ }();

As the author says, it makes the code harder to read, for sure. I love how expressive and freak javascript is, but things like this seem utterly unnecessary to me.

Sunday, 7 June 2015

International Brigades 2.0

Volunteers have been joining the fight against the Fascist Beasts of ISIS in Syria and Irak since last summer. First volunteers came from USA and UK mainly, some of them had militar experience and were joining the battle in a Good vs Evil basis, to defend ordinary men and women from being decapitated, raped, tortured and sold as slaves by the Islamist terrorists. Most of them did not have a left wing ideology, and indeed some of them ended up not feeling comfortable being integrated in a left wing force like YPG-JPG and decided to move to other "not red" groups, like some Christian militias or the Peshmerga.

Since the MLKP (a communist Turkish-Kurdish revolutionary vanguard) made a call to join an International Brigade to fight against IslamoFascism and support the Social Revolution in Rojava, a new kind of western volunteers showed up, these ones with a clear left or far-left ideology. It's unknown how many foreigners make up the ranks of this left wing militia (notice that most foreign revolutionaries there are Turkish-Kurdish Communists and Anarchists), but for sure they have had a certain media impact, and have helped a lot to bring to the table of the European left the drama of the Kurdish people and the need of Antifascists to confront IslamoFascism in the same way they confront "White-Nationalist-Fascism".
I already talked about the German revolutionary Ivana Hoffman, sadly fallen in combat against the IslamoFascist scum, and already in February a video was released portraying 2 Spanish Revolutionaries in Rojava, along with German and Turkish ones.

I had not known much of these humanitarian fighters until today, when through the site of the Comite de Solidaridad con Rojava y el Pueblo Kurdo I've found this documentary by a Spanish TV Channel about the Spanish Revolutionaries there. Unfortunately it is in Spanish, but even if you can not understand the language, the images are well worth your time. From this video I learnt that these Spanish guys are members of the Marxist-Leninist organization Reconstruccion Comunista (Communist Reconstruction) a very militant group putting a huge emphasis in the political education of its members. Knowing this, it's clear that these guys have not been drawn into this battle just for a quest of adventure or a youngster impulse, I assume that they are educated left wing militants taking a reasoned and consequent decision. They had previously done some interesting declarations to other Spanish media. As I'm linking an article in "El Pais" I need to clarify that I feel rather little respect for this Paper. It has its own agenda dictated by Spanish oligarchy, which makes it painfully partial when dealing for example with topics related to South America (Venezuela, Cuba) where this oligarchy has neocolonial interests and attitudes. In no way can it be considered at the level of European real papers like "Le Monde".

This is not a fight against Islam, but for peaceful co-existence between different cultures, and not just in favor of the Kurds, but all humanity. We cannot accept simplistic arguments that Islam is to blame. We are not fighting against Muslims, but against the fascism that Islamic State represents, in the same way that people fought in Spain in 1936 or in Stalingrad in 1943.”

By the way, these pictures of their organization, Reconstruction Comunista, quite impressed me. I'm quite far from some of their political positions, as the concept of "class war" is now totally alien to someone like me that to a certain extent has ended up in the moderate, "System changing but not System breaking" left, but the way they parade through the streets of Madrid, baring communist and republican flags in an almost military formation is really captivating. It gives a sense of discipline, organization, power and willingness to fight that is now more necessary than ever. At these times when the fascist monsters carrying the poison of radical islam or xenophobia and racism are more alive than ever in our old continent, the left must be ready for confrontation, a confrontation that goes far beyond dialectic and keyboards.

Honor and glory to Antifascist fighters

Saturday, 30 May 2015

Monuments to Horror

Every time that I say that I'm going to Paris, Berlin, Marseille, London... someone will say: "again? but if you've been there many times". Well, it's a reasoning that I can not understand. If I like a place, I like to go back again and again, both because I want to repeat the experiences and because these experiences are never the same. If you like a certain food or music you want to taste it again, you don't get tired of it unless you taste it too often, the same happens to me with places. Furthermore, cities like the ones I've mentioned have so many things to see and do that I bet you could spend several lifetimes visiting them and you would not get tired (and in this kind of dynamic, ever evolving cities, you'll always find something new).

Last weekend in Paris I came across just by chance with a beautiful sculpture paying homage to the victims of racism and antisemitism during WWII in France.

The words on the monument read:

"The French Republic in homage to victims of racist and antisemitic persecutions and of crimes against humanity committed under the authority of the so-called 'Government of the State of France.'"

You can read more about this topic here. Obviously the different French governments have never had any problem acknowledging and condemning the disgusting role of the Vichy fascist and collaborationist government in WWII, pretty far from what happens with Spanish governments when it comes to admitting and denouncing the horrors of Franco's dictatorship. France is France, and Spain is ...

This monument reminded me a lot (particularly the small girl playing with a toy located right in the center) to the monuments in Berlin's Friedrichstraße Station and London's Liverpool Street Station to the Kindertransport to rescue kids from Nazi occupied Germany. I have particularly fresh in my mind the one in Berlin:

A plaque on it reads: "Trains to Life, Trains to Death". Its portray of kids with their baggages and toys marching towards hope or horror is devastatingly powerful and emotional, and ever that I pass by it I can't help but stopping for a while and plunge into some moments of reflection. You can check these pictures to get a better idea.

Wednesday, 27 May 2015

Expat vs Inmigrant

Words, can be beautiful, can be painful, too often we just use them without really thinking twice about their real meaning, about what they sometimes subtly hide. Expatriate (expat) is like a cool world now. I think I've used it occasionally, even to refer to myself. I think the first time I gained contact with this term was through some friends that had moved to Switzerland and were in an 'expats forum' to find people to meet (seems like many Swiss nationals tend to be a bit 'particular' about foreigners and it's quite unlikely that you will manage to socialize with them). The term has gained a lot of traction, so well, if you move to another country to work, you are an expat.

But, this situation has existed since the first time humans came up with the concept of 'countries', so in the past we used a different word, immigrant. But, hey, we still use this word today, and seems as if for just the same, people that move to a new country. So one could think that they are synonyms, but for sure they are not, we don't use them as such, they are not used interchangeably.

You could say that maybe expat is more like a temporal move, it's false, it's used by people that have been living abroad for many years, and furthermore in many occasions when you move you do not know for how long, life is to complex for that kind of certainties. Also, it has nothing to do with whether you are moving inside the Schengen Area, cause USA and Canadian citizens are expats, but Polish people, Romanians or Bulgarians are usually immigrants. It's not about qualifications either, some European high school drop outs move abroad to be expats, some African, south American, Asian... university graduates are immigrants. So it seems like both words establish a difference, there are 2 types of people that move abroad. It seems like expats are cool, they are there to help the country, they are valuable, they should be welcomed, they should not be randomly questioned for their ID by the police. Immigrants are not so welcome, they 'steal' jobs, they do not integrate, they take advantage of the social system, they scare people. Expats come by plane, immigrants sometimes too, sometimes by bus, sometimes by patera, sometimes die in our coasts or are received with hits and hate from the police. I think all this stinks somehow like racism and xenophobia. Expats are like us, immigrants are different. Us versus Others, the same rotten misconception that has always led us to disaster. I even think expats can be against immigration, both in their own country and in the new one, cause in the end they don't consider themselves immigrants.

So yes, expat is a perverse term, I don't like it. I will never call me an expat again. I am an EU citizen, I'm white (well, Southern Europe 'Olive' skin) and have a University degree, but from now on I am an immigrant, like the Cameroonian or Moroccan people that work with me. We are equally integrated and equally contribute to this country (indeed, they pay French taxes while I still pay Spanish ones).

Actually, I think the (*)migrant term itself is confusing, more properly, it confuses. There's a nomadic nature in human beings. There's a constant (or there should be), change, evolution. You move from one kind of music to another, from one kind of films to another, from one clothing style to another, from one place to another, life should be a journey of discovery in all of the infinite aspects that make up the human nature. Furthermore, when do you stop being an immigrant? If you have lived more time in the new country than in the original one, you are still an immigrant? does it have to do with getting the nationality? Again, I think the term is terribly confusing, we are just nomads wandering in a sea of confusion.

Thursday, 14 May 2015

Garonne

If some days ago someone had asked me "hey, have you seen that beautiful fountain representing la Garonne and its four tributaries?" I would have said: "hum, I think there's nothing like that in Toulouse" (obviously as I tend to walk along its riverside several days per week I firstly associate la Garonne with my city). Then I would have thought about Bordeaux and said, "I don't think the astonishing set of sculptures in Bordeaux depicts la Garonne". When my questioner had told me "no, no, I'm talking about Lyon", I would have quite laughed loud and said "come on, learn some geography, it'll be a tribute to the Rhone or the Saône then".

He would have to show me this Wikipedia article to convince me that such incredible sculpture in Lyon (by the way, I had no idea it had been made by the creator of the Statue of Liberty) has anything to do with a river totally unrelated to that city. The French wikipedia article says:

Elle représente la Garonne et ses 4 affluents.

Reading the article you'll find that it was initially designed for Bordeaux, so the thing makes sense. However, the English article reads:

The fountain depicts France as a female seated on a chariot controlling the four great rivers of France.

So I guess when Lyon's city council decided to buy the statue they had to adapt its meaning to fit its final host, and well, the idea of the 4 rivers of France (Rhone, Loire, Garonne and Seine I guess) is a pretty valid explanation.

This short post is a nice excuse to publish this pic I took this winter in Prairie des Filtres, the so cute and charming river park of Toulouse

and also this night shot taken from Bazacle

Wednesday, 13 May 2015

Lyon et Marseille

It's right now one year and a half that I've been living in Toulouse. In this time I have paid 3 visits to Lyon and 3 visits to Marseille (both of them are 4 hours far from Toulouse by train, so it's worth going there even just for a weekend). The 2 cities are really extraordinary. In the first visit to each of them I started a post in the train when travelling back, but would not get back to it until the next trip. In the end I have 2 large but incomplete posts that I have serious doubts I will manage to finish (there are millions of things to write about these cities), so I've decided to just write several short posts about different aspects of each city. This post today is just the kick off.

I'll draw comparisons between both cities and Lisbon. Well, our present perception is a product of our previous experiences, Lisbon happens to be the first city I was where hills and view points (miradouros) have such an essential presence, so since then I guess every city that I visit where hills are pretty manifest reminds me of Lisbon (for other people it'll probably be Rome). Lyon is like a Parisian Lisbon and Marseille feels to me as if you had sprinkled part of Berlin's spirit over Lisbon. Sounds promising? well, it's even better.

Lyon is so absolutely beautiful that I would dare to say that it plays in the same league than cities like Vienna or Prague. OK, yes, a few points below, but in the same "premier league". By the way, it's pretty odd that I do this kind of football comparisons when I deeply dislike that "spectacle" for many reasons: capitalism at its worst, far-right hooligans, sparking rivalry between people, opium of the masses...) Its natural setting is hard to beat. The city center is caressed by 2 rivers, the imposing Rhone and the so cute Saone, in such a way that you feel as if you were in an island (indeed it's called Presqu'ile (peninsula, but literary "almost island"), and to both sides you have 2 beautiful hills. The old town is really nice, but what I particularly love is the "classic center" with that incredible French architecture that will make you feel in Paris. The so lovely and picturesque Croix Rousse is the part that so much reminds me of Lisbon, and if you long for Modern Architecture, La Confluence will fully quench your needs.

Marseille is probably the most underrated city that I've been to. I mainly knew it as Keny Arkana's hometown and as one of the most dangerous cities in Europe. Please, don't be freak out, sure you have to exercise some more caution than in other cities, but there's no reason for paranoia (OK, understand that in my case I could pass as a local, both for my phenotype, that can make me look as the son of an "original" French and an Arab, and for my "dress code"). The natural framework is hard to beat, enclosed by the sea and some imposing mountains, with 2 forts guarding the entry to the old port, and with the Count of Montecristo Island right out of the coast!. The architecture goes from the delightful decadence of Noialles to the French glamour of La Joliette and Republique, passing by some outstanding new museums. If you were amazed the first time you visited Sacré Coeur in Paris, you'll be fascinated by La bonne mere, the mesmerizing Neo-Byzantine church that overlooks the city, and that on one side offers astonishing views of the sea and the mountains, and on the other side is such an incredible view from the Old Port.
You like street art? Marseille will make you feel in Berlin, indeed I think Marseille is so "cool" that it could end up being a hipster paradise.

OK, I better stop it here and leave room for that series of posts about these 2 cities that I can envision now.