Dec 20, 2006

Reflection.Emit; mood!

These last days i've been working in a web 2.0 service for blogs, what this service does, is to read your blog and depending of what you are writing on it guess your mood and give you a flower matching with that mood, The website (really nice design , but currently only in dutch :( [multilanguage soon :)]) is www.readmymood.com and this is the flower representing the mood of our blog!


My Flower

Dec 15, 2006

.Net Patterns

When I was studying Software Engineering I look at the website data & object factory. There you can find the Gang of Four (GoF) typical patterns translated to C#. You know, Factories, Sigletones, Facades... I found that this patterns have a heavy Java look and feel, and pretty boring, being a big hole for a formal definition of the patterns being used in the .Net world taking profit of the .Net languages improvements, as generics, delegates...

One example of pattern that fits in this hole is the Scope pattern.

Dec 6, 2006

Colors and Hex: Back to the very basics

Today I've been doing a WinForms aplication at work and I want to reuse a color scheme for a web site. Since WinForms don't allow you to use css :) I've to convert the HTML colors (#006600) to System.Drawing.Colors.

You can do that with one of the thousands Color Calculators but I was expecting the Color class having a method like FromHTML. It was't there but I found something like this.

static Color FromArgb(int argb);

So, just writing FromArgb(0x006600) it should work... No way. The problem is that in this situation the alpha channel has the value 0, so the color is transparent.

All right, let's try FromArgb(0xFF006600). Doesn't compile! it's a uint instead of a int because is bigger than int.MaxInt, the compiler it's right, but the one who made this function should make a uint overload. It's the problem of sharing framework with VB people.

So... What can I do? Because int uses Two's_complement to represent negative values, we can do that: FromArgb(-0x01000000 0x006600) because -0x01000000 will be represented just as 0xFF000000.

Using the first day computer science lecture to pick a color!.

Dec 5, 2006

Code Snippet (Python): Localize your users by IP



On very useful trick if you are developing an international site (and you have local sites) it's to redirect your users to their local site depending on the IP address they are coming from. This is an easy (and optimized) way to do it just with a few lines in Python and mySQL database.

1.- Getting the info:

First of all, we will need the data with all IP-Country information, there are a lot of pay sites offering this feature but i have used this free (reduced version) of one of them.
The data provided by this site is a CSV (comma separated value) file, which we can import into a fully optimized MySQL database ;) (the import method is easily explained in this site )

2.- Working with the Data:

Actually a good way to work/store the IP information is to use the long notation, this notation is represented as:

IP in Long format = 16777216*a + 65536*b + 256*c + d
where:

IP Address = a.b.c.d
Normally in PHP we have ip2long() / long2ip() funtions that help us with the conversion, the Python implementation of this functions , (and here is when the snippet comes):

def ip2long(ip):
splittedaddr = ip.split('.')
ipnum = 16777216*int(splittedaddr[0]) + 65536*int(splittedaddr[1]) + 256*int(splittedaddr[2]) + int(splittedaddr[3])
return ipnum

def long2ip(ipnum):
w = int ( ipnum / 16777216 ) % 256
x = int ( ipnum / 65536 ) % 256
y = int ( ipnum / 256 ) % 256
z = int ( ipnum ) % 256
ip = str(w) + "." + str(x) + "."+ str(y) + "." + str(z)
return ip



By this way and with the help of your IP-Conutry Database we will be able to give our users a personalized assistance ;)

Dec 1, 2006

Parallel linqdigestion

An speculation for the future plans for LINQ, once parallel computing became mainstream, in Don Desmak blog.

Nov 22, 2006

Linqdigestion

Today I've downloaded the May CTP of Linq . I was expecting something more new but... Anyway, there is a lot of cool examples on it. One of them, LogicProgramming, builds a small Logic Programming lenguage inside C#!!!. You can do something like:


Rules rules = new Rules();

Func1 isToy = Func.Arity1("isToy");
Func2 playsWith = Func.Arity2("playsWith");
Func2 likes = Func.Arity2("likes");

// A doll is a toy.
rules += isToy("doll");
// A train is a toy.
rules += isToy("train");
// Ann plays with a train.
rules += playsWith("ann","train");
// John likes a toy if Ann likes that toy.
rules += Y => likes("john",Y)==likes("ann",Y);
// Ann likes toys that she plays with.
rules += X => likes("ann",X)==(isToy(X) & playsWith("ann",X));

// Ask a question: What does John like?
foreach(string s in rules.Solve(N => likes("john", N))) {
Console.WriteLine(s);
}


Cool right? The code is full of lambda expressions, extensional methods... swahili.

Nov 15, 2006

Open Java and Innovation

Congratulations for the Java developers community, I'm sure this is the move everybody was expecting Sun to make. Maybe is a good idea that Microsoft makes something like that, opening the source of .Net Framework.

But, maybe not. I'm not very sure that this medicine is what Java needs to stay in the climb. In the last years Java hasn't been very innovative by itself. I've heard about a lot of improvements in the Java platform, in the libraries, etc But the language is rarely changed and, as far as I know, there's almost no changes in the JVM as well. I thing this is the reason .Net and Ruby on Rails are improving their market share.

Standardization and Innovation

My point of view is that the open your software and following standards is a double edge sword sometimes. In stuff like HTML and CSS maybe is a good idea to have a well-understood platform with fixed rules, because that allows interoperability and that means competency (like Firefox) and that means innovation (tabs [ok, tabs comes from Opera… who cares!]). But sometimes a big open source community and a strong focus on the standards has just the opposite effect.

Imagine that, Microsoft Office has the 80% of the market share, Open Office have the 10% and Apple WhateverOffice another 10%, and all together belongs to the United Happy Office Association (UHOA). Then Microsoft ( who have thousand of programmers behind every single menu in office [and now Office don't have menus!]) feels that Word really needs a new improvement, let me say, resurrect Clipper, the office helper, and make it mucho smarter. But to do so he needs to introduce some metadata in the docs, and to do so he have to go to UHOA and ask Apple and the people behind Star Office (Sun?) to do so. They two don't ; have so many developers, so they prefer to postpone this functionality for UHOA Doc Boring Specification 2010 and then there´s no resurrected Clipper (and all the whales die at the same time)… Can you imagine a world like this?

Ok, that´s not the case of Java, but is something like that. I´m not very in in the Java Community Process mechanisms, but they are not working very well because Java is evolving very slowly. Maybe they have to handle with legacy code and thousands of OS and Phones and… ; washing machines??, or maybe they are just not brave enough. They are not the owner of his destiny, so they are stuck.



What´s better for Java, thousand of different compilers and JVM implementations, or just one but free to move?.

This is the approach that Microsoft is following with .Net, and they have done with C# and .Net more work than all the improvements Sun has added to Java since they launch it (Jitting, Properties, Delegates and Events, Value Types, Attributes, Operator Overloading, Unsafe Code….). But then with legacy code in the back, they have launch .Net 2.0 with a lot of new things like Iterators and Anonymous Methods and, for sure, real Generics that need changes in the ‘Virtual Machine’. And they are not stuck there. .Net 3.0 really shines! with Lambda Expressions, Objects and Collection Initializers, Extension Methods, everything with the target to make Linq possible.

To look deeper in the details, I´ve made a fun PPT about how an implementation of Linq can be done in the ‘Sun way’.

Anyway, Sun have do almost nothing in all this time, so maybe Open the Java code and let it go is not a bad thing.

Nov 13, 2006

Something great is happening.....



This evening (for my time zone) something great is going to happen ....

"What is it?"

... Ok i'll give you some clues.

One

two

I will write a new post explaining the consecuences and advantages once the anouncement will be official.

Nov 10, 2006

New blog launch!

Thank's Panch! This is my first post in Reflection.Emit()! It's going to be veeery sort couse I'm at work.

My name's Olmo, today I'm 23, and I'm a C# enthusiastic. My friend Francisco, on the other side, is more in Java, Python, Ruby and other heretic stuff.

So I think this blog will be about two good friedns sometimes, and a battleground 'othertimes'.

It's my first post in english, maybe this blog will be about 'misspellingtimes' as well :)

But that will be tomorrow, today is party time!