Thursday, 11 February 2016

The Ann Leckie Ancillary series... it sucks!

all three book covers I really missed reading a good science fiction book and when I was in this vulnerable mental state I stumbled upon this very positive review on Ars Technica recommending Ann Leckie's trilogy Ancillary. Ars Technica is one of the sites that I respect a lot for the quality of the news there, but I have to tell you that after this, my opinion of them plummeted. Let me tell you why.

The only remotely interesting characteristics of the Ancillary series is the premise - that an AI gets trapped in the body of an "ancillary" soldier that was used as only a physical extension among many others - and the original idea of using no gender when talking about people. You see, in the future, the empire language has lost its need of defining people by gender and therefore they are all she, mother, sister, etc. It is important that the genre is translated into our backward English is all female, as to balance the patriarchal bias of our society. Way to go, Ann! The books also won a ton of awards, which made me doubt myself for a full second before deciding that notorious book awards seem to be equally narrow in focus as notorious movie awards.

Unfortunately, after two books that only exposed antiquated ideas of space operas past, boring scenes and personal biases of the author, I decided to stop. I will not read the third book, the one that maybe would give me some closure as the last in the series. That should tell you how bad I think the books were. On a positive note it vaguely reminded me of Feintuch's Seafort Saga. If you want to read a similarly out of date space opera, but really good and captivating, read that one.

You see, it all happens on ships and stations, where the only thing that doesn't feel like taken from feudal stories are... wait... err... no, there is nothing remotely modern about the books. The premise gets lost on someone who focuses exclusively on the emotions of the Artificial Intelligence, rather than on their abilities or actual characteristics. If I were an AI, I would consider that discrimination. The same ideas could be put in some magical kingdom where magical people clone themselves and keep in touch. I don't know who invented this idea that the future will somehow revert to us being pompous boring nobles that care about family name, clothes, tea and saucer sets (this is from the books, I am not making it up), but enough with it! We have the Internet. And cell phones. That future will not happen! And if it would, no one cares! The main character acts like a motherly person for stupid or young people, no doubt reflecting Leckie's mood as a stay-at-home mom at the time of writing the books. You can basically kill people with impunity in this world of hers, if you are high enough on the social ladder, but swearing is frowned upon, for example.

OK, ranted enough about this. I don't care that her vision of the future sucks. I wouldn't have cared if her writing was bad - which it isn't. It's not great either, though. I do care when I get flooded with review titles like "The book series that brought space opera into the 21st century", by Annalee Newitz, or "Ancillary Justice is the mind-blowing space opera you've been needing", by Annalee Newitz, or "Why I’m Voting for Ann Leckie’s Ancillary Justice", by Justin Landon - a friend of Annalee Newitz' from the Speculative Fiction compilations, and "A mind-bending, award-winning science fiction trilogy that expertly investigates the way we live now.", by Tammy Oler, who is writing with Annalee Newitz at Bitch Media. Do you see a pattern here?

I have to admit that I think it is a feminism thing. So enamored were these girls of a story that doesn't define its characters by gender, that they loved the book. Annalee's reviews, though, are describing the wonderful universe that Leckie created, with its focus on social change and social commentary, and how it makes one think of how complex things are. I didn't get that at all. I got the typical all powerful emperor over the space empire thing, with stuck up officers believing they know everything and everything is owed to them and the "man/woman of the people" main character that shows them their wicked ways. The rest is horribly boring, not because of the lack of action, but because of the lack of consequence. I kind of think it's either a friend advertising for another or some shared feminist agenda thing.

Bottom line: regardless of my anger with out of proportion reviews, I still believe these books are not worth reading. The first one is acceptable, while the second one just fizzles. I am sure I can find something better to do with my time than to read the third. The great premise of the series is completely wasted with this author and the main character doesn't seem to be or do anything of consequence, while moving from "captain of the ship" to "social rebel" and "crime investigator" at random.

Wednesday, 10 February 2016

I presented an introduction on Reactive Extensions at ADCES

My ugly mug next to my beautiful code On the 9th of February I basically held the same talk I did at Impact Hub, only I did better, and this time presented to the ADCES group. Unbeknownst to me, my colleague there Andrei Rînea also held a similar presentation with the same organization, more than two years ago, and it is quite difficult to assume that I was not inspired by it when one notices how similar they really were :) Anyway, that means there is no way people can say they didn't get it, now! Here is his blog entry about that presentation: Bing it on, Reactive Extensions! – story, code and slides

The code, as well as a RevealJS slideshow that I didn't use the first time, can be found at Github. I also added a Javascript implementation of the same concept, using a Wikipedia service instead - since DictService doesn't support JSON.

Wagakki Band - Akatsuki no Ito

Japanese culture is certainly special. The music, the drawing style, the writing, the cinematography, they are all easily recognizable and usually of high quality. Yet I think it is even cooler when artists are able to blend Japanese feeling with Western cultural artifacts. Check out this Japanese traditional sound... made metal: Akatsuki no Ito (The Thread of Dawn?)

Friday, 5 February 2016

Modifying collections from different threads and still binding it via WPF

angry developer This post is discussing the solution to the NotSupportedException "This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread" and also the InvalidOperationException "An ItemsControl is inconsistent with its items source".

In the first case you want to bind in Windows Presentation Foundation a collection property from your viewmodel and it says no. What happens is that you are using a BindingList<T> or an ObservableCollection<T> and the binding system is using in the background a CollectionView that wraps it which does not support changes via multiple threads. The solution to this is rather simple: use this piece of code:
BindingOperations.EnableCollectionSynchronization(collection, lockObject);
This short blog post from Florent Pellet explains things a little, but that is ending on a dire note: The ViewModel becomes dependent on the view It also suggests that you need to create a lock object for each UI thread, if you have more.

This works in .NET 4.5 and that is the reason that when you are looking the exception up you get all kind of answers that either suggest you invoke any changes on the Dispatcher UI thread (which I believe is against the idea of having a viewmodel) or weird bastardizations of the collection classes used, like trying to invoke the events for list changes on the dispatcher of the invoking delegate. I've tried that and I got the second InvalidOperationException exception that I will be covering later on :)

But let's go further and examine what is going on. If you look at the method declaration, EnableCollectionSynchronization also allows specifying a synchronization callback, something that you could use to manage weird custom collection classes. The Remarks sections says When you call this overload of the EnableCollectionSynchronization(IEnumerable, Object) method, the system locks the collection when you access it, which implies you are losing some performance, but not much else. In case you have many parallel threads that are modifying your collection, you need to lock it, anyway. You may, of course, create your own high performance system of changing a collection and, maybe, run a separate method to marshal changes from your private data structure to the UI bound one.

Now, the InvalidOperationException "An ItemsControl is inconsistent with its items source" is thrown when the ItemsSource property has become out of sync with the Items property, which is usually generated by the ItemsControl. So when I tried to create my own badass collection class, I managed to avoid the first exception and I got this one. The same solution applies to both cases:
BindingOperations.EnableCollectionSynchronization(collection, lockObject);
Funny enough, you have to run this piece of code on the Dispatcher UI thread.


But where to use it? It would be rather simple to use it in the viewodel constructor, using the ((ICollection)collection)SyncRoot object, or even in the constructor of a class that inherits from either BindingList or ObservableCollection and has nothing but this type of initialization. I believe that, since this is a binding issues, something within WPF, then the binding system should handle it, like some type of synchronizing Binding. For a second I thought that the IsAsync property of the Binding class would solve this by itself, but it wouldn't work. Also, Binding doesn't have any methods to override and BindingBase is an abstract class with internal methods to implement, which of course doesn't work. Otherwise it would have been OK, I believe, to create a special SynchronizedCollectionBinding class that enables collection synchronization at bind time. BTW, if you are thinking to implement everything starting with MarkupExtension, forget it. The Binding class is a bit hardcoded in Visual Studio and it wouldn't actually work as expected.

That's it, folks!

Wednesday, 3 February 2016

I presented an introduction on Reactive Extensions at Impact Hub

Reactive Extensions logo Today I was the third presenter in the ReactiveX in Action event, held at Impact Hub, Bucharest. The presentation did not go as well as planned, but was relatively OK. I have to say that probably, after a while, giving talks to so many people turns from terrifying to exciting and then to addictive. Also, you really learn things better when you are preparing to teach them later, rather than just perusing them.

I will be holding the exact same presentation, hopefully with a better performance, on the 9th of February, at ADCES.

For those interested in what I did, it was a code only demo of a dictionary lookup WPF application written in .NET C#. In the ideal code that you can download from Github, there are three projects that do the exact same thing:
  1. The first project is a "classic" program that follows the requirements.
  2. The second is a Reactive Extensions implementation.
  3. The third is a Reactive Extensions implementation written in the MVVM style.

The application has a text field and a listbox. When changing the text of the field, a web service is called to return a list of all words starting with the typed text and list them in the listbox, on the UI thread. It has to catch exceptions, throttle the input, so that you can write a text and only access the web service when you stop typing, implement a timeout if the call takes too long, make sure that no two subsequent calls are being made with the same text argument, retry three times the network call if it fails for any of the uncaught exceptions. There is a "debug" listbox as well as a button that should also result in a web service query.

Unfortunately, the code that you are downloading is the final version, not the simple one that I am writing live during the presentation. In effect, that means you don't understand the massive size reduction and simplification of the code, because of all the extra debugging code. Join me at the ADCES presentation (and together we can rule the galaxy) for the full demo.

Also, I intend to add something to the demo if I have the time and that is unit testing, showing the power of the scheduler paradigm in Reactive Extensions. Wish me luck!

Monday, 1 February 2016

I was at FOSDEM'16

Long story short: I thought FOSDEM 2016 was terribly non-technical.

The entire conference took place at the ULB Solbosch Campus in Brussels, Belgium, which is composed of several buildings in which many rooms are being used for presentations. That meant that not only you had to plan the speeches that you wanted to attend to, but also consider the time it took to move from one building to another (in the cold and rain). Add to this the fact that the space was still insufficient for most talks, and if you didn't get there before the talk started, it wasn't uncommon to find the room full and be turned down at the door for security reasons (meaning fire hazards and the likes, not stupid terrorism). I thought the mobile app FOSDEM Companion was very helpful in keeping track of what is what and where and when.

The talks themselves, though, were mostly 20-25 minutes long. While some reached to 45 minutes, most of them were short presentations of one product or another. Someone would speak in front of a Powerpoint (or some alternative) slide and the most common template was: "I am X I work at Y and we are doing product Z. Here is a history of the product, here is what it can do for you and you can find more at these links." They were open source and free, alright, but other than that it felt like it was a marketing conference, not a technical one. I have seen only one presentation that included actual code.

This doesn't mean I didn't enjoy myself. I've met old friends and some of the presentations were really interesting. I was particularly impressed by something called Ring, which is a completely peer to peer and securely encrypted communication system. Basically it allows you to find people, talk to them (via text, sound, video), while having no central server. It was something that I was looking for and that uses DHT as a discovery mechanism.

So my conclusion is that if you are not there for a specific project or topic, so that you end up finding the people that are interested in the same thing and network with them, FOSDEM is pretty superficial. The talks were recorded and the videos will slowly appear on the FOSDEM video archive site, so actually going there just to see the presentations alone might not be necessary. Being from a slightly different technical domain, I wasn't interested in socialization, and I think that was my biggest mistake.

The people there looked interesting. A friend of mine summarized it well: "one of the few places where there is a queue at the men's bathrooms and not at the women's". There were of course plenty of facially haired, pony-tailed, black leather wearing, Linux laptop carrying hackers running around, but most of the people there didn't look that young or that "hacky". In fact, I think the age average was probably around 40.

That's about it for my FOSDEM report. If you need any more information, leave me a comment and I will fill any holes in the description.

Update:
The talks that I went to and I liked were these:

The Last Policeman, by Ben H. Winters

Book cover This book was recommended by Jeff Atwood, of Coding Horror and Stack Overflow fame. He liked it, I wasn't impressed. In The Last Policeman, Ben H. Winters attempts to describe a world that is powerlessly waiting for the arrival and impact of a 7km wide asteroid. While smaller than the one that killed the dinosaurs off, it would still pretty much end human civilization and most of the life on Earth. As a result, people are killing themselves in depression, quit jobs to "go bucket list", nothing is working, nothing gets repaired, etc. In all of this, a detective is trying to solve a case that looks like just another suicide, but he feels it's not. It is an interesting concept and it was well written by Winters, but I had difficulty believing in the world he was describing. More than that, except rumors of something Iran is planning there is no mention of any other country. I believe that in this situation a lot of people would inertially and routinely continue what they were doing until they figured out that it doesn't make sense (and that probably it didn't make sense to begin with), but there would certainly be more aggressive social changes that the author completely ignores. Plus that "going bucket list" would certainly become frustrating once you can't go on a cruise because no one is sailing the thing or you can't enjoy your favorite food because the restaurant got closed.

Worse than that, at the end of the book I was pretty satisfied with it. It was short, to the point and while not perfect, it was enjoyable. And then I learn that it is part of a trilogy. This automatically diminishes the act of reading it somehow and the book entire by the fact that I can't convince myself to read the other two books. So yeah, bottom line: I thought it was kind of average.