viernes, diciembre 31, 2004

ReflectionOnly apis

Since I want to end this year with a good thing, I will talk about a new mini api contained in the 2.0 version of .Net, called ReflectionOnly. As its title says, this is a group of methods that load assemblies and retrieve the metainformation. The difference with the Load methods, is that the last retrieve information and also prepare the environment to execute code contained withint them (late binding is something that uses this feature).

Since there can be time when it is important to only load the metainformation -based on performance, for example-, ReflectionOnly methods help that.

Probably we will include this in Mono in the next weeks, as long as I finish the methods -currently I have a working Assembly.ReflectionOnlyLoadFrom method- and let them to be reviewed by the jit guys.

Below an example:


using System;
using System.Reflection;

public class Tester {

static void Main ()
{
Assembly ass1, ass2;

AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;

ass1 = Assembly.ReflectionOnlyLoadFrom ("AssemblyRefParent.dll");
ass2 = Assembly.ReflectionOnlyLoadFrom ("AssemblyRefChild.dll");

Type t = ass2.GetType ("Child");
if (t == null) {
Console.WriteLine ("Type Child could not be loaded");
return;
}

Console.WriteLine ("Parent of Child = {0}", t.BaseType.Name);

Console.WriteLine ("ReflectionOnly Assemblies:");
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies ()) {
Console.WriteLine ("\t{0}, ReflectionOnly = {1}", a.FullName, a.ReflectionOnly);
}

}

static void OnAssemblyLoad (object o, AssemblyLoadEventArgs args)
{
Assembly loaded = args.LoadedAssembly;

Console.WriteLine ("Assembly Loaded = {0}", loaded.FullName);
Console.WriteLine ("Is Reflection Only = {0}\n", loaded.ReflectionOnly);
}

}

Output

Assembly Loaded = AssemblyRefParent, Culture=neutral
Is Reflection Only = True

Assembly Loaded = AssemblyRefChild, Culture=neutral
Is Reflection Only = True

Parent of Child = Parent
ReflectionOnly Assemblies:
AssemblyRefDriver, Culture=neutral, ReflectionOnly = False
mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, ReflectionOnly = False
AssemblyRefChild, Culture=neutral, ReflectionOnly = True
AssemblyRefParent, Culture=neutral, ReflectionOnly = True

jueves, diciembre 30, 2004

My wishes for the next year

This has been a year with good and bad things. But for the next year, I have my purposes and things to do, and also my wishes for the three wise men (as we call him in Mexico).
My wishes are:

  • Be hired in a *certain* company.
  • A laptop (today everybody has a laptop, except me).

And because I could not get my wishes done, I add them to next purposes:

  • Work in the new GC engine for Mono
  • Move to a different city (Boston or Frankfurt would be ok ;-) )
  • Finish a novel in which I'm working on (an be a good one, I don't want to be one of the so many geeks that _try_ to be good writers)

sábado, diciembre 18, 2004

Great article about the Mexico gov

Today I found a very interesting article (in Spanish) about the mexican governmentm, and the reasons that show that we have to improve tons of things.

Unfortunately, as I have mentioned earlier, in Mexico it is more difficult to deliver this kind of information to the people, because of the government managed news, because of the paid political magazines, and because the people here in Mexico is used to believe everything shown in TV.

Currently I just can say that I see in Manuel Lopez Obrador the best choice for president in next 2006 elections, against the bad options that the two other main political groups could offer us.

The link here.

lunes, diciembre 13, 2004

Mono VM Docs

Miguel reported that now the docs for the Mono VM (Reflection, Internal calls, JIT, GC Handles, Interpreter, IO Layout,...) are avalaible to be seen in monodoc.

Note, however, that work for documenting them is needed. Currently, however, some of them are a little documented, and other can be just be seen (which is a good things, since I won't need to look the namesof the functions).

A screenshot below:

jueves, diciembre 09, 2004

Mono 1.1.3 released

Mono 1.1.3 was released yesterday. The mos important changes are:

  • New build system

  • SSAPRE (Common subexpression elimination)

  • Full support for Mono.C5 (Generics library) in gmcs

  • Bundles (mechanism to bundle in a single binary the Mono runtime)

  • Support for the /doc option in mcs

  • C# 2.0 new features (contravariance/covariance and properties accessors modifiers)



The last features added to mcs were made by me ;-)

martes, diciembre 07, 2004

Education Problems

Read at DW that Germany is currently having problems with its education system, because some students leave the school when the are still young (this also is a consequence of the education system). And it also points out that in Germany the success the students get is involved with their economical situation.

At least there they have good schools, and they are now trying to improve the educations system. In Mexico we have several problems, and the current government (that being said, the last government monopoly and the current one) is not improving the system, but just making it worse.

How? creating more techinical universities, technical high schools, which shows that the government is just interested in producing qualified workers for the big companies.

Second, the more money you have, the better work you get. If you go to a expensive (very expensive) private school/university, you get almost the same education you could gain in a public one, but with more expensive builds *and*, more important, you get the sympathy of the companies. If you studied in a public university, you have fewer probabilities to get a decent job than if you studied at a particular one. Worse, the education you get there is usually not as good (or not that bad) as the one you could get ina public universitie.

Third, I thinkg we have a matter of vision and the ideas we get. Students at public universities receive an excelent education, _but_ they are educated to serve and not to manage a company; they are going to be part of another problem that in Mexico happens: the chief is an dumb-ass and his workers are people with good level, but who don't want to improve their status.

It is well known that our current public system doesn't empaphize in teaching how to think, but how to repeat _and_ do the things your chief ordered to you.

One important person told me that our *president* Fox (the most bizarre political you could ever known) decreased the amount of money for public universities, and since he couldn't do that, he then gave that money to private ones. WHAAAAAAT?

viernes, diciembre 03, 2004

Covariance and Contravariance

Support for delegates Contravariance/Contravariance support is now in Mono SVN repository.

In C# world, delegates are constructions designed to save a function; in the C world, this is similar to function pointers. Delegates offer some advntages over C function pointers, as compile and run type checks, additional properties, and they also add clearness in code.

Currently, the delegates are defined just as the following example:

public delegate void MethodHandler (string msg);

In this case, MethodHandler will act as a pointer to methods with the signature defined by itself; this is, methods with void as return value, and string as a unique paratemer. A method such void SomeMethod (string msg) would be valid, but a one like void OtherMethod (string msg, string msg2) or int AnotherOne (string msg) wouldn't.

The problem here is that the methods passed to the delegates must have the exact signature defined by it. Here is where Contravariance and Covariance come to scene.

Covariance
Having something like:

class A {}
class B : A {}

delegate A MethodHandler () { // Do something }


It would be nice to have the chance to pass not only methods like A MyMethod (), but also B MyOtherMethod. This would be possible because Be is just only a specialization of class A, which is the return value defined by delegate MethodHandler. So, returning B instead of A could be done just because B is in fact, a A class, bust maybe with more methods, more properties, etc.

With the Mono 1.x series,a dn also with MS .Net 1.0, that wouldn't be possible. Mo more: .Net 2.0 (which is in state of beta) and current Mono development branch support it.

Contravariance
Again, having code like this:

class A {}
class B : A {}
delegate void MethodHandler (B b);

Methods in the form: void SomeMethod (A a) and also void OtherMethod (B b) could be passed. Why? it's because B instances could be casted to A, so, if a delegate is called, it will receive a B instance, which will cast to A for the void OtherMethod (B b).

Just as above, this is not possible with Mono 1.x/.Net 1.0, but it is avalaible with .Net 2.0 and Mono development branch.