Once again has the "Coding Horror" blog written a very useful blog. As a computer scientists I am always expected to know how to save virtually any system from virus and stupid users. One of the top problems, I always run into is people which have allowed spy ware onto their computers, making them slow and unpredictable.
In the linked blog, there is a description of how to remove spyware. (link)
Enjoy cleaning...
Monday, 18 June 2007
Tuesday, 12 June 2007
Reflection
Reflection is the mechanism of discovering class information solely at runtime. Reflection has been introduced with the .NET framework, and its usage of metadata.
Metadata is data about data, and in .NET framework it is contained along the code, to allow, among others reflection. The Metadata consists of class names, method signatures and the like, to enable both for runtime lookup of a class (i.e reflection) but also to enable the cross language execution. When the compiler compiles code, it always create the metadata along with the compiled code, and puts it in the assembly.
Reflection means being able to get instantiate a class of a type, just by providing the name of the class at run time or invoke methods just by presenting their name.
The use of reflection is slow and should only be used when absolutely necessary (link).
Maybe more later
Metadata is data about data, and in .NET framework it is contained along the code, to allow, among others reflection. The Metadata consists of class names, method signatures and the like, to enable both for runtime lookup of a class (i.e reflection) but also to enable the cross language execution. When the compiler compiles code, it always create the metadata along with the compiled code, and puts it in the assembly.
Reflection means being able to get instantiate a class of a type, just by providing the name of the class at run time or invoke methods just by presenting their name.
The use of reflection is slow and should only be used when absolutely necessary (link).
Maybe more later
Friday, 8 June 2007
Software developer you are you owne worst nightmare
Stop writing code, its just more lines where bugs and errors can hide. The following is snippet I have copied from one of my own favorite bloggers Coding Horror, which writes about "the best code, is no code at all" where he actually references another blog written by Wil Shipley who argues that we should rein in our natural tendencies to write lots of code:
Which is some very clever words. You cant have everything, and the things you want, always comes at a cost of something else.
Now go coding and remember to use the KISS principle (Keep It Simple Stupid)
The fundamental nature of coding is that our task, as programmers, is to recognize that every decision we make is a trade-off. To be a master programmer is to understand the nature of these trade-offs, and be conscious of them in everything we write.
In coding, you have many dimensions in which you can rate code:
* Brevity of code
* Featurefulness
* Speed of execution
* Time spent coding
* Robustness
* Flexibility
Now, remember, these dimensions are all in opposition to one another. You can spend three days writing a routine which is really beautiful and fast, so you've gotten two of your dimensions up, but you've spent three days, so the "time spent coding" dimension is way down.
So, when is this worth it? How do we make these decisions? The answer turns out to be very sane, very simple, and also the one nobody, ever, listens to: Start with brevity. Increase the other dimensions as required by testing.
Which is some very clever words. You cant have everything, and the things you want, always comes at a cost of something else.
Now go coding and remember to use the KISS principle (Keep It Simple Stupid)
Thursday, 31 May 2007
Properties in C#
All good programmers have spend hours made getters and setters. So Microsoft have decided to make it a bit harder (I think now, I might change my mind later).
Heres an example of old time code
public class MyClass
{
private int x;
public int getX()
{
return x
}
}
ect.
In you application you can get x with the following code:
mc.GetX();
Now C# provides a built in mechanism called properties to do the above. In C#, properties are defined using the property declaration syntax. The general form of declaring a property is as follows.
<acces_modifier> <return_type> <property_name>
{
get { }
set { }
}
This means that I can do the top example the following way:
Where <access_modifier> can be private, public, protected or internal. The <return_type> can be any valid C# type. Note that the first part of the syntax looks quite similar to a field declaration and second part consists of a get accessor and a set accessor.
For example the above program can be modifies with a property X as follows.
class MyClass
{
private int x;
public int X // property
{
get
{ return x;}
set
{ x = value;}
}
}
The object of the class MyClass can access the property X as follows.
mc.X(10) // setter.
y = mc.X // getter.
I think its a step in a good direction, but splitting the attribute and the property is in my view, just as bad as not having them.
Heres an example of old time code
public class MyClass
{
private int x;
public int getX()
{
return x
}
}
ect.
In you application you can get x with the following code:
mc.GetX();
Now C# provides a built in mechanism called properties to do the above. In C#, properties are defined using the property declaration syntax. The general form of declaring a property is as follows.
<acces_modifier> <return_type> <property_name>
{
get { }
set { }
}
This means that I can do the top example the following way:
Where <access_modifier> can be private, public, protected or internal. The <return_type> can be any valid C# type. Note that the first part of the syntax looks quite similar to a field declaration and second part consists of a get accessor and a set accessor.
For example the above program can be modifies with a property X as follows.
class MyClass
{
private int x;
public int X // property
{
get
{ return x;}
set
{ x = value;}
}
}
The object of the class MyClass can access the property X as follows.
mc.X(10) // setter.
y = mc.X // getter.
I think its a step in a good direction, but splitting the attribute and the property is in my view, just as bad as not having them.
Wednesday, 30 May 2007
equal types in vb.net and c#
Even though c# and vb.net uses the same libraries, there is some differences in what name identify the classes, below I will make a list.
And keywords:
*)
const:
- Can't be static.
- Value is evaluated at compile time.
- Initiailized at declaration only.
ReadOnly:
- Can be either instance-level or static.
- Value is evaluated at run time.
- Can be initialized in declaration or by code in the constructor.
| vb.net | c# |
|---|---|
| Boolean | bool |
| Date | System.DateTime |
| String | string |
| int32 | int |
And keywords:
| vb.net | c# |
|---|---|
| Shared | static |
| Friend | internal |
| ReadOnly* | const* |
*)
const:
- Can't be static.
- Value is evaluated at compile time.
- Initiailized at declaration only.
ReadOnly:
- Can be either instance-level or static.
- Value is evaluated at run time.
- Can be initialized in declaration or by code in the constructor.
vb.net friend becomes c# internal
Porting a friendly structure from vb.net to c# is done by altering the "friend" keyword to "internal" in c#
Regions in .NET
As a fan of agile development, where everything should be structured into small classes, its hard to see regions as anything but a bad solution for a bad problem. But they are here, and people are using them, so no sense in not knowing what they do. Its a simple answer:
They do nothing, zip, nada. A region is simply a construct to enable Visual Studio.NET to hide pieces of code outside of the normal bounderies of methods, structures and classes.
In vb.net a region have the following for:
#Region "DataTypes"
' types of service:
#End Region
And in c#:
#region "DataTypes"
// types of service:
#endregion
So no magic here... Sorry
They do nothing, zip, nada. A region is simply a construct to enable Visual Studio.NET to hide pieces of code outside of the normal bounderies of methods, structures and classes.
In vb.net a region have the following for:
#Region "DataTypes"
' types of service:
#End Region
And in c#:
#region "DataTypes"
// types of service:
#endregion
So no magic here... Sorry
Subscribe to:
Posts (Atom)