Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

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!.

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.