Saturday 26 October 2019

book cover I haven't been as frustrated with a book as with Lightless for a long time. Everyone in it is incompetent to the level of cretinism. The only people remotely good at what they do are psychos, all of them.

I understand why books like these need to be written: when you write a character based play-like story you become a better writer, but it doesn't mean what you write is any good. In this case, a character based story has cardboard shapes moving around randomly instead of characters. It failed. The main character is a computer programmer. As one, I felt insulted that C.A. Higgins believes we are that moronic.

As for the plot, that's the most redeeming factor, but it's not great either. In a future where mobile devices don't exist and locks are still based on physical keys and the Solar System is under the iron boot control of ... err... The System, an organization straight out of Blake's 7, with the same cartoonish efficiency, a mysterious ship is boarded by two people who turn out to be criminals the System wants. 90% of the book is people being dumb and talking to each other, all while assuming they are the bread of the universe. The rest is people doing really dumb things.

Conclusion: all the "smart" bits of the book were obvious from the start, making the journey of the buffoons in the story to figure them out really boring. The idea of the Ananke was added only to make this, of course, a trilogy. It reads like a theater play with people being stuck in a room.

FizzBuzz for the next generation

FizzBuzz is a programming task that is often used for job interviews, because it shows the thinking of the candidate in an isolated and concrete case. The requirements may vary slightly, but is goes like this: A loop is going through numbers from 1 to 100. The candidate must write the code in the loop that will display, for each number, a string. This string is: "Fizz" for numbers divisible by 3, "Buzz" divisible by 5 and "FizzBuzz" for numbers that are both divisible by 3 and 5. For all other numbers, just display that number.

There have been many implementations of this, for example my own in JavaScript from a while ago and FizzBuzz Enterprise Edition, which is always a good read about how not to complicate your code. However, since I've last written about it, JavaScript has changed, so I felt compelled to write an updated version. And here it is:
(d=n=>('0369'.includes((f=n=>n>9&&f([...''+n].reduce((s,v)=>+v+s,0))||n)&&f(n))&&'Fizz'||'')+(/[05]$/.test(n)&&'Buzz'||'')||n)*(i=n=>n>100||console.log(n+': '+d(n))+i(n+1))*i(1)

Among the abominations there, some of them inspired by C++ because why not, there are some of the new JavaScript constructs, like arrow functions and the spread operator. I know it seems pointless, but it's not: try to understand what the code does. If you want to see it in action, open Dev Tools in any browser and copy paste it in the console.

Tuesday 22 October 2019

Adding comments to SQL code generated by Entity Framework Core

A funny feature that I've encountered recently. It's not something most people would find useful, but it helps tremendously with tracing and debugging what is going on. It's easy, just add .TagWith(someString) to your LINQ query and it will generate comments in SQL. More details here: Query tags.

Code Coverage in .NET Core

One of the best things you could do in software is unit testing. There are tons of articles, including mine, explaining why people should take the time to write code in a way that makes it easily split into independent parts that then can automatically tested. The part that is painful comes afterwards, when you've written your software, put it in production and you are furiously working for the second iteration. Traditionally, unit tests are great for refactorings, but when you are changing the existing code, you need not only to "fix" the tests, but also cover the new scenarios, allow for changes and expansions of existing ones.

Long story short, you will not be able to be confident your test suite covers the code as it changes until you can compute something called Code Coverage, or the amount of your code that is traversed during unit tests. Mind you, this is not a measure of how much of your functionality is covered, only the lines of code. In Visual Studio, they did a dirty deed and restricted the functionality to the Enterprise edition. But I am here to tell you that in .NET Core (and possibly for Framework, too, but I haven't tested it) it's very easy to have all the functionality and more even for the free version of Visual Studio.

These are the steps you have to take:
  • Add coverlet.msbuild NuGet to your unit tests project
  • Add ReportGenerator NuGet to your unit tests project
  • Write a batch file that looks like
    @ECHO OFF
    dotnet test "YourProject.csproj" /p:CollectCoverage=true /p:CoverletOutputFormat=\"opencover\" /p:CoverletOutput=bin/coverage --collect:"code coverage"
    "..\packages\reportgenerator\4.3.0\tools\netcoreapp3.0\ReportGenerator.exe" "-reports:bin\coverage.opencover.xml" "-targetdir:bin/CoverageReport" "-assemblyfilters:-*.DAL*" "-filefilters:-*ServiceCollectionExtensions.cs"
    start "Code Coverage Report" "bin/CoverageReport/index.htm"
    
    and save it in your unit test project folder
  • Optional: follow this answer on StackOverflow to be able to see the coverage directly in Visual Studio

Notes about the batch file:
  • 4.3.0 is the current version of ReportGenerator, change it with whatever version you have
  • the DAL filter tells the report to ignore projects with DAL in their name. You shouldn't have to unit test your data access layer.
  • the ServiceCollectionExtensions.cs filter is for files that should be ignored, like extension methods rarely need to be unit tested

Running the batch should start dotnet test and save the result in both coverage.opencover.xml and also some files in the TestResults folder. Then ReportGenerator will generate an html file with the coverage report that will get open at the end. However, if you followed the optional answer, now you are able to open the files in TestResults and see what parts of your code are covered when opened in the Visual Studio editor! I found this less useful than the HTML report, but some of my colleagues liked the option.

I hope this helps you.

Ascension (Tangled Axon #1), by Jacqueline Koyanagi

book cover If you want a book about women feeling stuff and constantly interrupting each other whenever they are about to communicate anything relevant while acting like space pirates in a desolate corporate universe, but doing nothing particularly consequential, Ascension is the book for you.

It is the distant future: space is called The Big Quiet, the universe has turned into a cosmic version of bankrupt Detroit because of the infusion of magic tech coming from a different universe (well, it's baryonic matter infused with human will, but yeah... magic) and all major characters are women and most of them are lesbian. About what you would expect from Jacqueline "(J)" Koyanagi, who describes herself via marketing as "writes science fiction and fantasy featuring women of color who love other women, disabled characters, neuroatypical characters, and diverse relationship styles.".

The main character is a female engineer (ugh, space surgeon) that falls in love with a peg leg female captain of a starship (that she also falls in love with) while being pursued by the authorities for something they didn't do. The physical attraction between the two girls is so strong that events like death of her family or genocide are just pushed in the background.

I guess we need books like these to realize how someone might act annoyed with books that only contain straight male characters, but other than that this is just low quality space pulp. And this trend is taken to a point so extreme that in the whole book there are only three males: a man who is part wolf, full of muscle, brooding silence and the occasional snarl, a security guard who is incapacitated before acting and the husband in a random family who's first act is to isolate and attack the protagonist before also being quickly disabled. I pity women who see males like this.

Bottom line: I read it all just to see if behind all the agenda bullshit there was anything interesting related to story or characterization or world building. But no.

Beer Money: A Memoir of Privilege and Loss, by Frances Stroh

book cover The autobiography of an artistic daughter of a beer tycoon, Beer Money has almost nothing to do with beer, but everything to do with how we can't really choose your family and how toxic interacting with them can be. I liked the writing and sad as it is, the book was not meant to be dramatic, only truthful.

It was a difficult book to finish, even as it was very personal, as I like biographies to be. Mostly because it is just biographical, with nothing in the lives of the characters that has any meaning. The only lesson one can learn from the book is that once you realize your family is crap, you should stay away, no matter how difficult it would be. A very valuable lesson, I agree, but singular.

Frances Stroh is part of the old German family that introduced fire brewed beer to the US on a large scale. Their Detroit empire imploded from bad management by family members, the collapse of the car industry and so on. And while that was going on, she had to contend with a passive mother, a father with an inflated ego who couldn't care less about the people around him unless in rare moments that seemed like a heavenly gift to respect and love deprived children, siblings who went into drugs and alcohol to avoid the pain and last but not least the lukewarm reaction of the world to her own artistic ambitions.

The author seems to have accepted her fate and the strained love/disappointment relationship with the most important people in her life. I liked it and I thought Frances Stroh has a gift for melancholic writing, but I can't really recommend it to most people.

Wednesday 16 October 2019

Epiphany! Why political correctness is wrong.

Just has a revelation. There are studies that show the moment you introduce currency in a social transaction, the dynamics change dramatically, leading to conflict, selfishness and the dissolution of societal and even emotional bonds. For a random reference check this article: Why Good Deeds and Money Don’t Mix.

I've been struggling with this new political correctness movement because 1) I didn't get it 2) almost every one of the people actively acting offended in this context appears to be... not nice and 3) it doesn't seem to be helping any. So, am I the bad guy? I started to ask myself. Am I a racist homophobic sexist misogynistic normie white male working in the tech field or is there something else going on? Judging by how far from normie people who actually know me think I am, I started to think about it more.

And it came to me! Political correctness is a form of currency forcefully introduced into our social transactions. Not only is it causing trouble for people who are assholes, but also for normal people who suddenly feel they have to pay something. And, as currency does, it breaks society, not strengthens it.

That is why so many people caught in this are so violent and partisan about it. That is why when you are nice towards a - I don't even know how to call them these days - not white person it feels good, as it would being nice towards anybody else, but when you are forced to do it, it well... feels forced. It feels like duty, like work, like paying a tax. The concept of balance slowly creeps in and makes one push back. Maybe with a joke, maybe with an angry tweet, maybe with something worse like actually picking on someone for their skin color, sex, age, religion or anything else. And they do it because picking on someone for being... I don't know... Romanian, doesn't feel like restoring anything. And now Romanians are pretty angry, because offending Jewish people or of recent African descent is somehow "wronger", so they get offended and feel left out. It's wrong to pick on anyone either way, deal with it!

In the end, introducing currency just pushes people into two diametrical opposed groups: the payers and the people who are owed. And of course, the people who ride the wave and get their little percentage to convert it to any other currency: money, hate, power, etc. We become slaves to the middlemen even when we interact with other people! Hell, they want to introduce ethics for computers now. Where does it end?!

So, as I am an egalitarian in my misanthropy, I submit that you should get offended by people just like any other person would. Leave currency to bankers. Or pick on them! No one ever got into a twist for calling bankers names.