Saturday, 31 March 2018

Devilman Crybaby - masterpiece or masturbation?

the Japanese Netflix poster I've watched several lackluster recent Japanese animes from Netflix and I was feeling bored and disappointed with the clichés spouted by almost every character, most of them as cardboard as they can be. So when I started with Devilman Crybaby, a very original show both from the standpoint of the manga it adapts and the animation style, I was hoping for not being bored. And I wasn't. The show is fast, jumping from scene to scene and asking the viewer to extrapolate what happened in between. The characters are complex and seldom critical of one aspect or another of society, or representing such negative treats. Violence and sex are everywhere, although they are often depicted as kinds of vices and impulses that people have to fight against. The animation style is weirdly psychedelic. So did I like it? Not really.

Even from the beginning I was off put by the animation style. It's paradoxically both artistic and very simple. It made me think of Aeon Flux (the MTV animated series), which had several other things in common with this, as well. But I didn't let it bother me and I continued watching. As I said before, the characters are complex and the story is meandering around the peculiarities of each of them, which made it interesting. However, the plot was full of holes! Things that were "revealed" later on were evident from the beginning, people acted in weird ways that were eroding the suspension of disbelief. There were fights, but simplistic in nature and more inline with the symbolism that the author was so hard on. There were substories, but kept to a bare minimum. Do you see a pattern already?

Yes, in its entirety, things that were not important to the philosophical message that the anime wanted to make were abstracted, simplified or removed altogether. It is hard to enjoy any of it after you've got the memo. Even worse, perhaps because of its heavy (handed) symbolism, all the articles and reviews online praise it as a masterpiece. I said it before and I will say it again: just because it is not the usual crap it doesn't mean it's good. There are so many sorts of crap. You read two or three of them, discussing "what they meant", and you realize they are as full of shit as the makers of the anime. If you need to explain what you meant, the joke wasn't very good!

To be less of a dick about it, the show has many redeeming qualities, that is why I can't discuss too much the particulars without spoiling it, and you might want to watch it. However, to me, those qualities were wasted in the pseudo spiritual and moral bullshit that suffused the show. One alleviating circumstance is the source material, written in the 70s, which I have not read, so I can't really compare, but it was the 70s. Weird and wonderful stuff came from back then. This is mostly just weird. And I really hated the title.

Here is the trailer:

Thursday, 29 March 2018

.NET Standard gotcha: unit tests don't need to be Standard

You created a library in .NET Core and you want it to be usable for .NET Framework or Xamarin as well, so you want to turn it into a .NET Standard library. You learn that it is simple: a matter of changing the TargetFramework in the .csproj file, so you do this for all projects in the solution.

But .NET Standard is only designed for libraries, so it makes no sense to change the TargetFramework for other types of projects, including some that are in fact libraries, but are not used as such, like unit test projects.

For example if you attempt to run XUnit tests in Visual Studio you will see that the tests are discovered by Test Explorer, but when you try to run them it says "No test is available in [your project]. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.". While this is an issue with XUnit, more likely, it is also a non-issue, since your test project should use the .NET Standard libraries, not be one itself.

Wednesday, 28 March 2018

ECMAScript/Typescript gotcha: Map has to be used with set/get not like a Dictionary in .NET

In ECMAScript 6 there is a Map class that looks and feels like a .NET Dictionary. As an extension of JavaScript, TypeScript code like this is totally valid:
let map:Map<number,string> = new Map<number,string>();
map[1]="Category One";
let name:string = map[1]; //name is now "Category One"

However, the code above is wrong. What this does is create a string property named "1" on the map object with a value "Category One". Its "size" is 0. The correct code would be like this:
let map:Map<number,string> = new Map<number,string>();
map.set(1,"Category One");
let name:string = map.get(1); //name is now "Category One", map.size is 1

Similar code for ECMAScript 6, you can just declare the map as let map = new Map();

Just in case you wonder why utilize this hard to use type instead of a normal object, it's a user choice. Most of the pros involve the type of the key (object keys can only be strings or symbols) and ease of counting and iterating, but these issues can be solved trivially in code, if ever needed.

Monday, 26 March 2018

Proxima (Proxima #1), by Stephen Baxter

Book cover Proxima is the first book in the Proxima duology, by Stephen Baxter. And it is barely about Proxima! The book starts with multiple viewpoints over several arcs, is split into tiny chapters and volumes, attempts to become something epic and eventually fizzles. It's not that it's a bad book, it's simply not very good.

You have alien technology found on Mars, two different expeditions to Proxima C - if you don't count the first misguided one, a habitable planet in the Proxima Centauri system, several people and their families over a span of several decades, Artificial Intelligences, a nebulous period in the history of mankind called "The Heroic Generation" which seems to have left people in fear of innovation and discovery, alien lifeforms, artificial lifeforms, parallel timelines, etc. And it's all mixed in. It feels like it should be more, like it was meant to be more, but it just comes out as jumbled and directionless. I think what bothered me most is that characters barely have time to change. In order to explain what happens with a zillion people Earth, Mars, Mercury and an alien planet in a single book, their personal development is sacrificed.

But overall the book was interesting. It covered some bits of Earth future history that most sci-fi works quickly get past. The downside is that it went over them really fast, too :) The actual exploration and life on Proxima was on fast forward, too, with a really hard to believe ecosystem for its simplicity. Oh, and that ending was horrid! I will not read any of the works in the series. I feel that Baxter is overambitious, but also very courageous. I usually have a lot of problems with his works, but still read some of them.

Tuesday, 20 March 2018

B: The Beginning - averaging anime into obscurity

The main characters What do you do if you want to make an anime that would be successful not only in Japan, but everywhere Netflix is watched? You take a bit of every successful anime and mix it all together. This is how you get the kingdom of Cremona, set somewhere in a nondescript time that has 1960's cars and cellphones and a nondescript place that looks like Europe, where experiments with the bones of god like creatures leads to superpowerful beings that are super crazy fast and shout Nipponisms with every opportunity: win and lose (in life, but seen as a game), protecting (someone, something, anything) just so your life makes some sense, "I will kill you with my own hands" and so on and so on, but also super smart detectives that figure things out, all for the sake of energetic, smart, cute and ultimately pointless much younger girls. But wait, there is more: there are crazy psychopaths that kill people and are super smart. There are arrogant evil people that have a lot of power, but are ultimately crazy, and which act as if everything and everybody is beneath them. And of course, all the fighting is done with magical swords and henchmen die quicker and with less talk than bosses, who are not particularly strong, but they just yap and yap and yap.

The anger that you see expressed in my review is related not so much to the mediocrity of the anime, but to the potential that it had. The animation is well done, the sets are good, the story is... ahem... workable. And yet they press every button that was ever pressed and add absolutely nothing new. B: The Beginning even has the gall to believe it will spawn sequels, so whatever else they had in mind they left it for later. I would say that's typical DragonBall Z, but that should apply to Saiyans not anime shows! You don't leave the good part for the end of the battle! You don't level up your writing only when you see that everybody is bored already.

Bottom line: the writing was the biggest flaw of this series: unimaginative and inconsistent, with tiresome dialogues and brutal switches of emotional context that made even the most motivated viewer break stride. The rest was always just good enough, with no evidence of any effort for reaching greatness. As mediocre as it can possibly be.

Monday, 19 March 2018

Being a Dog: Following the Dog Into a World of Smell, by Alexandra Horowitz

book cover I found Being a Dog a bit misleading, as it is not so much about dogs as it is about smell in general. However, as a book about smell it's a concise and very interesting book. Alexandra Horowitz has a steady professional writing style and the information in the book is being related as anecdotes from her very thorough research.

From the very start the book acknowledges that dogs are not visual and auditory like humans are; instead their main sensory organ is their nose. As the author explores the world of smells, we understand more about us, dogs and how we sense the world in general. I liked many sections of Being a Dog, but I found the first part as most interesting. Mainly because it is about dogs :) There we find that the structure of the nose of dogs is as much responsible for their great sense of smell as is the immense number of sensory cells and dedicated brain neurons. Horowitz explains that dogs do not pass the so called "mirror test", but that is because they are not visual. If the experiment is constructed so that the mirror is olfactory, then they easily pass the test. It also tells us where the smelly glands on the dog are, including its paws. And indeed, I smelled my dog's paw and it was concentrated and nice. If you have a dog, smell their paws now!

That doesn't mean that the part about human smell was not captivating. I found myself smell things on the subway - that is a good thing - just because I felt inspired by what the author described. In conclusion, I recommend the book. It's a light read and it is the kind of work that makes us aware of a part of the world that is both near and ignored.

String theory in C#. My own string!

Well, if Java can do it, so can I! Why not make my own C# string class that can do whatever I want it to do? Requirements? Here they are:
  • I want it to work just like regular strings
  • I want to know if the string is empty just by using it as an if clause, just like Javascript: if (text) doSomething(text);
  • I want to see if it's a number just by adding a plus sign in front of it: var number = +text;
  • I want to easily know if the string is null or whitespace!

OK, so first I want to get all the functionality of a normal string. So I will just inherit from it! Only I can't. String is a sealed class in .Net.
Yet there is an abstract class that seems destined to be used by this: ValueType! It's only implemented by all value types (more or less) except String, but I will be the next guy to use it! Only I can't. If I try, I get the occult message: "Error CS0644 'EString' cannot derive from special class 'ValueType'". But it does help with something, if I try to inherit from it, it tells me what methods to implement: Equals, GetHashCode and ToString.
OK, then, I will just do everything from scratch!

Start with a struct (no need for a class) that wraps a string _value field, then overwrite the equality methods:
public struct EString
{
private string _value;
 
public override bool Equals(object obj)
{
return String.Equals(obj, _value);
}
 
public override int GetHashCode()
{
return _value == null ? 0 : _value.GetHashCode();
}
 
public override string ToString()
{
return _value;
}
}

I used 0 for the hash code when the value is null because that's what the .Net object GetHashCode() does. Now, in order for this to work as a string, I need some implicit conversion from string to my EString class. So add these two beauties:
public string Value { get => _value; }
 
private EString(string value) { _value = value; }
 
public static implicit operator string(EString estring)
{
return estring.Value;
}
 
public static implicit operator EString(string value)
{
return new EString(value);
}

EString now supports stuff like EString text="Something";, but I want more! Let's overload some operators. I want to be able to see if a string is null or empty just like in Javascript:
public static bool operator !(EString estring)
{
return String.IsNullOrEmpty(estring);
}
 
public static bool operator true(EString estring)
{
return !!estring;
}
 
public static bool operator false(EString estring)
{
return !estring;
}
Yes, ladies and gentlemen, true and false are not only boolean constants, but also operators. That doesn't mean something like this is legal: if (text==true) ..., but you can use stuff like if (text) ... or text ? "something" : "empty". Overloading the ! operator allows also something more useful like if (!text) [this shit is empty].

Moar! How about a simple way to know if the string is null or empty or whitespace? Let's overload the ~ operator. How about getting the number encoded into the text? Let's overload the + operator. Here is the final result:
public struct EString
{
private string _value;
 
public string Value { get => _value; }
 
private EString(string value) { _value = value; }
 
public override bool Equals(object obj)
{
return String.Equals(obj, _value);
}
 
public override int GetHashCode()
{
return _value == null ? 0 : _value.GetHashCode();
}
 
public override string ToString()
{
return _value;
}
 
public static bool operator !(EString estring)
{
return String.IsNullOrEmpty(estring);
}
 
public static bool operator true(EString estring)
{
return !!estring;
}
 
public static bool operator false(EString estring)
{
return !estring;
}
 
public static bool operator ~(EString estring)
{
return String.IsNullOrWhiteSpace(estring);
}
 
public static decimal operator +(EString estring)
{
return decimal.TryParse(estring.Value, out decimal d) ? d : decimal.Zero;
}
 
public static implicit operator string(EString estring)
{
return estring.Value;
}
 
public static implicit operator EString(string value)
{
return new EString(value);
}
}

Disclamer: I did this mostly for fun. I can't condone replacing your strings with my class, but look at these examples for usage:
EString s=inputText;
if
(!~s) {
var d = Math.Round(+s,2);
if (d != 0) {
Console.WriteLine("Number was introduced: "+d);
}
}