Object.is

•December 1, 2014 • Leave a Comment

Until now, most people used either the  equals (==) or the identically equals (===) operator to compare two values. The latest was the recommended way to test for identity since it avoids performing type coercion during the comparison. Unfortunately, even the identity equals operator isn’t entirely accurate. Here’s an example:

+0 === –0 //returns true
NaN === NaN //returns false

Fortunately for us, the latest release of the spec introduces the Object.is method, which takes care of the quirks associated with the use of the equal operators. It accepts 2 arguments and returns true when those values are equivalent. Btw, equivalent here means that the values have the same type and the same value. Here’s how to get the correct results for the previous example:

Object.is( +0, –0); //false
Object.is( NaN, NaN); //true

Bottom line: Object.is produces the result that the identity equals operator should have produced for all the existing values and you should use it when writing JavaScript 6 code.

Rest parameters

•November 26, 2014 • Leave a Comment

While taking a look at what’s new in JavaScript 6, I’ve noticed that it introduces the notion of rest parameters. As we all know, we can pass any number of parameters to a function during its invocation. Until now, if we needed to write a function which receives an undefined number of parameters, we could simply use the arguments object from within it to access all the argument values.

With JavaScript 6, we now have the concept of rest parameters. We can use rest parameters to replace the arguments object in several scenarios. Here’s an example of its usage:

function doSomething(first, …items){
  //access first parameter by name
  console.log(first);
  //access remaining parameters through rest parameter
  items.forEach( item => console.log(item) );
}
//here’s an example of calling the function
doSomething(1, 2, 3);

items is a rest parameters. Rest parameters are indicated by 3 dots (…) and must always be the last parameter specified in the function’s parameter list. The name used for the rest parameter (in the previous example, items) allows us to reference an array which contains the values passed to the function. Notice that unlike arguments, the array referenced by the rest parameter contains only the values passed from the position occupied by the parameter in the function signature (in this case, that means it will contain values from the second position onward – if we need to access the first parameter, then we must use the parameter named first).

Before going on, I must say that you can still use the arguments parameter in JavaScript 6 code. So, why bother using rest parameters? Well, if you have some experience in writing JavaScript, you’ve probably noticed the use of the forEach method for iterating though all the values from the second position onward. This method can only be applied to array instances (for now, let’s forget that we’re using a lambda expression to define the callback function expected by the forEach method). If you decide to go with the arguments parameter, you won’t be able to do that because arguments is an object and not a real array. This might be a good enough reason for using the new rest parameters…

One final note, which might be important for deciding between using rest parameters and the arguments object: the arguments object has additional properties which aren’t related with the values passed as arguments (ex.: callee property).

And that’s it for now. Stay tuned for more.

Getting started with kpm

•November 20, 2014 • Leave a Comment

1,2,3, contact!

I’m not sure if there’s anyone still reading this, but I’ve decided to restart writing here again. I’ll be using this blog to document my experiences with the new ASP.NET 5.0 (for which there’s already a VS 2015 preview version). I’ve decided to do this since I won’t be updating my PT books on these subjects.

If you haven’t been living under a rock, you’ve probably heard about the latest release of ASP.NET, aka ASP.NET vNext. vNext is supposed to use a new stack, where you’ll find several of the traditional .NET features split into several packages that you’ll only load when you really need them (pay-for-play model). You’ll also find a new unified web stack, with simple packaging and versioning rules which should ease the problems associated with side by side run of different versions.

The new platform uses a new runtime/SDK, known as KRuntime. In order to get a specific version of the runtime (yes, there are several versions, based on architecture – 32 vs 64 bits – and features – CLR vs CoreCLR), we’ll need to resort to the K Version Manager tool (aka kvm). The docs already have all the details on how to install the kvm tool, so I’ll concentrate on looking at what we can do with it. Before going on, it’s worth it pointing out that kvm is simply a Powershell script, so nothing prevents you from opening it in your favourite text editor and seeing what it does.

One of the first things we’ll need to do is update the runtime to the latest version by using the upgrade option:

kvm upgrade

Running this command will end up upgrading the x86 CLR K runtime and setting it as the default runtime that is being used by your profile. You can always update the amd64 version (64 bits) by writing the following:

kvm upgrade –amd64

Notice that this will also promote the 64 bits as the default active runtime for your profile. And sure enough, you can also update the Core CLR by using the –r option. For instance, here’s how to upgrade the 64 bits Core CRL K runtime and set it as the default:

kvm upgrade –amd64 –r CoreCLR

Since you can have lots of runtime versions installed in a machine, it would be really great to have a way to list all of them. And that’s why there’s a list option:

kvm list

Running the previous command on my machine results in the following:

Active Version     Runtime Architecture Location                    Alias
—— ——-     ——- ———— ——–                    —–
       1.0.0-beta1 CLR     amd64        C:\Users\Luis\.kre\packages
       1.0.0-beta1 CLR     x86          C:\Users\Luis\.kre\packages
  *    1.0.0-beta1 CoreCLR amd64        C:\Users\Luis\.kre\packages default
       1.0.0-beta1 CoreCLR x86          C:\Users\Luis\.kre\packages

As you can see, we’ve ended up getting the Core CLR 64 bit version set up as the default active runtime. Notice also that the active runtime is aliased to the default name. kvm supports aliases operations by using the alias parameter. When used without any more info, it will simply report all the current aliased versions:

PS C:\code\git\home> kvm alias

Alias   Name
—–   —-
default KRE-CoreCLR-amd64.1.0.0-beta1

You can also pass a name to the alias and that will return its associated runtime version. For instance, if I pass it the default name, here’s what I’ll get on my machine:

PS C:\code\git\home> kvm alias default
Alias ‘default’ is set to KRE-CoreCLR-amd64.1.0.0-beta1

Now, as we’ve seen, we have 4 versions installed by default and nothing prevents you from creating alias for them. For instance, here’s how we can create a new alias for the 64 bits Core CLR runtime version:

PS C:\code\git\home> kvm alias CoreCLR64 1.0.0-beta1 -amd64 -r CoreCLR
Setting alias ‘CoreCLR64′ to ‘KRE-CoreCLR-amd64.1.0.0-beta1′

And just to be sure that we did end up getting what we wanted:

PS C:\code\git\home> kvm alias

Alias     Name
—–     —-
CoreCLR64 KRE-CoreCLR-amd64.1.0.0-beta1
default   KRE-CoreCLR-amd64.1.0.0-beta1

PS C:\code\git\home> kvm alias CoreCLR64
Alias ‘CoreCLR64′ is set to KRE-CoreCLR-amd64.1.0.0-beta1

Now, aliases are quite useful because we can use them with the other options that can be passed to kvm. For instance, let’s say that we want to use the Core CLR 64 bits version as the default runtime. Since we’ve created the CoreCLR64 alias, them we can simply pass that name to the kvm use command:

PS C:\code\git\home> kvm use CoreCLR64
Adding C:\Users\Luis\.kre\packages\KRE-CoreCLR-amd64.1.0.0-beta1\bin to process PATH
PS C:\code\git\home> kvm list

Active Version     Runtime Architecture Location                    Alias
—— ——-     ——- ———— ——–                    —–
       1.0.0-beta1 CLR     amd64        C:\Users\Luis\.kre\packages
       1.0.0-beta1 CLR     x86          C:\Users\Luis\.kre\packages
  *    1.0.0-beta1 CoreCLR amd64        C:\Users\Luis\.kre\packages CoreCLR64, default
       1.0.0-beta1 CoreCLR x86          C:\Users\Luis\.kre\packages

If we didn’t had the alias, we’d have to specify the version, CPU and flavour of the CLR we want to use (sure, there are defaults, but my brain is already lagging for my daily tasks, so I won’t really be memorizing any of them):

PS C:\code\git\home> kvm use 1.0.0-beta1 -amd64 -r CoreCLR
Adding C:\Users\Luis\.kre\packages\KRE-CoreCLR-amd64.1.0.0-beta1\bin to process PATH
PS C:\code\git\home> kvm list

Active Version     Runtime Architecture Location                    Alias
—— ——-     ——- ———— ——–                    —–
       1.0.0-beta1 CLR     amd64        C:\Users\Luis\.kre\packages
       1.0.0-beta1 CLR     x86          C:\Users\Luis\.kre\packages
  *    1.0.0-beta1 CoreCLR amd64        C:\Users\Luis\.kre\packages CoreCLR64, default
       1.0.0-beta1 CoreCLR x86          C:\Users\Luis\.kre\packages

As you can see, the result is precisely the same and that’s why I prefer to create an alias in order to reduce the required typing (yes, I’m lazy!).

Whenever you want to remove an alias, you should use the unalias option:

PS C:\code\git\home> kvm unalias CoreCLR64
Removing alias CoreCLR64
PS C:\code\git\home> kvm list

Active Version     Runtime Architecture Location                    Alias
—— ——-     ——- ———— ——–                    —–
       1.0.0-beta1 CLR     amd64        C:\Users\Luis\.kre\packages
       1.0.0-beta1 CLR     x86          C:\Users\Luis\.kre\packages
  *    1.0.0-beta1 CoreCLR amd64        C:\Users\Luis\.kre\packages default
       1.0.0-beta1 CoreCLR x86          C:\Users\Luis\.kre\packages

There’s one final option which you can use with the kvm command: install.You can use this option to install a specific runtime. It works in a similar way to the upgrade/use options, so I won’t be giving any examples of its usage here.

Before ending, I’d just like to mention the existence of the –g and –f flags, which can be used with the upgrade, install and use options. The –g flag can be used to persist changes globally across the machine (instead of just saving them on the current user profile).As for the –f flag, you can use it to force the execution of the current request. For instance, if you want to force the download of a previously downloaded runtime, you can use the following command: kvm update –f.

And that’s it for now. Stay tuned for more on the ASP.NET vNext.

Book review: Propose, prepare, present: hot to become a successful, effective and popular speaker at industry conferences

•June 18, 2013 • Leave a Comment

[Disclaimer: I’ve received a copy of this book for reviewing]

In this (really!) short book, Alistair Croll presents you several tips on how to improve your chances of becoming a good professional speaker. Alistair starts by introducing the conference industry world. Having an idea about how it works is important for understanding the risks and obstacles you might face. After this introduction, you’ll see how you can adapt an idea to a specific type of event. As you’ll find out (if you read the book), having a good idea is not enough for making into the conference as a presenter. You’ll probably need to have one or two good topics, write a good CFP about it and, if you get picked, you’ll probably need to adapt it to the available sessions/slots.

Chapter 3 is a great one because it will present several tips that will help you get chosen from the available candidates. It also presents several things which will probably hurt you during the process, so you should really pay attention to this chapter. The last two chapters give you some tips on how to improve your presentations and on how you can improve your chances of making money at these conferences.

Typically, this is not the sort of book I read. However, I was looking for something to give me some tips on this subject (conferences) and this book was really what I needed to get an overall look on the topic. Overall, I’m giving it a 7/10.

Book review: UX for Lean Startups

•June 7, 2013 • Leave a Comment

[Disclaimer: I’ve received a copy of this book for reviewing.]

Nowadays, there are no doubts about the role UX plays in getting a great product. Unfortunately, UX is generally associated with costly processes which involve lots of design. In this book, Laura Klein does an excellent job in showing you how to apply several techniques in  order to reduce the time and money which is typically spent in this area.

Even though the book has UX in its title, the truth is that book concentrates on showing you several techniques that will help you continuously test the user experience. No, I’m not talking about color use or stuff like that. I’m talking about techniques which will help you validate if the problem you’re trying to solve deserves to be solved (ie, should you be wasting your time and money building this product) or that will improve the way you run your qualitative and quantitative research and testing. In other words, Laura introduces several approaches which will help you apply lean principles to UX design.

Looking at its title (UX for Lean Startups) might mislead you into thinking that this book is for someone who wants to create a startup. In my opinion, it’s not. In fact, I’d say that given the importance that UX plays in software, the book’s title should be something like UX for Lean Developers. But hey, that’s just me Smile

Overall, I’m giving it a 8/10.

My ASP.NET 4.5 is out

•April 4, 2013 • Leave a Comment

I’ve been so busy that I’ve forgot to mention that my ASP.NET 4.5 book (written in Portuguese) is out.

Book review: CLR via C#

•February 25, 2013 • Leave a Comment

[Disclaimer: I’ve received a copy of this book for reviewing]

Yesterday I’ve finally finished reading Jeffrey Richter’s last book CLR via C#, 4th edition. I’ve been getting a copy of this book (buying or being lucky enough to get a review copy) since it was called Applied Microsoft .NET Framework Programming. Each new edition ends up adding new cool stuff and this last edition didn’t disappoint. Besides Garbage Collector chapter rewrite, this latest edition introduces the new Reflection API (introduced by .NET 4.5)  and presents several new concepts associated with the new WinRT framework. If you’re a die hard C# programmer, you should be pleased to know that the book has been updated to illustrate the new C# 5.0 async features introduced by the latest .NET framework release.

So, this is really a book I love and fortunately for us developers, Jeffrey has been doing an excellent job of maintaining and updating it during these last years. In my opinion, this is still the .NET reference book every developer should buy and read. My score: 10/10.

 
Follow

Get every new post delivered to your Inbox.

Join 573 other followers