Tuesday, July 29, 2014
Static type inclusions VNext
Static type inclusions
class Abc
{
/* ... */
public double ComputeNumber(double x)
{
var ae = Math.Exp(-alpha * x);
var cx = Math.Cos(x);
var sx = Math.Sin(x);
var sqrt = Math.Sqrt(ae * sx);
var square = Math.Pow(ae * cx, 2.0);
return Math.PI * square / sqrt;
}
}
Exp
, Cos
, ...) 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;
}
}
Do
,Create
, Perform
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