and has 0 comments
Imagine a space pulp "escape from a room" story and you get The False Admiral (also known as simply Admiral). Sean Danker writes a short and fast paced story about three Evagardian space navy members that find themselves on a derelict ship on an unknown alien planet. From start to end the hero of the story, helped by the other younger three, must solve problem after problem in order to keep them alive. It's a short, fun and simple book.

At first I was convinced that this was not the beginning of the story. The main character mentions previous events that are not described in the book and he makes efforts to hide his real identity from the others, to the point where they have to choose between trusting him or arresting him as an enemy spy. But no, that part of the story is not written yet. A second book in the Admiral series has been released, called simply Free Space, but I will probably not read it. And this is not because I did not enjoy Admiral, but because I have other stories I would rather read.

Bottom line: when you need a quick disconnecting read, try this book. It's dubious sci-fi and it is rather more similar to detective noir than space opera or military stories, but it is fun.

and has 8 comments
I've learned something new today. It all starts with an innocuous question: Given the following struct, tell me what is its size:
    public struct MyStruct
{
public int i1;
public char c1;
public long l1;
public char c2;
public short s1;
public char c3;
}
Let's assume that this is in 32bit C++ or C#.

The first answer is 4+1+8+1+2+1 = 17. Nope! It's 24.

Well, it is called memory alignment and it has to do with the way CPUs work. They have memory registers of fixed size, various caches with different sizes and speeds, etc. Basically, when you ask for a 4 byte int, it needs to be "aligned" so that you get 4 bytes from the correct position into a single register. Otherwise the CPU needs to take two registers (let's say 1 byte in one and 3 bytes in another) then mask and shift both and add them into another register. That is unbelievably expensive at that level.

So, why 24? i1 is an int, it needs to be aligned on positions that are multiple of 4 bytes. 0 qualifies, so it takes 4 bytes. Then there is a char. Chars are one byte, can be put anywhere, so the size becomes 5 bytes. However, a long is 8 bytes, so it needs to be on a position that is a multiple of 8. That is why we add 3 bytes as padding, then we add the long in. Now the size is 16. One more char → 17. Shorts are 2 bytes, so we add one more padding byte to get to 18, then the short is added. The size is 20. And in the end you get the last char in, getting to 21. But now, the struct needs to be aligned with itself, meaning with the largest primitive used inside it, in our case the long with 8 bytes. That is why we add 3 more bytes so that the struct has a size that is a multiple of 8.

Note that a struct containing a struct will align it to its largest primitive element, not the actual size of the child struct. It's a recursive process.

Can we do something about it? What if I want to spend speed on memory or disk space? We can use directives such as StructLayout. It receives a LayoutKind - which defaults to Sequential, but can also be Auto or Explicit - and a numeric Pack parameter. Auto rearranges the order of the members of the class, so it takes the least amount of space. However, this has some side effects, like getting errors when you want to use Marshal.SizeOf. With Explicit, each field needs to be adorned with a FieldOffset attribute to determine the exact position in memory; that also means you can use several fields on the same position, like in:
    [StructLayout(LayoutKind.Explicit)]
public struct MyStruct
{
[FieldOffset(0)]
public int i1;
[FieldOffset(4)]
public int i2;
[FieldOffset(0)]
public long l1;
}
The Pack parameter tells the system on how to align the fields. 0 is the default, but 1 will make the size of the first struct above to actually be 17.
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct MyStruct
{
public int i1;
public char c1;
public long l1;
public char c2;
public short s1;
public char c3;
}
Other values can be 2,4,8,16,32,64 or 128. You can test on how the performance is affected by this, as an exercise.

More information here: Advanced c# programming 6: Everything about memory allocation in .NET

Update: I've created a piece of code to actually test for this:
unsafe static void Main(string[] args)
{
var st = new MyStruct();
Console.WriteLine($"sizeof:{sizeof(MyStruct)} Marshal.sizeof:{Marshal.SizeOf(st)} custom sizeof:{MySizeof(st)}");
Console.ReadKey();
}
 
private static long MySizeof(MyStruct st)
{
long before = GC.GetTotalMemory(true);
MyStruct[] array = new MyStruct[100000];
long after = GC.GetTotalMemory(true);
var size = (after - before) / array.Length;
return size;
}

Considering the original MyStruct, the size reported by all three ways of computing size is 24. I had to test the idea that the maximum byte padding is 4, so I used this structure:
public struct MyStruct
{
public long l;
public byte b;
}
Since long is 8 bytes and byte is 1, I expected the size to be 16 and it was, not 12. However, I decided to also try with a decimal instead of the long. Decimal values have 16 bytes, so if my interpretation was correct, 17 bytes should be aligned with the size of the biggest struct primitive field: a multiple of 16, so 32. The result was weirdly inconsistent: sizeof:20 Marshal.sizeof:24 custom sizeof:20, which suggests an alignment to 4 or 8 bytes, not 16. So I started playing with the StructLayoutAttribute:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct MyStruct
{
public decimal d;
public byte b;
}

For Pack = 1, I got the consistent 17 bytes. For Pack=4, I got consistent values of 20. For Pack=8 or higher, I got the weird 20-24-20 result, which suggests packing works differently for decimals than for other values. I've replaced the decimal with a struct containing two long values and the consistent result was back to 24, but then again, that's expected. Funny thing is that Guid is also a 16 byte value, although it is itself a struct, and the resulting size was 20. Guid is not a value type, though.

The only conclusion I can draw is that what I wrote in this post is true. Also, StructLayout Pack does not work as I had expected, instead it provides a minimum packing size, not a maximum one. If the biggest element in the struct is 8 bytes, then the minimum between the Pack value and 8 will be used for alignment. The alignment of the type is the size of its largest element (1, 2, 4, 8, etc., bytes) or the specified packing size, whichever is smaller.

All this if you are not using decimals... then all bets are off! From my discussions with Filip B. Vondrášek in the comments of this post, I've reached the conclusion that decimals are internally structs that are aligned to their largest element, an int, so to 4 bytes. However, it seems Marshal.sizeof misreports the size of structs containing decimals, for some reason.

In fact, all "simple" types are structs internally, as described by the C# language specification, but the Decimal struct also implements IDeserializationEventListener, but I don't see how this would influence things. Certainly the compilers have optimizations for working with primitive types. This is as deep as I want to go with this, anyway.

and has 0 comments
Hex has a very King-like feel. The quintessential American little town, the close knit community, the apparent order and control, the breaking of chaos and the reveal of the true face of humanity. And yet, the inspiration for the story came from Roald Dahl's The Witches and it was originally about a little Dutch town. However Thomas Olde Heuvelt saw an opportunity while reviewing the English translation of the book and updated it for an American audience.

The premise is interesting enough. Imagine a modern town that is also haunted by the 350 year old witch that cursed it. People have molded their lives around the witch, using the Internet and technology to monitor her and hide her from the world outside their little town. And when something goes wrong, it goes very wrong. However, I loved that the end was not the typical American horror story, in which the baddie does unspeakable things and the heroes suffer and maybe prevail after grievous losses. It's difficult to talk about it without spoiling the ending, so you will have to read the book and remember me when Katherine displays shock.

Now, I can't say I loved the book. It is well written and the characters are compelling enough. However, it did feel like someone was excited to write a story in the American way, and that is exactly what I did not expect from the author. I mean, I've read The Boy Who Cast No Shadow and that was both powerful and fresh. Hex is not very long, though, and easy to read. Perhaps its best feature is also its worst: it is predictable. You read it and it's like those supposedly funny fail videos where you know something is going to happen, you can even guess what it is going to be, but you are still watching to see it unfold. If you like Stephen King, you will like this book.

and has 1 comment
As an experiment, try to find this video without knowing the name of the song or of the band. I tried so hard until my brain just gave up and remembered the name of the band all by itself. So here is the video. Now I can always find it when I need it. Cool song and video, I think.



And so that other people can find it: it's a music video about an astronaut crash landing on an alien planet and finding his own dead bodies and more versions of himself continuously falling and dying in different ways.

and has 0 comments
Obsidian and Blood is a collection of all the works in the Aztec magical universe created by Aliette de Bodard. It contains the three books Servant of the Underworld, Harbinger of the Storm and Master of the House of Darts, plus three short stories (which perhaps you should read first). The stories can be found online, if you want a free taste.

Now, while I enjoyed the books, I felt a little cheated. In fact, these are not fantasy books as much as policiers, just set in the tiny and magical Aztec world. Acatl, priest of the Dead, is trying to solve the mystery of various murders and magical transgressions. He is driven, moral and relentless, willing to sacrifice everything in order to save his friends, loved ones and ultimately the world. So it's basically a cop book, only with Aztec gods around.

The writing style is very technical, reminding me of so many other authors that learned the craft in writing classes, with a mentor and a group and so on. However, it was in no way innovative. I felt that the books are the written equivalent of TV movies: professional, but mediocre. And while I stuck through all the books instead of stopping with the first, it's kind of like watching the rest of a miniseries just because you watched the first episode.

The context is the only thing that elevates the book above average. It is an interesting setup to base the stories on Aztec mythology, but I felt that modern sensibilities prevailed and the author chickened out when it came to child sacrifices and ritual torture and so on. They are mentioned, but everybody, whether heroic or villainous, is rational and follows a modern way of thinking.

Bottom line: I wish these were filled with the horror and majesty of the old blood gods, making me feel something visceral and true, more like the short stories and less than the books. As such, these are just police mystery stories set in the Mexica empire.

and has 0 comments
For anyone coming from the welcoming arms of Visual Studio 2015 and higher, Eclipse feels like an abomination. However, knowing some nice tips and tricks helps a lot. I want to give a shout out to this article: Again! – 10 Tips on Java Debugging with Eclipse which is much more detailed that what I am going to write here and from where I got inspired.

Three things I thought most important, though, and this is what I am going to highlight:
  1. Show Logical Structure - who would have known that a little setting on top of the Expressions view would have been that important? Remember when you cursed how Maps are shown in the Eclipse debugger? With Show Logical Structures you can actually see items, keys and values!
  2. The Display View - just go to Window → Show View → Display and you get something that functions a bit like the Immediate Window in Visual Studio. In other words, just write your code there and execute it in the program's context. For a very useful example: write new java.util.Scanner(request.getEntity().getContent()).useDelimiter("\\A").next() in the Display window, select it, then click on Display Result of Evaluated Selected Text, and it will add to the Display window the string of the content of a HttpPost request.
  3. Watchpoints - you can set breakpoints that go into debug mode when a variable is accessed or changed!

For details and extra info, read the codecentric article I mentioned above.

and has 2 comments
Hungry Trekkies, not nourished enough by the latest Star Trek movies, have been treated with not one, but two Star Trek series this fall. One is Star Trek: Discovery, the other is The Orville.

You may be incredulous at first, considering you are likely to not have heard of The Orville at all and, if you did, you thought it was a Star Trek parody. But no. Four episodes into the series it's pretty clear that this is a serious sci-fi opera, with some comedy added for spice. What about the new Star Trek series? Well, it's set before The Original Series, it has the visuals closer to the Abramsverse Star Trek (but without the flares, thank you very much), it has redesigned Klingons and a pretty impressive first two episodes.

It is too early to discuss the plot of Discovery yet as the premise hasn't even been revealed in its entirety. As of yet I can only tell you that I hate the main character. A human female raised by the Vulcans behaves in a way that makes one believe her education was acquired only from Vulcans in Pon Farr. CBS went all in and made the show available on their own CBS All Access network and hired actors like Michelle Yeoh to play in the pilot.

Yet Orville, with clearly less money and with TV actors and comedians managed to do better. The episodes are separate, like in a traditional Star Trek series, rather than a long serialized story. The plot of each episode is related to social or moral issues, like in traditional Star Trek series. People are positive and talking about themselves and their feelings, like traditional Star Trek series. There is comedy, but it is not part of the scaffolding of the stories. It's just a funny crew in a Star Trek clone that's as close as it gets. And if we are at the subject of celebrity actors, episode four has freaking Liam Neeson in a few scenes.

Conclusion: it may go either way, but right now The Orville seems to have done what I thought people would do: renounce the CBS/Paramount property and their money grabbing schemes, but keep faith with Gene Roddenberry's vision. Because that is the soul of Star Trek, not the money thrown by corporations to turn it into an all action and explosions piece of crap. Still, I have hope for Discovery as well. Only time will tell.

P.S. Now if they would only do Andromeda right...

and has 0 comments
While Blood of Elves is the third work in Andrzej Sapkowski's Witcher series, it is the first actual book, the rest being collections of short stories. The style is the same, the characters the same. What changes is the scope of the story, the size of the described universe.

Is that a good thing? I can't say. While I applaud Sapkowski's attention to historical detail and the way the names are written or spelled in human or elven languages, the action still feels like I'm watching one of those Polish TV plays for children. A lot of dialogue, some exposition, no end to the moralizing stories about the environment and how politicians suck. So I am undecided whether this is a better way of treating The Witcher. However, I can say that the first book in the saga is nothing more than a chapter in a large story. A lot of set up, a lot of discussions, a lot of "almost there, but not quite" and then the book ends when you were starting to wonder what is going to happen. That makes the book incredibly disappointing as a stand alone story and, as I don't intend to read more of the Witcher, kind of a waste of time.

It is similar to one of those Hollywood movies that get split into two parts and it is never a good idea to watch the first part, then wait for a year to see the continuation. While I could read it really fast and there was nothing complex in it other than the political and geographical details, the story is almost nonexistent. I didn't like that at all. To add insult to misery, the book is about Ciri, the princess/witcher/witch, and very little about Geralt who appears mostly in memories and does very little in the story.

Bottom line: unless you are committed to read the entire Witcher series, don't bother reading this volume. It's not that it is badly written, it's that it does nothing but setting up the next books. It is an oversized chapter of a larger story and cannot be entertaining as a stand alone.

and has 0 comments
This book is NOT about vampires. For a long time I avoided reading it because the title so suggested some steamy vampire young adult crap. But no! The book is a hard sci-fi book about the end of humanity, written in a style that I can hardly imagine any man would be able to adopt. And that's a good thing.

Lilith's Brood is in fact a collection of three works (Dawn, Adulthood Rites, and Imago) by late writer Octavia E. Butler. That is why it is so damn long. Since she died, there won't be any more books in the series, so the "Xenogenesis #1-3" label is a bit misleading, just the name of an out of print collection that gathered the three stories together.

The story is about a species of aliens who decide to save the human race after a global war that had doomed it to extinction. The aliens are very interesting, but even more interesting is how the author surfs the edge of defining them as good or evil. Some of the things they do are benevolent and generous, others are, by human standards, insidious and evil. Imagine a benevolent Zerg species coming to Earth. Or a biological Borg with good intentions. Or an intelligent virus that rationalizes its actions as for the better good. It is difficult to keep reading as it pretty much describes the salvation of the human race as a centuries long rape and corruption process by a species that is much more advanced than us, but in very important ways, more animal than humans are. And we are almost helpless. Imagine you are a pet of omnipotent new-age vegans. It's something like that.

I was saying that only a woman could have written about it in this way because the focus is on survival and procreation, on protecting and avoiding death, on how the body feels rather than the mind. I do think that males were presented as either violent mindless rapey idiots or sensitive pacifist weak side characters. The arrogance of the aliens also has a strong vibe of "mama knows best", which explains why males were reduced to enraged murderous states. I mean, that's always the result of that "educational method". But the book is good enough to make you ignore that.

The bottom line is that this is a great book, one that is incredibly detailed and focused on characters, rather than technology or some story arch that has to end at some defined point. It made me think of so many things. I've once had this fantasy of writing a book about people being treated as pets. This is as close as I've read so far. Lilith's Brood made me reconsider the way I raise my dog! It also made me think of the nature of individuality, its benefits and perils, or the definition of humanity. Can you still be human when stripped of all dignity? As I said, while very very good, it is not easy to read. I was sometimes putting the book down and fantasizing on things I would have done if I were some character in the book.

Worth a read, that's for sure.

and has 0 comments
You may have noticed that when using the Pirate Bay site, your CPU usage goes up all to the top. That is because the web site is silently using CoinHive, a distributed cryptographic currency miner that uses the processing power of web users. The easiest solution for me was to go to %windir%/System32/drivers/etc/hosts and add the line
1.1.1.1 coin-hive.com
This tells your computer that the coin-hive server is in an unreachable place. You could add URLs with coin-hive in your URL filter or ad blocker software instead.

Now, CoinHive is not a bad thing. (Using it silently is. I wonder if they do this for mobiles as well, destroying their battery life.) In fact, the idea is pretty interesting and I've considered it before in a different context. I may still use it. You are browsing a web site and there are no ads on it or you have a mighty good ad blocker. How is that site to sustain itself? It does so by using some of your processing power. Before the advent of cryptocurrency, there was not way of efficiently monetize CPU power. People have tried, with projects like SETI@Home, but it was always a not very granular process. It only worked for processes that could be split into tiny pieces that were still relevant.

So there you have it, an interesting idea, used in a nefarious way :) Or, if you want to support the site, leave it on. You will make them money.

and has 1 comment

As with all the programmer questions, I will update the post with the answer after people comment on this. Today's question is:
You have a list of regular expressions for strings to be matched against. You need to turn them into a single regular expression. How can you do it so that a string needs to match any of the initial regular expressions? How can you do it to match them all at the same time?

Here is a question for programmers. I will wait for your comments before answering.

and has 0 comments
The Last Wish is not what I expected. I liked the Witcher games reasonably well, but I liked the character in the stories of the games more than the one in this book. Andrzej Sapkowski creates this character who is trained by pain, knowledge, poison and discipline to become the ultimate monster killer. However, the result is a very ordinary person, one who is better at fighting and resisting various magic or chemical attacks, but still a regular dude. He has friends, he falls in love and has moral qualms, he gets defeated and knocked out.

The book is actually a collection of short stories with Geralt the witcher as the main character. Some are reimaginings of classical folk tales, but all of them are about real versus perceived monsters. Is something huge with dagger like teeth a monster to be killed or is there a cursed person inside. Is a normal human less monstrous just because he looks normal, or is he a cruel and vicious villain? In all stories there is a lot of dialog, with characters that are not clearly developed talking a lot about what is going on. I didn't like that. It felt like reading plays.

But even so, I would have said that the book is OK. Like someone trying to write a fairy tale of their own. Why not? But there was this expectation from the games that the witcher was a womanizer that decides who lives and who dies based on his own strange code and lives on the edge by the strength of his skill. In fact, in the books he is the most decent hero I've read about in a while. He is one of the last of a dying breed, like samurai or American native warriors, not because of the monsters that kill them off, but because of humans spreading everywhere and expecting everyone to live by their code of conduct. If he would kill all the monsters in the world, he would be the very next to be destroyed by the people who no longer need him and have always hated him. Let me tell you that it is hard to reconcile my expectations with the book character.

Bottom line: an OK book. Certainly not great in any respect. I recommend you read it before researching the character or playing the games. I think that the book makes the games more interesting, by adding a backdrop story, but the games make the story hard to enjoy... because they are simply better.

and has 0 comments
We Eat Our Own is a reimagining of the making of an infamous movie called Cannibal Holocaust. It was an exploitation movie, featuring all kind of violence, from rape to murder and cannibalism, but also one that strives for maximum realism. In her book, Kea Wilson is portraying a world of emotional dog-eat-dog, with the movie and even the reality around the film set becoming part of a cannibal act where people use and consume and corrupt others.

I can't say I enjoyed the book too much. It is very well written and it makes the reader get visceral feelings about the people and the events inside, however I couldn't make myself care about any of it. In striving for realism herself, Wilson managed to make all her characters human, flawed, real, and almost impossible to empathize with. You understand some of them, you even see yourself think or act the same, but none of it is something you would want to see yourself do. Also, while a lot of the people in the book are caught in an abuse cycle, none of them is actually stuck there. They can leave at any time. Perhaps this is the most intriguing and interesting point of the story: even the most horrible things that we do to each other require some form of consent from the victims, some form of submission, without which the abuse would never happen or at least, not last too long.

In conclusion, I am sure there are a lot of people that will enjoy the hell out of this book. People oriented, feeling focused people, perhaps. I had difficulty making myself finish it, even fully conscious that the writing was very good. But this is my review, so I will not grade this above average. Probably it is a good idea to watch Cannibal Holocaust first, even if the movie is only an inspiration for the book.

After my disappointment with the Firefox for Android lack of proper bookmarks API implementation, I was at least happy that my Bookmark Explorer extension works well with Firefox for desktop. That quickly turned cold when I got a one star review because the extension did not work. And the user was right, it didn't! One of the variables declared in one of the Javascript files was not found. But that only happened in the published version, not the unpacked one on my computer.

Basically the scenario was this:
  1. Load unpacked (from my computer) extension
  2. Test it
  3. Works great
  4. Make it a Zip file and publish it
  5. Shame! Shame! Shame!

Long story short, I was loading the Javascript file like this: <script src="ApiWrapper.js"></script> when the name of the file was apiWrapper.js (note the lowercase A). My computer file system is Windows, couldn't care less about filename casing, while the virtual Zip filesystem probably isn't like that, at least in Firefox's implementation. Note that this error only affected Firefox and not Chrome or (as far as I know - because it has been 2 months since I've submitted the extension and I got no reply other than "awaiting moderation") Opera.