and has 0 comments

  I just finished watching the fourth season of The Expanse TV series and, in strong withdrawal, I started reading the Expanse shorts written by James S.A. Corey. Serendipity has it that Gods of Risk is covering most of the Bobbie Draper subplot in the TV season I just watched and that the story happens during Christmas (although what Christmas means on Mars is a bit vague).

  The story is less detailed and with characters pretty different from the TV series, after all it's a short novella, but the basic plot is that same: nephew gets in trouble with the local underworld, aunt Bobbie kicks ass and saves him. It's well written and contains that element of world lesson that I felt was in Auberon. In this case, the only reason the good Martian nephew gets in trouble is his affection for a girl and his desire to protect her after she begs for help. Help provided, despite warnings from both his aunt and her pimp, she spurns him. A good lesson for adolescents everywhere.

and has 0 comments

  Want to feel old? Flea (born Michael Peter Balzary) writes this memoir at 57. In Acid for the Children, he covers his life from childhood in Australia up to, but not including, the Red Hot Chili Peppers era. And it's a nice book, one of those autobiographies that are written with honesty and nostalgia and that shares the lessons the author learned during his life.

  Michael was a scrawny kid, with either physically abusive, alcoholic or indifferent parent figures, born in a poor family. Yet his spirit was that of an artist, so he did what kids like that do: lots of risk taking, misdemeanors just for the sake of it, lots and lots of drugs of all kinds. In the book he thanks his guardian angels for not getting HIV or other life ending diseases or addictions. By the time he got noticed as a base player, he had escaped most of the mentality and came to grips with his parents. He even leans towards snowflake territory at the end there. The book is loosely chronological in order, made of various anecdotes. How he remembers stuff from his childhood with so much detail when I don't remember what happened ten years ago is a mystery, but that's how some people are.

  It's always good to read books like these. Makes you see the world with different eyes. In Flea's case, he made me realize that people do drugs from different reasons: some want to reach a potential they feel is right under their skin, they use them as tools to uncover themselves and when they do, they reach a place of bliss and pure joy. Others want to get to the bliss and joy directly, with no talent or drive to talk of, so they become addicts and "losers". Perhaps that's a kind of uncovering themselves, too. He also made me realize that you need some life experience to be able to access the emotions that are required to do art. It may seem obvious, but when our highest drama is who said what on Twitter or how beautiful is the scenery in a tour guided vacation, we don't have that experience. Lost to this illusion of safety in efficiency as cogs in the machine we lose not only our individuality, but our chances to even become people.

  Bottom line: Flea is a really nice guy, if he can say so himself, and it becomes clear as the book progresses that he had that from the very start, he just had to jump through some hoops to make that work for him. I am glad he made it. I liked the book.

and has 0 comments

First of all, what is TaskCompletionSource<T>? It's a class that returns a task that does not finish immediately and then exposes methods such as TrySetResult. When the result is set, the task completes. We can use this class to turn an event based programming model to an await/async one.

In the example below I will use a Windows Forms app, just so I have access to the Click handler of a Button. Only instead of using the normal EventHandler approach, I will start a thread immediately after InitializeComponent that will react to button clicks.

Here is the Form constructor. Note that I am using Task.Factory.StartNew instead of Task.Run because I need to specify the TaskScheduler in order to have access to a TextBox object. If it were to log something or otherwise not involve the UI, a Task.Run would have been sufficient.

    public Form1()
    {
        InitializeComponent();
        Task.Factory.StartNew(async () =>
        {
            while (true)
            {
                await ClickAsync(button1);
                textBox1.AppendText($"I was clicked at {DateTime.Now:HH:mm:ss.fffff}!\r\n");
            }
        },
        CancellationToken.None,
        TaskCreationOptions.DenyChildAttach,
        TaskScheduler.FromCurrentSynchronizationContext());
    }

What's going on here? I have a while (true) block and inside it I am awaiting a method then write something in a text box. Since await is smart enough to not use CPU and not block threads, this approach doesn't have any performance drawbacks.

Now, for the ClickAsync method:

    private Task ClickAsync(Button button1)
    {
        var tcs = new TaskCompletionSource<object>();
        void handler(object s, EventArgs e) => tcs.TrySetResult(null);
        button1.Click += handler;
        return tcs.Task.ContinueWith(_ => button1.Click -= handler);
    }

Here I am creating a task completion source, I am adding a handler to the Click event, then I am returning the task, which I continue with removing the handler. The handler just sets the result on the task source, thus completing the task.

The flow comes as follows:

  1. the source is created
  2. the handler is attached
  3. the task is returned, but does not complete, thus the loop is halted in await
  4. when the button is clicked, the source result is set, then the handler is removed
  5. the task completed, the await finishes and the text is appended to the text box
  6. the loop continues

It would have been cool if the method to turn an event to an async method would have worked like this: await button1.Click.MakeAsync(), but events are not first class citizens in .NET. Instead, something more cumbersome can be used to make this more generic (note that there is no error handling, for demo purposes):

    public Form1()
    {
        InitializeComponent();
        Task.Factory.StartNew(async () =>
        {
            while (true)
            {
                await EventAsync(button1, nameof(Button.Click));
                textBox1.AppendText($"I was clicked at {DateTime.Now:HH:mm:ss.fffff}!\r\n");
            }
        },
        CancellationToken.None,
        TaskCreationOptions.DenyChildAttach,
        TaskScheduler.FromCurrentSynchronizationContext());
    }

    private Task EventAsync(object obj, string eventName)
    {
        var eventInfo = obj.GetType().GetEvent(eventName);
        var tcs = new TaskCompletionSource<object>();
        EventHandler handler = delegate (object s, EventArgs e) { tcs.TrySetResult(null); };
        eventInfo.AddEventHandler(obj, handler);
        return tcs.Task.ContinueWith(_ => eventInfo.RemoveEventHandler(obj, handler));
    }

Notes:

  • is this a better method of doing things? That depends on what you want to do.
  • If you were to use Reactive Extensions, you can turn an event into an Observable with Observable.FromEventPattern.
  • I see it useful not for button clicks (that while true loop scratches at my brain), but for classes that have Completed events.
  • obviously the EventAsync method is not optimal and has no exception handling

and has 2 comments

  You are writing some code and you find yourself needing to call an async method in your event handler. The event handler, obviously, has a void return type and is not async, so when using await in it, you will get a compile error. I actually had a special class to execute async method synchronously and I used that one, but I didn't actually need it.

  The solution is extremely simple: just mark the event handler as async.

  You should never use async void methods, instead use async Task or async Task<T1,...>. The exception, apparently, is event handlers. And it kind of makes sense: an event handler is designed to be called asynchronously.

  More details here: Tip 1: Async void is for top-level event-handlers only

  And bonus: but what about constructors? They can't be marked as async, they have no return type!

  First, why are you executing code in your constructor? And second, if you absolutely must, you can also create an async void method that you call from the constructor. But the best solution is to make the constructor private and instead use a static async method to create the class, which will execute whatever code you need and then return new YourClass(values returned from async methods).

  That's a very good pattern, regardless of asynchronous methods: if you need to execute code in the constructor, consider hiding it and using a creation method instead.

and has 0 comments

  What I like about Brandon Sanderson is his optimism. In the Skyward universe people are quarantined on a planet while regular alien incursions must be repelled by younger and younger pilots flying crappier and crappier fighters. Anyone else would have made this a bleak post-apocalyptic story. Not Sanderson. He somehow makes it feel cheery!

  In Starsight we learn more about the aliens and the thing that made them all hate humans so. Spensa has to navigate (pun intended) another flight training school, but in a totally different context and the things she learns are even more valuable for the survival of the human race.

  This is a simple linear book with few but relatable characters and a fast pace. I finished it in a day. Skyward is not the best series of Sanderson's, being of a sub-genre that I disconsider, the one of the smart savage that learns the secrets of the world and advances in it with no particular problems and often with the help of overpowered "ancient" artifacts. It's not really that bad here, but I have to compare it with The Reckoners, which has a similar cheery vibe, but also terrible loss and realistic pain. Skyward is just too soft.

  Bottom line: almost pulp, I enjoyed reading the book, but I also felt that it didn't bring too much at the table.

and has 0 comments

  What is it with Brent Weeks and story endings? He himself says at the end of this final book from the Night Angel trilogy that the biggest challenge is the middle of the story. I don't see it that way. His stories have deep and rich middle parts, with new threads constantly being created, new characters and revelations added. It's the ending where, so far, I've felt disappointed.

  Don't get me wrong, this trilogy was great and Beyond the Shadows was a very well written book. It's just that with every chapter in the Night Angel story, the magical world and the characters get wider and the expectations grow with them. The finale, regardless of how epic, should feel like it closes all avenues, it resolves all conflict and explains everything and it just can't! Worse, by using unexpected external forces, abilities, premonitions, prophecies, characters, nations, unknown historical facts - and Weeks uses them all in his endings - everything you've read so far gets invalidated. Glaring examples in Beyond the Shadows are Jenine Gyre and Elene, both some of the most prominent female characters in the story, which fulfil their prophesied purpose almost like tools. And when you look behind, at their personal storyline, you realize that most of it was superfluous, pointless and nonsensical. The character in the end has almost no resemblance to the one at the beginning (or middle) and some of the decisions taken contradict some of the previous ones.

  And then there are all the nations and magic flavors and the geopolitical and historical context. What happens to those?! At the end, every character is awesome, fully grown and with amazing abilities. At the end! When they can't do anything anymore. All their strength and experience is used for a quick bow and a speedy exit stage left.

  Bottom line: Brent Weeks writes epic fantasy stories like Brandon Sanderson and ends them like Peter F. Hamilton, in a rushed mess. Night Angel is no exception. Considering both people I compared him with are in my list of favorite authors, he will probably be on it, too.

and has 0 comments

  Shadow's Edge continues the Night Angel story started in The Way of the Shadows. Kylar has to choose between his desire for a peaceful life and his responsibility. Characters die, but not really, then they die for real, but not really, while new characters and previously unheard of cultures all converge on Cenaria. Why? No one knows. It's all the fashion now.

  In this book, though, characters are much more relatable and the narrative flow feels more natural. You root for them to succeed. I liked it more than the first book in the trilogy, but now I dread the last book, Beyond the Shadows, will have Brent Weeks finish the saga like he did Lightbringer, with characters randomly brought down or up in an epic finale that lacks real meaning. But it could also be great! The suspense is killing me.

and has 0 comments

  Brent Weeks is a great writer, but all his stories so far seem to suffer from the same flaw: nothing of importance that happens in them does so in any relation to what had happened before. If someone is desperate and without choices, they become rich people with connections to nobility. If they plan things in great detail, some new character of great power comes and changes everything. Everyone in indeed connected to everybody else, but not in the way you thought. And if you thought something was in a certain way, don't fret, new information will appear that changes everything. Yes, the characters are captivating, the world building amazing, but the flow of the stories is more suited to movie than book as it's either a thoroughly passive experience or a very frustrating one. It was true for Lightbringer and so far it seems true for the Night Angel trilogy.

  In The Way of Shadows, the lead character is a street urchin that becomes a magical assassin's apprentice, finds noble friends, influences the fates of kingdoms, loves and is loved, loses his soul then finds it again and so on. A lot of people die, but not really by his hand. I mean, he becomes a lean mean killing machine, but we don't learn about his 10 year career, only about his skills. Thus he has the opportunity to make all kinds of moral judgements in the end. He has immense power, but he can't reach it unless he finds a special artefact that allows him to draw on it. Of course he finds one, but only when it's too late to properly train with it, so whenever he does things they are very random and somehow further the plot along. And, as if this weren't enough, there are prophecies and people that can see possible futures and influence it, so that the fates of the characters are even more unpredictable.

  As you have guessed, for me the experience has been as much a positive one as well as a really really frustrating one. How can I possibly invest in a story that changes radically like maddenning rat mazes in science experiments?! I really hope against hope that the ending of the trilogy is going to be satisfactory, but considering Night Angel comes before Lightbringer and that ended as randomly as possible, too, what are really the odds?

  Bottom line: Weeks is a sadist who writes beautiful stories, but forbids you any investment in the fate of his characters. There is only one god and his name is Brent.

and has 0 comments

  A while ago I had this story idea about a certain population that has something special that all others want and that they desperately need to consume. It's the exact premise of The Marrow Thieves, and the population in question is native Americans.

  Now, Cherie Dimaline is Métis herself, so I must trust that she knows what she is talking about, but from my standpoint, all the clichés I thought were stupid about American Indians are right there. It's like people have heard them so many times they started believing them. I am talking about calling themselves Indians, I am talking about the wise old man and wise old woman that guide (through restrictions of both knowledge and permission) young energetic youths, also the non violent Indian that knows responding to violence with violence makes him like the White man, the bow and arrow Indians - although they live in Canada, so who knows, the native people that are in harmony with nature, the betraying Indian - but only because of substance abuse, something the West has brought on them, and so on.

  In short, the book says "please take whatever you want from us, because we are nice, non violent and in harmony with everything. Even if we will eventually fight back, it will be only after we've been thoroughly defeated, humiliated and destroyed as a people". It's hard to empathise with such a moral for the story. I understand it was all mostly metaphor, but still.

  Bottom line: it was OK, but wouldn't recommend it.

and has 0 comments

  The reviews for this book are great and most of them say three things: it was inspired by the 1987 movie Near Dark, it has a different - realistic - take on werewolves and it's a coming of age story. As such, the main character in Mongrels is a boy that lives in a family of werewolves: people that occasionally turn into wolf like creatures, but that brings few advantages and a lot of trouble. Not only are their instincts frustrating in a human society, but turning takes a lot of energy and turning back pulls anything in the fur inside the skin of the human shape: ticks, elastic materials and as wolves they age with the speed of dogs. Since they can't adapt to the normal human way of life, they live on its fringes, as a family of white trash Americans. They steal, they scavenge, they kill animals whenever it doesn't get too suspicious, they move a lot and they are always poor.

  I can't say the book is badly written, but it's the equivalent of, I don't know, werewolf Kenny from Southpark. It's depressing, it's gray, it tries too much to make a social commentary by using the werewolf thing as a gimmick. Yes, it's a fresh take on the mythos, but it's a boring one. It certainly is not a horror book and too little of it is fantastic in nature. Instead it's the story of this boy trying to make up his mind if he is a wolf or a man. It could have just as well been a story about homeless gypsies, without any of the wolf thing, and it would have been the same.

  Bottom line: Stephen Graham Jones is clearly a good writer, but in this case he just wrote a smart book... about werewolves. And Near Dark was way better!

and has 0 comments

  Disclaimer: this is a Romanian book and I personally know the author.

  The book is a journey of a woman, starting from an 18 year old ingenue and ending as a mother and a wife considering her life choices. Perhaps ending is not the right word, since "the game" is about the journey, rather than a specific destination, and the character's story continues after the finale of the book. Split into three narrative flows, the story quickly switches between inner thoughts and external events, fantastical fairy tale concepts and their emotional connections to the character's real life.

  I started reading with dread. It's about women. They're crazy, right? And various sources, that I was actually trying to avoid in fear of spoiling the book, were whispering things that ranged from teenage sex scenes to dramatic philosophical musings. And it was all correct, only I actually liked the book. What I think happened is that it fell under the category of autobiographies, a genre that I am appreciating a lot as it opens my eyes to how other people see the world.

  Em Madara is taking pieces of her soul and crafts a dramatized version of life where she examines her life choices, but also goes further, taking the stratospheric view of people being possible versions of a single identity that they don't remember, of all life teetering between light and darkness, life or death, pleasure and pain, left or right, a choice and another.

  In Hide and Seek (the English translated title) you get hormonal infatuation, self destructive behaviors, temptations and hard personal choices, family drama, love for children, animals or life in general, self exploration, but also Daoist philosophy, Romanian, German and Russian folklore, movie, music and literary references, all bits and pieces of a mosaic that, in the end (Ende is goal in German), make up a single person.

  All in all, a solid novel and a very good beginning for a new writer.

and has 0 comments

   Has it been so long? It feels only yesterday I was reading Contagious, the second book in the Infected trilogy, and intending to read the third one. Now, more than ten years later, here I am finally finishing it. And it was pretty cool. I mean, it's no literary masterpiece, but it presents a consistent sci-fi future, compelling characters, action packed scenes, scientific accuracy. There was love put in this. Sometimes you just want to read something and not overthink it, like watching a blockbuster movie. And sometimes I wonder what do those people think when making those movies: Infected is much more interesting of a material. How come they don't make a series or film based on it?

  Anyway, as the title suggests, Pandemic sees the whole world in the grips of the alien contagion, with the same actors trying to save it. And as in the first two books, Scott Sigler mixes some great scenes with some really corny ones, some great human insight with silly lines like "Run to the chopper", "I'm getting to old for this shit!" or befuddling ones like "Seeing an American citizen being roast to a spit does that to someone". Too bad he was American, right? I have to say that most of the horror in this book comes more from the stupid decision top brass makes, rather than from the effects of the contagion. In the end, the brave souls on the ground save the day. The ending is epic and brings closure... up to the moment Sigler thanks people for carefully advising him about consistency in the 800 year spanning Sigleverse. Ugh! Sigleverse? Really? 800 years? Meaning I have to read more of this stuff to satisfy the completionist in me? Why did I have to read the Acknowledgements?

  Bottom line: action packed sci-fi horror alien invasion flick, split in three books. It is nothing if not enjoyable.

As you possibly know, I am sending automated Tweets whenever I am writing a new blog post, containing the URL of the post. And since I've changed the blog engine, I was always seeing the Twitter card associated with the URL having the same image, the blog tile. So I made changes to display a separate image for each post, by populating the og:image meta property. It didn't work. The Twitter card now refused to show the image. And it was all because the URL I was using was relative to the blog site.

First of all, in order to test how a URL will look in Twitter, use the Twitter Card validator. Second, the Open Graph doesn't specify that the URL in og:image should be absolute, but in practice both Twitter and Facebook expect it to be.

So whenever populating Open Graph meta tags with URLs, make sure they are absolute, not relative.

and has 0 comments

  Nice of the two authors pen-named James S.A. Corey to publish a novella to assuage the thirst for a new The Expanse novel. Auberon is pretty good, but on a human level, rather than on a science-fiction one. You could imagine the same story in a French or Belgian colony in Africa with minimal changes.

  The main focus is on the new Laconian governor of planet Auberon, arriving all smart and proud as the almighty representative of a regime that is rooted in discipline at all levels. Can he keep that up? No plan survives contact with the enemy, but how will things change?

  Bottom line: short, fresh, easy to empathize characters. A win.

and has 0 comments

I've changed a little the way the blog is being displayed. Now posts should present a more specific image than the general blog icon and the list of posts should display an image and then text, regardless of what is in the post. Let me know if anything goes awry.