domingo, noviembre 21, 2004

Invitation to avoid your daily lecture of a pseudo portal

Today I had the bad -when I say, I really mean bad- idea of reading some computer related news at a mexican portal -which name beging with "Co" and ends with "día"- just to see how the ideas are going in this country every day. All the things that, as mexicans dislike, are well represented there, and also they are well applied.

In this portal, is is easy to find persons with a bad aperture to new ideas, and the haughty ideas are there the bread of every day.

Nothing easier than go there (as mexican, it's probably you would have read sometime) and begin to read the news and find that almost everyone there don't believe in nothing, not even in the good things or bad ones; they don't think in the logical things or the other. I don't say anymore, because for a smart person, it should be enough.

I only hope that never the 'main' moderatore there contacts me or somehting like that.

And again, this is an invitation to not visit that pseudo portal anymore, and in general, all the portal where only people wanting see the bad things speak. As someone said, "there's no hope for those persons who only see the ugly things in the pretty ones".

Lets just try to make a better world.

miércoles, noviembre 03, 2004

Accessor Modifiers in CVS

The code for accessor modifiers support is -finally- in CVS. I wanted it to e included in the last release that will be taken place tomorrow (the development release, of course). However, as I said before, it is now in CVS in the mcs module.

The accessor modifiers are a new feature part of the C# 2.0 specification, and with it now is possible to add an access modifier -such PUBLIC, PRIVATE, etc- for the accessors -get/set- in the properties.

This is something important in classes where you want to keep some data hidden, and want to have your Property read-only, for example. A very common behavior for a class would be to have, then, your get accessor public, and keep your set accessor protected:


public int Count {
get {
// count is a private int field
return count;
}
protected set {
// Only protected members will be able to modify Count
count = value;
}
}


With accessor modifiers, there is improvement hiding get or set methods defined by a Property, thus avoiding the need no keep a lot of variables protected.

The rules for applying this are: your access modifier must be more restrictive than the parent, when overriding the accessor must keep the parent access modifier, and that if yor property has only a an accessor (only set or only get) you can't define an access modifier.

With the first, that implies every access modifier must be more restrictive than the parent, it is not possible to have:


public int Count {
get {
}
//
// Error: public is not more restrictive than public
//
public set {
}
}


The second is very obvious, but the third says you can't have a property just only one a accessor that has access modifier:


public int Count {
//
// Error: Property must have both set and get accessors
// for applying access modifiers
//
protected get {
}
}


And finally, a sample:

using System;

public class Test {
string message;

public Test (string message)
{
this.message = message;
}
public string Message {
get {
return message;
}
protected set {
message = value;
}
}

static void Main ()
{
Test t = new Test ("Mono");

// Good, it is possible to access get accessor
Console.WriteLine (t.Message);

// Bad, mcs will complain about the access
// t.Message = "Hey";
}
}