TechEd 2008

O TechEd está chegando aí (14 a 16/10) e contará com a presença de ninguém mais ninguém menos que Steve (Developers! Developers! Developers!) Balmer.

Os preparativos já estão a toda. Este ano estarei ministrando duas palestras:

  1. DEV301 – 300- 14/10/2008 14:00 – 15:15 – Sala 2 Melhores Práticas com a Linguagem C# 3.0
  2. WEB301 – 300 – 15/10/2008 09:15 – 10:30 – Sala 7 Internet Explorer 8 Para Desenvolvedores (junto com Miguel Ferreira)

Na palestra “Melhores Práticas com a Linguagem C# 3.0”, eu vou demonstrar os recursos que a linguagem ganhou na versão 3.0 e a melhor forma de usá-los. Também pretendo abordar os principais erros e gotchas que tenho encontrado por aí ao desenvolver o meu código e revisar código dos outros.

Na palestra “Internet Explorer 8 Para Desenvolvedores” eu e o Miguel Ferreira (PM do Windows) vamos mostrar o que o IE8 está trazendo de novidade para os desenvolvedores.

Além disto, estarei respondendo a perguntas no Ask The Experts. Para quem nunca participou de uma sessão destas, é uma chance de ter as suas dúvidas respondidas ali ao vivo e a cores. Imagina como um Fórum MSDN tête-à-tête. Imperdível!

Object creation with generics

Last week I was reviewing some code when I came across something that looked like.

class TypeTranslator<TOrigin, TDestination> {
    public TDestination Convert(TOrigin value) {
        Type typeOfTo = typeof(TDestination);
        TDestination to = (TDestination)typeOfTo.InvokeMember(null, BindingFlags.CreateInstance, null, null, null, CultureInfo.CurrentCulture);

        // goes on and copies the contents of each property from the TFrom object instance to the TTo object instance
        return to;
    }
}

 

The idea is to translate entity types to data transfer types. The class receives the origin and destination types upon instantiation and when Convert is called it creates a new instance of the destination type and populates its properties from the origin type enumerating through all its properties via reflection.

We all know that reflection is slow when compared to accessing the types and members directly, but the real problem on this code lays on the fact that it tries to instantiate a new object using a parameterless constructor, but there is no guarantee that the class has one.

It has all been working based on the convention assumed on the project that these types will all have a public parameterless constructor. What happens if a new developer comes in and unaware of the convention decides to create a constructor with parameters? The compiler seeing that there’s a constructor will not create the default parameterless constructor anymore. Since there’s nothing else checking it, it will only fail at runtime.

A runtime exception would be caught relatively early if they were using unit testing, but they aren’t using it, so it depends on trusting the developer to do the proper tests.

Well, I’m a developer, but I trust more on the compiler doing that job than on myself or whoever for that matter, so I proposed some changes:

class TypeTranslator<TOrigin, TDestination> where TDestination : new() {
    public TDestination Convert2(TOrigin value) {
        TDestination to = new TDestination();
        // goes on and copies the contents of each property from the TFrom object instance to the TTo object instance
        return to;
    }
}

This way, the compiler will guarantee that the type used has a parameterless constructor. Finding issues at compile time is much cheaper than at runtime.

Parlophone @ YouTube

A Parlophone, gravadora de bandas como Radiohead, Cold Play, Blur, The Verve, entre outros firmou parceria com o You Tube.

Já foram disponibilizados mais de 180 vídeo-clipes. Vários deles (se não todos, não fui atrás pra conferir) estão disponíveis em alta-resolução

Simplesmente imperdível!

http://www.youtube.com/parlophone

 

Growing software keeping things simple

Back in year 2000 I was running my own software development company and had a small kind of ERP system targeted at small companies.

Reading about all the advantages of interfaces such as the ability to switch implementations one for another at any time, I thought: "Wow! That’s amazing! I gotta do that!". So I went extracting the interfaces out of each class and making the classes refer to the interface. Soon I realized that in order to be really independent, I had also to change the methods and properties to point to the interfaces so I could change the object being passed to them.

Several weeks later I had it all done and working, but those were several weeks not adding new features. Only refactoring code at a time where we had no refactoring tools like today.

One could argue that I should have done interfaces from start and then I wouldn’t have had all that work. OK, I agree. The problem is that all that was new for me. Still, all the work would be compensated by the possibility of switching implementations whenever I needed!!!

The problem is that time never came! OK… To be fair, there were a couple of situations where I benefited from using interfaces. And that only became possible because I got a new insight, a new way of seeing the world – through interfaces. But for the most part, it was an overkill. When modifying a class, instead of having one place to change, now I had two!

It has been attributed to Albert Einstein that “Everything should be made as simple as possible, but no simpler

After so many years of developing software I came to appreciate simple designs.

I think about the ways the code might evolve in the future and instead of putting in things that pave the way to this predicted future, I tend to leave out the things that would otherwise make it more difficult to get there.

The reason for this is that the predicted future may never come to realization. So by putting in stuff now, I would eventually be throwing resources away. Resources that may be needed for something else.

It gets even worse when – driven by real needs – you find yourself having to accommodate changes that go in another direction that eventually are incompatible with what was initially predicted.

All of this has already been explained by people much better with words than I am. Take a look at YAGNI, KISS and DRY.

The bottom line is: Grow you software simple. Only add complexity when really needed. Even then, try to keep it as simple as possible, but no simpler. 🙂

Download gratuito de música – Legalizado e com remuneração do artista

Na semana passada eu descobri o Álbum Virtual da Trama.

Eles estão com uma idéia bem legal que é a de todo mês eles definem um orçamento e rateam a grana para os artistas que estão no site baseado no número de downloads.

Na semana passada haviam 3 bandas/artistas:

Cansei de Ser Sexy – Bem legalzinho

Tom Zé – Pura viagem. Provavelmente não escutarei novamente

Macaco Bong – Ainda não escutei.

Os álbuns ficam disponíveis por tempo limitado, então é bom estar checando o site de tempos em tempos para ver o que aparece de novo por lá.

Tem um videozinho lá no YouTube falando do projeto:

Studying for MCSA/MSCE

I’m a strong believer that the only way to build really good software is knowing your platform.

That’s why since from my early days of software development, I’ve made myself read at least a part of every recommended book about any topic I was interested in.

The the Internet came along and suddenly I was stroke by a tsunami of good and bad information sources.

Searching the Internet after information can be time consuming even with the aid of search engines. There’s so much information that it’s hard to know the best place to start and keep a track on your progress.

For that matter, I prefer learning through books. Since I started learning .NET, I bought more than 30 books and read at least a part of each of them. Books give you a path to follow and whenever it doesn’t give as much as detail as you’d like, you can always resort back to the Internet to gain deeper knowledge on a specific topic this time knowing what to look for.

Recently I noticed a trend in my learning patterns. Whatever problem I had that was development related, I could find something helpful in a couple of minutes because most of the time I knew what to look for.

The same has not been happening with infrastructure related stuff, though. Since I’ve been working a lot with distributed systems such as web services and web site infra-structure software, I’ve been spending more time than I would like to troubleshoot things like network connectivity and authentication issues.

For that reason, I decided sometime ago that I would start studying for the MCSA/MCSE certifications. I’m not sure I’ll pursue the whole path, but at least I’ll try to learn as much as I can about Active Directory, Network topologies, authentication and other stuff that I believe will help me do a better job developing distributed systems.

Late last month I bought MCSE Self-Paced Training Kit (Exams 70-290, 70-291, 70-293, 70-294): Microsoft® Windows Server(TM) 2003 Core Requirements, Second Edition. It hasn’t arrived yet, but after I bought it I gained access to MS Press books on Books 24 x 7 from the MVP program. The books I paid almost 150 bucks for are all there! Well at least the printed books are much more portable and I can read them while commuting to and from work.

There’s a lot of interesting books on 24 x 7. In the coming months I’ll eventually post my findings.

Good reading!

Acessando Excel Services a partir do SharePoint

Hoje eu tava revisando o código de uma Web Part usada no SharePoint que fazia alguns cálculos usando Excel Services.
Para quem ainda não sabe, o Excel Services expõe a funcionalidade de cálculo do Excel como um Web Service.
 
O projeto tinha uma Web Reference (um proxy) apontando para o Web Service do Excel.
 
O grande lance é que quando você está acessando o Excel Services a partir do SharePoint, não é preciso fazê-lo através do proxy. É possível e recomendável referenciar diretamente o assembly Microsoft.Office.Excel.Server.WebServices.dll.
Alguns dos métodos das classes do assembly têm assinatura direrente do proxy. Nos métodos com os quais tive contato, a diferença consistia do método local ter um parâmetro a mais: out Status[].
 
Como principal benefício, eu destaco o deployment mais simples, já que não é preciso lidar com a configuração do Web Service
 
Maiores informações: