Sunday, March 22, 2015

AngularJS 1.x and ReactJS

You've got to love this post on CodeMentor.io comparing Angular 1.x with ReactJS

https://www.codementor.io/reactjs/tutorial/react-vs-angularjs

A lot to find out about ReactJS. Proponents say it is more scalable AND faster using a virtual DOM than Angular with its 2000 $watch limit, but it also re-introduces html mixing with JS! Many would consider that an anti-pattern and not conducive to UI Testing. What about MeteorJS? Is that going to be a better framework? Would Angular 2.0 become the de-facto popular framework come late 2016? Guess, we will all find out in the not too distant future.

Saturday, March 21, 2015

Deadlock Async Await

Avoid using Task.Wait or Task.Result while calling async code as this would block on calling the async code. Any code that blocks on calling async code could cause deadlocks. Example:

public static class DeadlockAsyncTaskWait
{
  private static async Task DelayAsync()
  {
    await Task.Delay(1000);
  }
  
  // This method causes a deadlock when called in a GUI or ASP.NET context.
// Will work just fine when calling from a console app!
  public static void Test()
  {
    // Start the delay.
    var delayTask = DelayAsync();
    
    // Wait for the delay to complete.
    delayTask.Wait();
  }
}

Moral of the story: Go async all the way and use async await. That's just the nature of asynchronous coding

Reference : https://msdn.microsoft.com/en-us/magazine/jj991977.aspx

Sunday, March 15, 2015

Of Nullable Type in C#

Nullable Types (they are used for value types) are very useful when dealing with database tables that has a column with NULLABLE value type. Allowing the default value to go through in the ORM or data layer could be misleading becuase NULL could default to the 0 value say for an int type property/column.

So use int? to assign the value of the NULLABLE int column type from the database when mapping to your POCO objects. Since we use a nullable type, we can use HasValue method while mapping the property to try to get to the value.

Nullable types DONT work for reference types like strings or your reference type POCO objects, because they are already NULLABLE (default value is NULL) and the compiler does not allow it. It makes sense, because there is no reason to add NULLABLE type to reference types which are already NULL by default.

So these are not allowed
Player? nullablePlayer;
string? nullableString;


while this is allowed
int? nullableInt; //The default value then is NULL and not 0.