Tuesday 11 September 2018

Mixin and Compose

While thinking of a possible design I came up with an idea that seemed interesting to me. I was thiking of having a main class and organizing additional behaviours in objects to be used as mixins. We would create instances of the main class and add extra behaviours by combining them with different mixins as we saw fit. OK, nothing out of the ordinary, the interesting part is that some of the behaviours (methods) I would not just want to add them, but to compose them (create a new method that calls to the other methods).

What I mean is that if I have a class with a method "process", and I mixin with one of its instances some object that also has a "process" method (we have a collision then), we would end up with a new "process" method that invokes both methods. Probably this is not the generic behaviour that we want for our mixins and collisions, in other occasions we would want the last "process" method to be added to override the previous ones, or maybe just throw an error, but for some situations it's a behaviour that makes quite sense.

So I've cooked a mixinAndCompose basic implementation and sample:

class Particle{
	constructor(position, velocity){
		console.debug("Particle constructor");
	}

	evolve(){
		console.debug("Particle updates position based on velocity");
	}
}

//animation logic to be "mixed in"
const alphaAnimateLogic = {
	initAlphaAnimate(minAlpha, maxAlpha, currentAlpha, initialDirection){
		this.minAlpha = minAlpha;
		this.maxAlpha = maxAlpha;
		this.currentAlpha = currentAlpha;
		this.initialDirection = initialDirection;
	},
	
	additionalMethod(){
		console.debug("additionalMethod: " + this.currentAlpha);
	},


	evolve(){
		this.currentAlpha++;	
		console.debug("Particle updates alpha values");		
		this.additionalMethod();	
		
	}
}

//bouncing logic to be "mixed in"
const bounceLogic = {
	initBounce(xLimit, yLimit){
		//...
	},
	
	

	evolve(){
		console.debug("applying bounce logic");
	}
};

//---------------------------

function mixinAndCompose(target, mixinObj){
	for (let propName of Object.getOwnPropertyNames(mixinObj)){
	 	if (typeof(mixinObj[propName]) == "function" && typeof(target[propName]) == "function"){
			console.log("composing: " + propName);			
			let targetFn = target[propName];
			let mixinFn = mixinObj[propName];
			target[propName] = function(...args){
				targetFn.apply(this, args);
				return mixinFn.apply(this, args);

			};
		}
		else{
			console.log("adding: " + propName);				
			target[propName] = mixinObj[propName];
		}
	}
	return target;
}


let particle = mixinAndCompose(new Particle(), alphaAnimateLogic);
mixinAndCompose(particle, bounceLogic);
particle.initAlphaAnimate(0,10,0);
particle.initBounce();
console.log("--------");

particle.evolve();
console.log("--------");

particle.evolve();
console.log("--------");

particle.evolve();

This strategy to deal with mixins in collisions could also make sense in some occasions for collisions in Multiple Inheritance

Saturday 8 September 2018

Victimist Asshole

I had forgotten to post about this issue at the time the controversy broke out, but I think it's still worth to write here some lines of disdain for this very visible example of an immigrant that rejects to fully integrate and embrace the society that has given him everything he has.

Ozil is (apart from an asshole) a German football player of Turkish descent that has quit the German national team because he says to be "victim of racism and discrimination". He claims that when the team wins he's considered a German, but when they lose people consider him a Turk. If that were true that would be horrible, but that's not true at all. The criticism to this idiot started after he showed up on TV smiling and shaking hands with the Turkish fascist president Erdogan. As we all know Erdogan is an enemy of the Western civilization, an ultra-nationalist Islamist that among many other crimes denies the Armenian genocide, massacres the Kurds, funds and promotes the Islamists and asks German citizens of Turkish descent not to integrate in the European culture and be ready to be a "Trojan horse". Obviously, having such kind of friends have made many people in Germany to openly criticice Ozil and think that he did not deserve to be part of the German team. I assume it would have been the same if he had shown up with a poster of Adolf Hitler. Showing appreciation for an assasin like Erdogan should have caused the immediate exclusion (now and forever) of Ozil from the German team.

Rather than showing remorse for his actions (he even refused the requests from a free-speech organization to speak out agains Human Rights violations in Turkey), this piece of crap has tried to turn the persecutor into victim (why is it that Muslims are so prone to do so?). The guy that supports a discriminatory leader (Islamism and ultra-nationalism are the mother of all discriminations) says that he is a victim of racism (from the so evil German society that accepted his parents in the country and provided him with health care and education...) It's just disgusting...

The Ozil bastard has tried to sort out things by saying that he has 2 hearts (a German one and a Turkish one). I've said it before, if you are born, raised and educated in a country that has treated you as one more citizen, I can not understand the obsession with "the land of your ancestors". It's normal and OK that you have a certain feeling for the land of your family, but considering that as the basis of your identity seems so stupid to me... It's so deterministic, you are what your ancestors were, not what you choose to be??? Regarless of how stupid this "split heart" thing seems to me, of course it's up to each individual to decide which is his identity, but for sure, if he intends to represent/defend one country (either by playing in the national team, joining the army...) he must have a single loyalty, which is clear not to be the case for the Ozil rat.

Friday 7 September 2018

Mandela's Nightmare

I guess when someone thinks about South Africa the main things that come to mind are the sickening Apartheid system of the past, Nelson Mandela and the current crazy levels of insecurity, gangs violence and murder. Maybe you have also read about how after the end of Apartheid the pressure from Financial Markets prevented the ANC from carrying out effective social policies, and on the contrary forced them into a privatisation campaing that is at the root of the failure of this African nation. One could think that the race unequality has been replaced by class unequality.

Watching this documentary one learns that racial tensions and segregation have been getting worse and worse in the last years, but this time it's the "white" population who is suffering racism. It would be wrong and unfair to just say that wealth has changed from white hands to black hands. A huge majority of rich South Africans are "white", and "whites" continue to be a majority in companies high ranks and land ownership. But this said, we've seen an explosion in the number of "whites" living under poverty levels and being dragged into shanty towns. This has been caused by the stupid "positive discrimination" policies forced upon by the government. Companies are obliged to prioritize the hiring of "black" employees. Probably this new color of discrimination is not having too much effect in highly qualified jobs as there are not many "black" candidates, but for lower positions, it's doing almost impossible for many "whites" to find a job and pushing them into poverty.

Poverty is equally sad whatever the color of who is suffering it, and race/ethnic supremacy is equally disgusting whatever race or ethnicity is endorsing it. Now, it's "Black"/African supremacy what is on the rise, thanks to the EFF anti-white racist party. We can see in the documentary how some "Black" rappers-criminals are also preaching hate against "whites", advocating for assaulting them and grabbing their lands. This is not just some theorical crap, "white" farmers are being attacked all over the country. As a response, "white" communities are closing over, and the dream of a multicolor/multiethnique South Africa seems now as far away as during the old Apartheid times. Mandela's dream still waits...