Sunday, March 27, 2005

"Feature Creeps" in BMCS

This "Good Friday" weekend had been a "Good Hacking" weekend for me. I made good progress on the conversions between the primitive types.

As I was hacking, the following question constantly surfaced at the back of my head - "How will I be managing the features sneakily creeping in from gmcs world to the bmcs world?". There are two components to answering this question - Identifying that a feature is creeping in and tactfully "handling" the same.

To cite an example, "unsigned numeric types" are "feature creeps" from the C# world. The following pattern keeps recurring in the gmcs conversion routines.

static public Expression ImplicitNumericConversion (EmitContext ec, Expression expr,
                               Type target_type, Location loc)
{
    Type expr_type = expr.Type;
    if (expr_type == TypeManager.ushort_type){
        //
        // From ushort to int, uint, long, ulong, float, double
        //
        if (target_type == TypeManager.int32_type)
            return new OpcodeCast (expr, target_type, OpCodes.Conv_I4);
   }
}

The ushort_type above is cached in the TypeManager as follows:

public class Typemanager
{
    // cached unsigned short type
    static public Type ushort_type = typeof (System.UInt16);
}

One naive way of handling this is to remove all references to the unsigned types. I tried doing this snip, snip, snip ... and it's no fun but a plain drudgery.

Then I sat back and said to myself, sure enough, I can do better than this and ended up doing this -

namespace Mono.CSharp {
    public class NotDefinedAsPrimitiveType {
    }
}

public class TypeManager
{
    public static Type ushort_type = typeof (NotDefinedAsPrimitiveType);
}

Barely three lines of change and most of the feature creep is gone !

Btw, I should admit that it took more time writing these few lines of code than doing all those snips ...

Coming back to the question that I raised previously, the obvious answer is that I should start educating myself about the language semantics in the C# world. This will help me make educated and intelligent choices for handling of feature creeps.

2 Comments:

At 7:46 am, Blogger Goji Juice said...

Hello everyone! ... sorry I'm a newbie, how does this blog thing work? I bought some products from this store: www.eBookLovers.com but too dumb to figure out. Any help would be greatly appreciated!

 
At 8:24 am, Anonymous Anonymous said...

Many times something can seem wonderful on the surface but when you get down to the meat of the issue it is not so great. This happens more often then not when people fail to read the fine print about online casino bonuses. While there are a good many online casino bonuses out there, which ones are actually worth the time and hassle to take part in? Lets take a look at some of them.
[url=http://www.casinolesoleil.com]online casino[/url] http://www.casinolesoleil.com casino Internet casinos offer the same games you can find at land casinos, including but not limited to; baccarat, blackjack, craps, roulette, slot machines, and video poker. Some only focus on one or two games, and some offer other games. Whichever you want to play, search around to find the best for your needs.
[url=http://www.redlotuscasino.com]online casino[/url] http://www.redlotuscasino.com casino Of course, when you play in a casino, you have a basic understanding that the house almost always wins. This also applies in online casinos. So make sure that you go slowly on transferring money, since online casino, just like traditional casinos, can become quite addictive. [url=http://www.triumphcasino.com]casino[/url] http://www.triumphcasino.com casino http://www.affrewards.com [url=http://www.affrewards.com]casino affiliate program[/url] As with all gambling bingo is totally addictive and you should be careful of its grip on you! [url=http://www.bingokisses.com]bingo[/url] [url=http://www.bingoeuphoria.com]bingo[/url] bingo bingo http://www.bingokisses.com http://www.bingoeuphoria.com Bingo is usually played in special halls where many players can play at the same time. The actual fun is the tension building up seeing other players closer and closer to the finish line. However, with the advent of the Internet, BINGO has gone online as well. There are many ways to play on the net, though the basics remain the same. You will have to complete a given pattern before anyone else in order to win. Over the net, you need not shout the computer will flash it out for you. Some online games also have chat attached to the games where you can speak with other players online and have fun right from your home, office or any other place where you can get on the net. Chatting is a great way to meet new people and pick up the tips and tricks.
http://www.casinolesoleil.com http://www.redlotuscasino.com http://www.triumphcasino.com http://www.bingokisses.com http://www.bingoeuphoria.com http://www.pulsebet.com http://www.affrewards.com http://www.thehighrollerclub.com
http://www.buyphentermine1.com [url=http://www.buyphentermine1.com]phentermine[/url] http://www.norxbuy.com buy phentermine

 

Post a Comment

<< Home