CategoryRamblings

How I almost lost all my source codes.

Now sit down my dear and listen carefully, I’ll tell you a story about how I almost lost all my sources.
A while ago, I decided to give my marvelous Macbook pro mid-2013 an upgrade. I searched online a little bit and at the end I bought an SSD drive, a Corsair Force LE 240GB

“But 240 is not enough!” you might say.  “You’re right”. It’s not enough. 

I was not using the DVD drive at all so after a brief research, I found the right adapter and replaced it with the old 500gb Apple disk , leaving space for my shiny new SSD.

Everything was perfect, El Capitan was lightning fast, everybody was happy. But then came the day that I needed Windows. So Bootcamp joined us and new partitions started to appear.

180GB OSX Extended and 60GB NTFS on the SSD.
450GB OSX Extended and 50GB exFAT on the ol’ Apple disk.

Again, everything was perfect, El Capitan was still lightning fast, Windows 10 was running fine, everybody was happy.

I was running Windows from the SSD and all the programs were installed on the other drive, together with all the source codes. Yes, before you ask, I have a Bitbucket account. Yeah, a Github one too, but Bitbucket gives you private repos for free.

However, after a while, I realized that when Win10 goes to sleep mode some strange misbehavior appears, in the form of weird SMART messages when turning on MacOs.

Long story short, one day I rebooted from Win to MacOs and puff! the partition with all the sources was gone. Disappeared. An empty, dark and cold space.
I almost got an heart attack.

Disk Util, Disk Warrior, mysterious command line tools, I tried everything, nothing worked. After hours of researches and curses, I fired up Windows and did the only thing I had left:

chkdsk e: /f

That saved my day.

Moral of the story? Always backup your source codes, even the most insignificant snippets.

29/09/2016

I married a wonderful woman.

The fact that she’s my high school crush just makes everything more magical.

To be honest, sometimes I feel like I am in a tv show for teens, like Dawson’s Creek or Beverly Hills 90210…

And now I am sitting here, in the house we are still decorating together, while she’s taking care of me ( I got high fever the day after the wedding ) and our pregnant cat meowing at us.

I love you, iLa.

 

Edge Guardian available on Steam!

This time I just want to spread the word about my two good friends Maurizio and Marco from Hypotermic Games, who have finally got the chance to publish their first game on Steam, Edge Guardian !

In a nutshell, it’s an action beat-em-up for the HTC Vive where you’ll find yourself in a cube-based world, forced to punch your way out through thousands of enemies.

I don’t own an HTC Vive, but even if I haven’t had the possibility to try the game, I can easily say that it’s gonna be really addictive. Take a look at the gameplay if you don’t trust me.

Good luck guys!

This time the answer is 34.

I am turning 34.

Yesterday I was writing my Master Thesis. I was 24.

The day before I was playing the drums at my 18th birthday party.

Now I am a father, the CTO of a small software company, and share my days (and nights) with a beautiful woman. I am definitely not complaining, but sometimes I feel like I am missing something. Time mostly.

Time has become slippery, acquiring momentum and now is rolling faster and faster. Every day I tell myself I need to stop and learn to take care of the little things…and every night I go to sleep cursing me for not being capable enough.

In my next life I want to be a cat.

CQRS: on Commands and Validation

Let’s have a quick discussion about CQRS. There’s a lot to say to be honest, so let’s try to focus on just one thing today: validating your Commands (who knows, I could start a series after this, we’ll see).

The idea is simple: how can I make sure that the data I am passing to my Command Handler is valid?

Also, what is the definition of “valid” ?

There are several aspect to take in consideration, several “levels” of validation. I could just make sure the Command object is not null and/or the data it contains is not empty. Or I could run the validation against some kind of context and check the application Business Rules.

As you can imagine, having different levels means that we could have different implementations scattered in various places/layers of our architecture. For example I could have the API Controller (or whatever outmost layer you have) check for null and perform some Business Context validation later, before or directly in the Command Handler.

In my last project however, I decided to keep things simple and keep my validation in just one place.

Initially the right spot was the Command Handler itself, but of course this would have violated the SRP.

A quick and immediate solution was to have a separate instance of a IValidator<TCommand> injected in the handler. Easy.

Then I realised that my handlers are more “close to the metal” than expected: in most of the cases they access directly the DAL (passing through some kind of IDbContext) and I didn’t wanted to rewrite the call to the IValidator in case I had to switch the persistence layer.

Luckily enough, there’s a nice pattern that came into rescue: the Decorator! As explained very clearly on the SimpleInjector docs, you can create a ValidationCommandHandlerDecorator class, inject an IValidator<TCommand> and let your IoC do the rest.

Maaaaagic.

Bonus tip: in some cases you may want to skip completely the validation. Maybe you have a very good reason or maybe you’re just lazy. Whatever.

In this case, all you have to do is to write some kind of NullValidator<TCommand> class and instruct your IoC to use it when a specific validator is missing for that Command.

© 2017 Davide Guida

Theme by Anders NorenUp ↑