Monday, 24 August 2015

Solidarite Toulouse - Kurdistan

This last Saturday I came across a demonstration of the Kurdish community in Toulouse against ISIS and their sponsor the Turkish islamo-nationalist government. Indeed I think this demo was prompted by the last brutal attacks and repression exercised by the Turkish fascist state: bombing of Kurdish freedom fighters and civilians, the delivery of Kurdish prisoners to a certain death and torture in hands of Al-Nusra, the rape, torture and murder of a Kurdish female fighter... and the list goes on and on and on. Not that my French language skills are sky rocketing, but once joined to the demo I managed to chant some slogans like:

  • Erdogan assasin!
  • Daesh (ISIS) Terrorists!
  • Kurdistan libre!
  • Solution politique pour le Kurdistan

Obviously I took some pictures:



The organizers were handing out to the passers by an interesting pamphlet explaining this new chapter of Turkish dirty war and violence against the Kurds.







BOYCOTT TURKEY!!!!!!!!

Friday, 21 August 2015

Cyprus

I think many people don't know that Cyprus is a divided (invaded) country, and its capital Nicosia is the last remaining divided big city (along with Jerusalem). Though I quite knew about this situation, watching a few documentaries [1] and [2] on this topic last weekend has really infuriated me. Sure this is fostered by the visceral hate that I have developed lately for Turkey (as a state): the permanent neglect of the Armenian, Assyrian and Greek genocides, their ongoing joint venture to perpetrate a Kurdish genocide and destroy any kind of coexistence among religions (Syria...)

The passivity of the international community towards the Turkish invasion of Cyprus and the ensuing murdering and looting is shocking, not only at that time, but particularly now. With Cyprus being a member of the EU, the whole EU should exercise a hard boycott on Turkey, damaging their economy as badly as possible, putting them to the corner to force their complete withdrawal from Cyprus and strong economic compensations. The EU has just done so with different actors and without a real reason. I'm talking about the economic sanctions to Russia because of the conflict with Ukraine. I've already said it before, basically I don't give a shit about any of those 2 countries. In my eyes they are probably the 2 most xenophobic, utranationalist, racist and homophobic societies in the world (yes, sure, I'm judging them as a whole, it goes without saying that sure there are normal Russian and Ukrainian individuals that abhor their societies as much as I do), so I don't think we should spend any effort with them. Anyway, the alleged "Russian invasion" of Eastern Ukraine can not be compared in anyway to what happened in Cyprus. Russia is supposed to have entered into a territory where most of the population is of Russian descent, while the percentage of Turks in Norther Cyprus before the invasion was pretty lower. Likewise, so called "progressive" forces in Europe seem never tired of remembering us about the drama of the Palestinians, but stay oblivious to the drama of Kurds, yazidis or Eastern Christians being slaughtered by ISIS and the collaborationist Turkish government.

Hopefully I think in the last years the idea of Turkey joining the EU has been losing momentum, and indeed, I think it's just impossible. In principle all EU member states have to agree on a new country entering the Union, and obviously Cyprus will never agree, and I assume that Greece either. I had always opposed to the idea on cultural and historical basis, now it's purely that I can't consider Turkey a civilized country.

As a curiosity, I'll have to admit that Turkey seems to have done one good action in these years regarding this island, they have constructed a rather unique undersea pipe to carry water to the chronically water deficient island (to the Turkish occupied side, of course

We can all wish that with the rising tensions in Turkey (I think they could be on the verge of a civil war between islamo-nationalist scum on one side and Kurds and left-wing Turks on the the other side), some Left-wing Kurdish or Turkish fighter will make justice and get us rid of the current Turkish Fuhrer, that vicious torturer and murderer called Erdogan.

Saturday, 15 August 2015

Bytecodes, ASTs and so on

These pieces of news: [1], [2] and [3] about WebAssembly have made a pretty intereting read. It's not that I am interested in using it, I think 99% of web development projects will continue to be done in an every day more powerful and beautiful JavaScript, but the concept is pretty interesting since a technical stand point.

Being able to write high performance code for the web so that game engines can run smoothly on the browser is cool, but as I've said, I guess few people will ever need it. Having your Browser Virtual Machine running for a same "application" two parsers (one for JavaScript and one for WebAssembly) compiling to a common bytecode language is cool, but nothing new (you've been able since a long while to mix Python and Ruby into a C# application, and the same for Java). What is funny is that in the CLR and the JVM the first citizens were the static, "low level" languages (C#, Java...), and then the dynamic and more feature filled languages (Python, JavaScript, Groovy) were added as second citizens, for the web it has been right the contrary path.

What I find really interesting is that the code written in this "binary format for the web" is not bytecodes, in the sense that is not a set of instructions for a stack based (CLR, standard JVM) or registers based (Dalvik) Virtual Machine, but a bit upper level, a binary representation of an Abstract Syntax Tree (AST). Does this ring a bell? Well, it's just what is done with the DLR languages, that are compiled at runtime into a DLR AST that will be then transformed into .Net bytecodes.

The main performance advantage offered by WebAsm over JavaScript is that parsing this binary AST into bytecodes is way faster than parsing JavaScript. Though quite unrelated, my mind established a link between this and JerryScript, a JavaScript engine for small embedded devices. In the article they explain how they managed to make this engine fit into just 64KBs of memory:

From the perspective of IoT, we only focused on memory footprint.

JerryScript is a pure interpreter in contrast with multi-stage adaptive JIT engines today. So it has no overhead for storing compiled code. Even the parser doesn’t store AST. It produces bytecode line-by-line directly from the source code. For data representation, objects in JerryScript are optimized for size. JerryScript is using compressed pointers, bytecode blocks with fixed size, a pre-allocated object pool and multiple representation of Number objects to achieve both standard compliance and memory optimization. We will keep continue to reduce the memory footprint in various ways.

Friday, 7 August 2015

WPF vs WinForms

I don't like WPF. I've ever found it complex and overarchitectured, with a rather steep learning curve (and most times the VS designer does not seem able to draw effectively a XAML form) . For thin client applications a HTML5 SPA using your favorite JavaScript Framework/toolkit is usually more than enough. For thick clients sometimes is also enough. For those that it's not and for purely client applications you can try some of the HTML5 and node combinations discussed here. Anyway, for business line applications, Windows client applications are still needed and demanded. For those cases, I still would prefer to avoid WPF and stick to Windows Forms, and seems like I'm not the only one.

Sure there are many horribly architectured Windows Forms applications out there, just a continuation of the classical vb5 and vb6 nightmares. Obviously that's not Windows Forms fault, and many people have been developing pretty well desinged WinForms applications. The use of MVC (well, indeed I think it is MVP) demonstrated here is quite similar to what I've used in the few WinForms projects I've worked on.

With this in mind, the other day I was wondering if there is really any advantage in using WPF over WinForms. The resulting "research" did not give me conclusive answers, but made me refresh my poor knowledge of how Windows GUI applications work.

Apart from XAML, the recommended patterns and the new controls, under the covers the main evolution from WinForms to WPF is that WPF uses Direct X for rendering while WinForms uses GDI. DirectX can discharge this drawing to the Graphic Card, while GDI will do it in your CPU. This means that WPF drawing should be much faster that WinForms drawing. However, in principle WPF objects are more heavy than WinForms objects (in .Net terms). You can read more about it in these interesting StackOverflow posts [1] and [2]

One interesting point raised there is:

That being said, if you have a LOT of controls, WPF can actually outperform Windows Forms by a fair amount. In Windows Forms, each control requires a separate window handle, and receives its own message sets. With a lot of controls, this can actually slow things down pretty dramatically.

So in "Windows terms" WPF controls are lighter. But, what does this window handle and messages thing mean?

The most essential feature of any Windows GUI application (either .Net or native) is the existence of a Message Loop. The main thread in your windows application runs in a loop waiting for messages (a click, a timer, a refresh...) and when a message is received it will pass it to the code (Windows Procedure) associated to the affected Window. The notion of what a Window is at that level is quite important. At this level a Window (a Win32 Window) is not just your "normal Window" (with is blue title bar, close button...) but also controls like buttons, combo boxes, edits... you can see it here. They are created with the CreateWindow Win32 function, that is how under the covers WinForms, classic vb, MFC,... create their controls.

Both WinForms and WPF are based on the Windows message loop (it's created and kept hidden from you by Application.Run), but WinForms works much closer to the Win32 reality. Underneath it uses the CreateWindow function in user32.dll for creating most of its controls. In turn, user32 uses GDI for drawing these controls. From here:

User32.dll is a core windows dll used for windowing and other interactive user program tasks. WPF does not use it much.
Windows.Forms is mostly a .net wrapper around User32, and so is still based entirely on GDI,GDI+, and window handles.

WPF uses CreateWindow just for creating "real windows" and then it will create its controls by drawing on these Windows via DirectX (as if it were drawing shapes). As an analogy, think of how html controls work. An html button or textbox looks like its WinForms counterpart, but it's not a Windows Control, but a shape that the browser draws (for example via Cairo in Firefox)

You can verify this by running Winspector and trying to select a control in a WinForms application and a WPF application.

In the WinForms application you can select controls, for example a button:

While in the WPF application the only thing you can select is the "normal Window":

Saturday, 25 July 2015

Set [[Prototype]]

When years ago I first heard about the plans to add classes to ES6 I was terrified they could intend to mutate the language from its Prototype based nature to a standard Class based paradigm. Almost immediately I found comments explaining that the addition of classes would be just syntactic sugar, and these classes would be translated by the compiler into the prototype chains we are used to.

Now that ES6 as a standard is a reality, and hopefully most ES engines will be implementing it pretty soon, it feels like it's time to get ready for it. On one side you can read here how indeed classes are just syntactic sugar.

ES6 classes are a simple sugar over the prototype-based OO pattern.

But furthermore you can read here that a standard way has been added to set the [[Prototype]] (aka internal Prototype) of an Object, by means of the Object.setPrototypeOf(obj, proto) method. We will no longer need to use the non standard __proto__ property, neither for setting nor for getting (as since ES5 we've had Object.getPrototypeOf(obj)).

It's noteworthy though the warning in the MDN about how slow setPrototypeOf can be.

DLR vs InvokeDynamic

I found out the other day that PowerShell 3.0 makes use of the DLR. It came as a surprise, as after the abandonment by Microsoft of the Iron languages, I thought they were setting it aside, just keeping it in the framework but with no plans of using it for anything. Hopefully it's not like that, and I guess the reason for not hearing anything about changes or evolutions in the DLR in the last versions of the CLR is that it's complete enough and there's no pressing need for improvements.

This finding, along with this excellent article about invokedynamic in the Java Platform, made me think again of the differences between both approaches for speeding up dynamic languages in the JVM and the CLR. Last year I had already discussed in this previous article how Java 8 implements Lambdas by means of invokedynamic and generating at run time the classes needed to contain the state of the lambdas, on the other side either C#, Scala and Groovy (at least in the pre-Java 8 times) create these classes fully at compile time.

Let's forget about Java Lambdas and let's focus on the "dynamic performance boosting techniques". Both invokedynamic and the DLR make massive use of runtime code generation, but in rather different ways.

invokedynamic When the JVM interpreter first finds an invokedynamic bytecode instruction, it will call into a bootstrap method and will obtain a CallSite object wrapping a MethodHandle. So the invokedynamic instruction will be replaced by a call to that MethodHandle hosted in the CallSite. This call to the bootstrap happens only once for each invokedynamic instruction found. As the code evolves, the MethodHandle in the CallSite can be replaced by another MethodHandle. Regarding the bootstrapping process, I think this statement I found somewhere is pretty important for its understanding:

"the key thing about invokedynamic is that it's essentially a JVM-level macro that defers lambda translation strategy to LambdaMetaFactory which is a library class."

and from this other article:

Whenever a invokedynamic call site is created in bytecode, it references a so-called bootstrap method for deciding what method should be invoked. A bootstrap method is implemented in plain Java and serves as a lookup routine for locating the method that should be called for the invokedynamic instruction. This lookup is only performed a single time. It is however possible to manually rebind a dynamic call site at a later time.

So the key part now is understanding what a MethodHandle is. Well, it's basically an object containing a "method pointer". So, it's basically the same as a .net delegate? yes and no. In .net we have multiple delegate types, classes that inherit from System.MulticastDelegate. We create (well, since .net 2.0 we normally use the Action and Func ones provided by the Framework) delegate types for the different method signatures that we need. This way, the invokation of a delegate is type safe and fast, as the the type correctness is guaranteed at compile time. In Java we have a unique MethodHandle class, so this type safety is guaranteed differently. The JVM itself knows about MethodHandles, and they are invoked through what is known as a "polymorphic signature", so it allows to call MethodHandle.invokeExact with different parameters in the different call sites.

DLR. The procedure to improve .net as a host for dynamic languages did not entail the creation of any new bytecode instruction or changes to the Virtual Machine, but a rather smart use of existing features like Expression Trees, Delegates and LightWeight Code Generation. This series of posts about the DLR internals gives and excellent explanation. Summing it up, in those locations where a dynamic call is performed (for example through the use of a variable declared as dynamic in C#) the corresponding compiler will insert the creation of a CallSite object and will invoke the delegate referenced by its Target property. So, basically this sounds just very similar to the CallSite-MethodHandle combo in the Java Platform. The CallSite creation in .net is done at compile time and in Java at runtime, so looks like the Java approach has to be more dynamic. Well, not really, the CallSite creation in .net is the less important part, the juicy thing happens at runtime, when depending on what object we really have at that point each time, dynamic code generation is used to create a new delegate (doing heavy use of a cache system) to bind to the CallSite.Target. This is pretty sophisticated and is explained here. I assume the JVM uses a similar Cache and decision system for rebinding the MethodHandle in a CallSite, but I have not investigated about it.

I've read in some places that the JVM approach is better and hence it's better suited for dynamic languages. This is one of those sources. It basically says (I think) that in the JVM when finally native code is generated this can be inlined, but it's not like that for the CLR. Honestly, this is a too advanced topic for me, so I can not say how true and how an impact it really makes. Anyway, if not the best, I think the CLR + DLR have proved to be a rather good host for dynamic languages, and with this in mind (and with all their investment in TypeScript) I'd love to see Microsoft coming up with an implementation of ES5-ES6 for the CLR (like Oracle has done with Nashorn)

Friday, 10 July 2015

Solidarity with Heroes

When a state welcomes back heroes with charges of terrorism one can not feel more than contempt and despite for that state. The 2 Spanish Freedom Fighters that have been risking their lives for 6 months in Rojava confronting that gang of rapists, islamo-fascists and perverts called ISIS have been detained by the Spanish repressive apparatus. You can read about it here and already posted about how the Spanish government exercises its repressive role against far-left militants that had sided with the pro-russian side in Novorossiya. It seems they intend to use the same charges against these 2 Humanitarian Fighters, "joining a terrorist organization", and "putting at risk the interests of the 'Spanish nation'"...

Both accusations are demented and delusional and prove how rotten the Spanish government is. Considering the YPG/YPJ as a terrorist group is like saying that being vegetarian is a crime against humanity... The second accusation "risks for the interests of Spain" is particularly stupid, as it indicates that the Spanish government acknowledges the links between the Turkish state and ISIS. I assume that the Spanish government does not recognize ISIS as a state. So, which other states we have there?. Irak and Syria? Both of them are fighting against ISIS (OK, yes, Assad is against the Kurdish liberation process, but I guess that's not a concern for the Spanish government). We have one country left, Turkey. Oh, yes, we all know that Turkey and its IslamoNationalist government are big allies of the West... (sick world). For sure the Spanish government does not want to irritate Erdogan, that friendly murderer... So, what we can deduce from this is that they admit that fighting against ISIS can irritate Turkey, and hence there's a link between ISIS and the Erdogan beast... Thanks Rajoy, you are admitting what we already knew...

There are millions of proofs of how the Turkish government collaborates with ISIS, but this article explaining how the terrorists entered Kobane some weeks ago through the Turkish border is revolting. Maybe this was the best way Erdogan could find to take revenge against the ascent of the HDP, the left-wing pro-Kurdish party.

I really think Kurdish people in Europe should conduct actions against the interests of the Turkish government, something similar to what an Armenian organization did in the 70's and 80's.