Tuesday, July 29, 2014

C# Async, Await

C# Async, Await





Static type inclusions VNext

Static type inclusions

The Java programming language is able to do a static type inclusion. Additionally some people familiar with .NET already know that VB is also capable of doing this. Static type inclusion means that the methods defined in a static class (also called procedures and functions) can be invoked, without specifying the name of the static class for each call. So this is like seeing the static class as a namespace. In this sense the static type inclusion is a possibility of using this "namespace".
What kind of scenarios are therefore possible? Let's first think about a class with a high usage of math functions. Usually one would be required to write something like:
Static type inclusions lets us now tell the compiler that we want to act as if the functions (in this case ExpCos, ...) would have been defined in this class, Abc. How does this look?
using System.Math;

class Abc
{
    /* ... */

    public double ComputeNumber(double x)
    {
        var ae = Exp(-alpha * x);
        var cx = Cos(x);
        var sx = Sin(x);
        var sqrt = Sqrt(ae * sx);
        var square = Pow(ae * cx, 2.0);
        return PI * square / sqrt;
    }
}
This feature is highly controversial and might lead to strange code and ambiguities. However, in the end one should decide if it is really worth using this feature from case to case. If the inclusion imports functions with names like Do,CreatePerform or Install then confusion is probably part of the game. If math functions are imported the decision is quite obvious.

Monday, July 28, 2014

Vnext C#

c# 6.0 may introduce the primary constructor concept

Primary Constructors provides syntactic shortcuts for the definition of a constructor. Primary constructor is beautiful way  to

declare the constructor It minimize the code  to declare  like the following

 

class Employee

{

    int x;

    int y;

 

    public Employee(int x, int y)

    {

        this.x = x;

        this.y = y;

    }

}

 

this is a lot of code for declaring constructor . the next version of c# may be look like the following:

 

class Employee(int x, int y)

{

    int x;

    int y;

}

 

it also possible that x and y may be generated automatically  .Therefore primary constructor could be used for simplifying

  our classes and for simplifying base constructor calls

 

 

 

//////////

 

Read-only auto Properties

 

The problem with auto-properties is that they are only useful if both, a getter and a setter are being expressed.

This means we usually see a lot of code that is similar to the following example

 

public int Salary {get; set;}

 

We do not always want to make the property public  some time we need to  private property then we can change the modifier of the set part.

This could look as follows:

 

 

Public int salary { get; private set;}

 

However, now we are back at a pretty ridiculous property from the class's perspective.

Why wrapping such a setter in a method, if one does not need the method character? Of course there are good reasons for this.

We could easily extend the method body while not having to alter any other code.

We could also change the setter to public again or create a protected setter.

All this is easily possible with the current construct.

Nevertheless for the purpose that is covered by the expression above, the expression itself seems to add too much overhead.

 

What we want is a (private) variable to set and a a (public) property to get. Of course this has always been possible:

 

class Employee

{

    int x;

    int y;

 

    public double Dist { get; } = Math.Sqrt(x * x + y * y);

}

 

This syntax seems to good if we want ot ensure that properties get initialize once  and  will never change  their value later on

this is useful concept read-only properties

 

 

 

//////////////

 

3)Monadic null checking

 

Some developer knows about that coalescing null operator(??) . This operator handle the null value. Now asp.net team may

   introduce the Monadic null checking .Sometime  our application crash due to null reference. I have worked in many mvc

application  where we can viewmodel ,touples and mvc application  used  the nested  classed . So we have to carefully to

check the null reference exception. check that example given below

 

int CallSomeMehedValue()

{

   var empdetail = SomeMethodCall();

   //first  i have to check the empdetail varaible is not null

 

    if( empdetail !=null)

  {  

     

    var b = empdetail.b;

   if( b !=null)

{

 

   var c= b.value;

    if( c !=null)

return c;

}

 

  

 return 0;

  

  }

 

}

 This example I have checked all null reference .Some developer handle null reference error  try and catch it will not only catch null references on empdetail , b, c, but also within the property calls.

Therefore any "real" null exception will also be caught, without us noticing that this is a real bug happening. It’s depend upon developer coding  how

to handle null reference.

 

Now asp.net Team may introduce dot-operator: ?.. Obviously this could create a chain, which would be broken once a null reference is detected.

In such a case we obviously require a default value. Otherwise we will return the result of the chain. Please check the example given below

 

int SomeMethodCallWithDefaultValue()

{

    var a = SomeMethodCall();

    return a?.b?.c?.Value ?? 0;

}

 

///////////

 

 

 

Apple  swift programming

 

a multi-paradigm, compiled programming language. shift designed to replace the objective c

 

 

 

 

 

 

 

 

 

http://blogsiteslist.com