Friday 29 July 2016

Getters and Setters not Needed

Since I first learned of property descriptors in JavaScript I've had a certain feeling of guilt. Let me explain. In .C# the good practice is to use Properties for the access to any kind of public data (not only for "processed data": calculated, filtered, logged..., but also for just trivial data fields). We do the same in Java with get/set methods. I mean that in C# we write:


public string Name { get; set; }

//this automatic property is syntax sugar for:

private string name;
public string Name
{
 get{
  return name;
 }

 set{
  this.name = value
 }
}

So one would expect that we would write code in JavaScript like this:


var person = {
    get name() {
        return name;
    },
    set name(newValue) {
        name= newValue;
    }
};

//or like this

Object.defineProperty(person, "city", {
   get : function(){ return city; },  
   set : function(newValue){ city = newValue; },  
   enumerable : true,  
   configurable : true});

but I think nobody does this, so why? are we doing something wrong just out of lazyness?

No, we are not doing anything wrong, it's just that JavaScript is a different beast, and what is necessary in C# or Java is useless in JavaaScript. The reason for using properties even for just data fields is to isolate calling classes of changes in that class. If in the future that data field needs to be calculated or some additional checks need to be done, changing from a data field to a property will break the customer class. If it was in a different assembly, we'll have to compile it again. This is clear in Java, where a getter/setter is just a method, but it's the same in C#, cause a property is transformed by the compiler in one (or two) method. Changing from a data access instruction to a data retrieving or setting method invocation is a breaking change in a static language. So, using properties makes our code resistent to change.

In JavaScript this is not a problem. First, everything gets interpreted/jitted each time the program runs. Second, even if during the execution of one program we decided to replace a data field with a data accessor property the flexibility of the runtime will allow us to do so. Assuming the code accessing that datafield has already been jitted, it will have to be replaced by the jitted version of the new accessor descriptor invokation, which will have some performance impact, but I guess it should not be a problem.

So, feel free and happy to not use data accessors when all we need is a data holder.

Sunday 24 July 2016

Rose Beton

Dans les derniers temps la maire de Toulouse s'a engagé à promouvoir le Street Art dans notre ville. Le dernier automne des murs du centre-ville ont été embellis par des artistes bien connus. Le projet continue à avancer, et cet été nous pouvons bénéficier du festival Rose Beton

Le projet a eu la très bonne idée de prendre le street art à l'intérieur du musée (Abattoirs), ce qu'est une bonne facon de lui donner la reconnaissance qu'il a manque pendant longtemps. Mais bien sûr que le lieu pour le street art c'est la rue, et donc le rose beton a pris les murs de Toulouse aussi.

I've leveraged one Sunday afternoon to visit most of the street works of the festival, "Les murs dans la Ville" (I have a few of them missing yet). While some of them were not too appealing to me, there are 2 that just delighted me.

The wall done in Empalot by HENDRIK BEIKIRCH is just amazing. The painting is beautiful, powerful and massive, but the choice of place is even more astonishing. The contrast between the work of art and the horrible building on which it lives (that's one of the ugliest buildings I have ever seen in a first world country) is shocking. Empalot is a "second degree" quartier sensible. It means that it's not the best place in town to live, but it's not a warzone were the police is stoned from the windows and attacked by mobs of criminals (like Le Mirail or some suburbs of Marseille) or where the Islamists reign and spread terror (some Parisian suburbs). Indeed, the neighbourhood has a certain charm (I was about to move to a flat in a nearby zone, so I rather checked the area to make sure it was still an area "controlled by La Republique"). I would say it's more like a multicultural place than a communitarist hell. Years ago many of the buildings got their facades revamped and part of the area looks a lot like the suburbs of Easter European cities. Now the city council is carrying out a redevelopment project to tear down some of the worst buildings and build new ones, trying to leverage the excellent location (next to the river and its exensive green area, 10 minutes far from centre-ville by metro) to entine new population to the area. The building where this work lives is one of those that will be torn down (a similar one has already been demolished) so unfortunately this piece of street art won't last for too long.

The other work that I've found pretty beautiful is one located rather close (1 metro stop), in St Agne. It's the result of a collaboration between French artists Monde and Maye.

Thursday 14 July 2016

Reflect.get

The other day when checking the Reflect API in ES6 I found something that seemed a bit strange to me, the receiver parameter that you can pass to Reflect.get(target, propertyKey[, receiver]) . The explanation says:

The value of "this" provided for the call to target if a getter is encountered.

Notice also that when you do a Reflect.get of a "getter" (accessor descriptor), the getter itself will be executed rather than returning you the descriptor.

So if you don't pass a "receiver" the "this" passed to the getter will be the "target", else the "receiver". The logic behaviour for me is the former, that "target" is used as "this", why would I want to pass a different object? Well, after some thinking I realised this is useful for proxies and what I posted about some time ago, using the proxy for internal calls vs using the proxied object. So if you are proxying the access to a getter and then you want that the actions in that getter also go through the proxy, you'll pass the proxy as "receiver". One first thought was that you could end up with some kind of recursion, but it's not like that. Reflect.get(target, propertyKey, receiver) will do a target.propertyKey to get the getter, and then invoke the getter with "receiver" as "this", which is quite different from doing a receiver.propertyKey, that with a proxy would cause recursion. If your getter is calling another getter and so on, in the end one of those getters will be just calling a data descriptor, so the proxying will end.

With all this, I've put a sample with 3 ways to proxy your method/property access. One that will not go through the proxy for internal calls (neiter method nor accessor descriptors), another that will go through the proxy for internal cases for both of them, and finally one that will do it for methods but not for accessors. You can check the code here.

A reminder regarding method calls. Method calls in JavaScript involve 2 actions, getting the function (so if proxying the get trap gets called) and then doing a call to the returned function passing as "this" the object on which you did the "get" (so if you are using a proxy, the proxy will be passed as "this" to the function, this is important for cases 2 and 3 in my sample)

Sunday 10 July 2016

Elle

Elle is an amazing film. A drama/thriller telling an imaginative and unconventional story. As important for me in the so pleasant experience that this film has been is the setting. Having an exciting job that allows to live a wealthy existence in Paris, inhabiting a gardened stone house (with those wooden shutters protecting those large windows)... buff, such a scenario mesmerises me.

If the setting is that great, the main character (with the superb performance of Isabell Huppert) is even more. A mature, sensual and powerful "femme d'affaires" that seems hardly affected by her horrible rape. The fashion in which she accepts one of the worst horrors that a woman can face is shocking and at the same time a bit revolting, as in a sense it seems to diminish how hideous such act is. Little by little the complicated history and personality of this woman unravel. The film revolves around the dangers and complexity of family, social, sexual and power relations, and does it astonishingly well,. Furthermore, it adds a few absolutely hilarious moments (not stupid humour, but the kind of comic situation that can come up at any moment, regardles of the seriousness of the time.

I could draw some similarties with Demonlover (another French masterpiece) and perhaps with Red Road. I first watched these films in the cinema, and I think films watched in the cinama keep a particular place in my memories and ranking.

The film is shot in French, but I was lucky that The American Cosmograph planned a session with French subtitles, that though intended for people with hearing disabilities, comes pretty handy for idiots like me that will never manage to understand spoken French. "désolé, je peux lire la Français sans problème, mais je ne comprends pas bien quand les gens parlent" is one of the few sentences that after so much repeating it I've managed to master its pronunciation)

Friday 8 July 2016

Brexit

First I'll start with one apology to some potential reader. If you are a British person that voted against the Brexit, sorry for all the disdain, contempt and even hatred that I'm going to express in the following paragraphs, but I guess you'll share with me such disdain for the bunch of assholes in your country that voted for this shit. My main feeling for England and Wales right now is "go fuck yourself".

So UK is quitting the European Union after a mass of ignorant, xenophobic (big part of the "exit" campaing was based on plain xenophobia) assholes decided so. As a convinced and proud European I consider this quite tragic, not because of the future of UK, that after this exercise of collective stupidity I quite don't care, but because other assholes in continental Europe will intend to follow their example. I would hope that populations in France, Italy or Holland will be a bit more smart, but well, I have little trust in the masses, people tend to follow the most stupid leader and swallow the most stupid ideas, as has happened in England and Wales.

I used to go to London once per year, as in the past it used to be my favourite city. Hopefully in the last years I've come to find cities like Paris or Berlin way more interesting than London. I've also been moving away from any sort of anglophile feeling. The country has been all these decades much more a servant of the USA than an European college. Over time this fact and many others (I'll list just a few) have caused on me a deep change in my feelings for England

  • Ridiculous idiosincracies like being proud of having a Queen
  • All this looking down on France or Belgium because of our problems with bad neighbourhoods and radical Islam, as if England had not just the same problems
  • The continuous stigmatization of immigrants as guilty of ruining the social system, when there is a mass of "aboriginal" English population that lives off the state doing nothing. How many times have you seen a "white skinned English person" working on a fast food restaurant or other badly paid job? At least in the past it was fairly uncommon, as they could get that same shit salary from the state.
  • Their crappy educational system (one of the worst in Europe) producing a mass of uneducated youngsters
  • The unionist/loyalist bastards in Northern Ireland seem almost that smart and fanatic as any redicalized muslim.

I'm not much sure of how many "made in England" products I've bought in the last years, but after this act of stupidity, given that England is no longer "one of us", I think I'll try to keep it to a minimum and benefit other countries. Likewise, I don't see myself visiting London for leisure/tourism with the regularity that I did it in the past.

In many ways UK has been an obstacle to a true European integration, so indeed I think we will be much better without them, the important thing is to use this as an opportunity to strengthen the unity of European countries and to reinforce the position of Europe in the geopolitical space. The joy of Trump after the Brexit reminds us once again that USA is not our friend. This Trump shithead is happy before the prospect of a broken Europe, so that he will be able to mangle with separate small governments, we have to be strong and do just the contrary, a strong Europe that will remain the vanguard of civilization and individual freedom, versus the other backward big powers like USA, Russia or the Islamofascists (Turkey, Golf States...)

Among the measures to put Europe back in the map one of the most important should be the creation of a European Army so that we can break away from NATO and take our own decisions as main players in the geopolitical arena. Another main step is abandoning the senseless idea of approaching Turkey to Europe. This islamofascist and genocidal democratic dictatorship has nothing to do with our values, and should be counted as an enemy, not a friend. The integration of other ultraconservative and nationalistic societies, like Ukraine, also has to be abandoned. The EU must be a selected club of progressist, advanced, liberal societies (so yes, there are countries like Poland, Hungary or the Baltic states that probably should not be in this club).

I hope that many companies will move part of their businesses (headquarters, research facilities, even factories) from England/Wales to the rest of Europe. Maybe then some of the idiots that voted for the brexit will feel so much contempt for Cameron, Farage and Boris Johnson as I do. I also hope that Scotland will break away from UK as soon as possible and Ireland will finally be reunited (and all the loyalist idiots kicked into England and join the masses of "pure-blood Brits" that live off the state :-D