Tuesday, January 26, 2016

Write Right!: Creative Writing Using Storytelling Techniques, by Kendall Haven

Book cover Write Right! is a monster. It goes through every step of writing a book, including the one that the author, Kendal Haven, considers the most important: editing. Then, in its second half, it contains exercises for improving writing. The intended audience of this book is teachers of creative writing, not just beginner writers, so that makes it even more valuable.

The mystery for me was how can someone write about captivating and engaging writing in a book as dry as Creative Writing Using Storytelling Techniques. I understand it is mostly a manual, but it was really difficult to go through it, as it was full of information start to finish. Now I must reread it at speed and make a summary of the techniques in order to even begin to absorb the huge amount of very useful information in the work. Not to mention actually doing the exercises at the end.

What I really liked about this book is that it is very algorithmic. At every page I was considering - and still am - how I might codify this into a software to help me evaluate a piece of literature and maybe even suggest improvements automatically. If I am to extract an essential idea of the work it would be "editing is very important". The author acknowledges the need to write fast, from your gut, to lay the words out there, not even considering spelling or grammar, just vomit your thoughts onto the page, but then he submits that the process of evaluating each scene, each chapter and the book for structure, wording, verb uses, sense involvement, specificity of language, action, dialogue, sequels (not book sequels, but that thing that details what characters think and feel about what just happened), etc. is perhaps the most important in translating that story that you have into an interesting book to read. And after getting a final version you are happy about, he makes you eliminate 15% of the words. Ruthless! :)

Let me make this clear, though: writing is damn tough. It consists of two parts: observing the world and describing the world. In a recent post I was complaining at how bad I am at the former, but this book makes it clear how complex is the latter. Making the written word express what is in your brain at the moment of creation is extremely difficult and complicated. This book helps in defining exactly what that is and give you tools to do it and improve on doing it. A great tool!

To sum it up: This is not light reading. It is a manual for writing teachers (what the hell are those? I wish I had some in school). It helps tremendously if you are self-taught, also. It requires multiple readings or at least a summarizing effort at the end, to structure it in a way that makes it easy using it as a reference. And then, of course, are the exercises for improving writing which take the second half of the book

Thursday, January 21, 2016

Patterns for Parallel Programming: Understanding and Applying Parallel Patterns with the .NET Framework 4, by Stephen Toub

Patterns of Parallel Programming Stephen Toub wrote this document, as he calls it, but that is so full of useful information that it can be considered a reference book. A 118 pages PDF, Patterns for Parallel Programming taught me a lot of things about .NET parallel programming (although most of them I should have known already :-().

Toub is a program manager lead on the Parallel Computing Platform team at Microsoft, the smart people that gave us Task<T>, Parallel, but also await/async. The team was formed in 2006 and it had the responsibility of helping Microsoft get ready for the shift to multicore and many-core. They had broad responsibility around the company but were centered in the Developer Division because they believed the impact of this fundamental shift in how programming is done was mostly going to be on software developers.

It is important to understand that this document was last updated in 2010 and still some of the stuff there was new to me. However, some of the concepts detailed in there are timeless, like what is important to share and distribute in a parallel programming scenario. The end of the document is filled with advanced code that I would have trouble understanding even after reading this, that is why I believe you should keep this PDF somewhere close, in order to reread relevant parts when doing parallel programming. The document is free to download from Microsoft and I highly recommend it to all .NET developers out there.

Date Published: 7/16/2010 File Size: 1.5 MB

Tuesday, January 19, 2016

SpaceX first stage landings on a sea barge: Three failures should be a strong indicator of a design flaw

Falcon 9 first stage explodes on barge In January 2016 SpaceX made history by landing the first stage of a rocket that they have just launched. I know, Blue Origin did it first, but SpaceX rockets are designed for GEO orbits, while Bezos' reusable rocket is for LEO, so different animals. However, they have tried doing the same three times, last time just yesterday, only landing on a special barge at sea. Each time this have failed. But let's watch the three attempts, see what's going on.

First time, a year ago, January 2015, you can see that something was wrong with the way the stage came down, it was already angled and the horizontal speeds were really high.


Second time, three months later in April 2015, it almost got it right:


Third time, yesterday, 18 December 2016, it actually landed, then a landing leg gave out:


But what happened? Each time the stage reached the landing spot, each time in a vertical position and with low vertical speeds. Every time the engine exploded it did when the stage tried to stop and fell over. Wouldn't a specialized grabbing mechanism have prevented some of these accidents? Maybe even the first one!

Now, I understand that the purpose of SpaceX is to have a first stage that can land anywhere, and so they must rely on their device only, assuming nothing of the landing site, but once they go through the engineering issues, just catch it in a net, intersect three metal cables to support the upper part of the stage, do something. Look of those things, slowly falling down: you want to jump and catch them, like you would a drunken friend. Make your rocket understand it's not alone, Elon, that it's got our support! :)

Seriously now, I can't even imagine what would happen if the wind started blowing harder while the rocket tried to land on the barge. Since you have a specialized landing vehicle, make it better. The rocketry is fine, it is time to work on the support infrastructure with just as much aplomb and creativity.

3 and 9 Feb, Bucharest: ReactiveX in .NET

Rx for .Net On the 3rd and 9th of February I will be presenting a demo of Reactive Extension in action on a Windows Presentation Foundation app that I am going to be building as I speak, first without and then with Rx. The presentation should be about 30-45 minutes, in Romanian, but I am sure we can accommodate foreign speakers by doing it in English if you request it. These events are all free, but you must register in order to know how many people to prepare for. Here are the Meetup links:
ReactiveX in Action, Wednesday, February 3 2016, 19:00, Impact Hub, Strada Halelor 5, Bucharest
MsSql / Reactive Extensions, Tuesday, February 9 2016, 19:00, Electronic Arts - Afi Park 2, Bulevardul General Vasile Milea 4F, București 061344
See you there!

Monday, January 18, 2016

Facebook won! I created an account...

So I've finally created a Facebook account. Yes, it won. I also accessed the Twitter one I created a few good years before and never used. These new social accounts will probably be used to publish what I post here, but anyway, I've updated the blog layout with my Facebook and Twitter accounts (see the icons top right).

Wednesday, January 13, 2016

Apologies for people from domains like co.uk or co.in, etc.

It seems that for a very long time, since Blogger implemented the ugly system that changes the blog domain to a local domain, my blog was inaccessible for people in the UK and other places where the domain country had more segments, like co.in, co.uk, com.au, etc. due to a bug in my solution for it. I need to apologize for that. I fixed the problem now, but damn it is a long standing bug, a full three years.

Saturday, January 09, 2016

You can use C# version 6 features right now, and how glorious they are!

Some of you may have heard of C# 6, the new version of the Microsoft .NET programming language, but what I am not certain about is that you know you can use it right now. I had expected that a new version of the language will be usable from the brand new upcoming fifth version of the .NET runtime, but actually no, you can use it right now in your projects, because the new features have been implemented in the compiler, in Visual Studio and, you have no idea how cool it is until you try, in ReSharper.

One might say: "Hell, I've seen these syntactic sugar thingies before, they are nothing but a layer over existing functionality. New version, my ass, I stick with what I know!", but you run the risk of doing as one of my junior developer colleagues did once, all red faced and angry, accusing me that I have replaced their code with question marks. I had used the null-coalescing operator to replace five line blocks like if (something == null) { ....

Let me give you some examples of these cool features, features that I have discovered not by assiduously learning them from Microsoft release documents, by but installing ReSharper - only the coolest software ever - who recommends me the changes in existing code. Let's see what it does.

Example 1: properties with getters and no setters

Classic example:
public int Count {
  get {
    return _innerList.Count;
  }
}

Same thing using C# 6 features?
public int Count => _innerList.Count;
Cool or what?

Example 2: null checking in a property chain

Classic example:
if (Granddaddy!=null) {
  if (Daddy!=null) {
    if (Child!=null) {
      return Grandaddy.Daddy.Child.SomeStupidProperty;
    }
  }
}

Same thing using C# 6 features?
return Grandaddy?.Daddy?.Child?.SomeStupidProperty;
Convinced yet?

Example 3: using the name of members as strings

Classic example:
public int Number {
  get { return _number; }
  set {
    if (_number!=value) {
      _number=value;
      OnPropertyChanged("Number");
      //with some custom code you could have used a better, but slower version:
      //OnPropertyChanged(()=>Number);
    }
  }
}

C# 6 version?
public int Number {
  get { return _number; }
  set {
    if (_number!=value) {
      _number=value;
      OnPropertyChanged(nameof(Number));
      // this assumes that we have a base class with a method called OnPropertyChaged, but we can already to things inline:
      PropertyChanged?.Invoke(this,new new PropertyChangedEventArgs(nameof(Number))
    }
  }
}

Example 4: overriding or implementing simple methods

Classic example:
public override string ToString() { 
  return string.Format("{0}, {1}", First, Second);
}

Now:
public override string ToString() => $"{First}, {Second}";

Example 5: exception filters

Classic example:
try {
  SomethingUnpredictable();
}
catch (Exception e) {
  if (e.InnerException!=null) {
    UnpackAndLogException(e);
  } else {
    throw;
  }
}

C# 6 version:
try {
  SomethingUnpredictable();
}
catch (Exception e) when (e.InnerException!=null) {
    UnpackAndLogException(e);
}

Example 6: using static

I don't particularly like this, but it can simplify some code when used right. Classic example:
return degrees*Math.PI/180;

C# 6 way:
//somewhere above:
using static System.Math;

return degrees*PI/180;

There are other more complex features as well, like special index initializers for Dictionary objects, await in catch and finally blocks, Auto-property initializers and Primary Constructors for structs. You can use all these features in any .NET version 4 and above. All you need is the new Roslyn compiler.

Enjoy the new features. I know I will!