Monday 3 March 2014

Safe Navigation Operator being considered for c#

One of the highest suggested features on UserVoice is the safe navigation operator. Now Mads Torgersen, PM of the C# Language, has expressed that they are considering implementing the feature. The next couple of months they will do some prototyping.

Why is this good and what is the Safe Navigation Operator?


Well, having a short hand null reference check would lighten up your code. Every time you're checking for null references in your code would get a lot easier and shorter. Lets have a look at it.

Lets say you're going to access an descendant of a given class. Our call would be Class.ChildClass.Property. Lets say for instance that ChildClass is null. We would have to check for a null reference of the Class type and ChildClass to be safe.


With the Safe Navigation Operator we would be able to write Class?.ChildClass?.Property without having to check for null references all the time.


Quite neat! If this is ever going to come to c# let's hope it's the next release. You can read more about the suggestion here.

/JJ


Sunday 2 March 2014

Chocolatey, apt-get for windows!

Chocolatey is simply a Machine Package Manager for Windows. When installing Windows applications, Chocolatey can do it for you in a single line. It will download and install that application with one line only! At the time speaking there are 1644 packages, so a lot of applications are available.

Installing Chocolatey is also a single line:
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin

From there you can just type cinst PackageName like cinst GoogleChrome. Look at Chocolatey's website to find the packages you need.

Enjoy an apt-get like tool for Windows!

/JJ