Travis Pettijohn: Blog

Hello World

Check out how convoluted this Hello World is using an anonymous method in C# 2.0:

using System;
using System.Collections.Generic;
using System.Text;

namespace HelloWorld
{
    /// <summary>
    /// Declare a delegate that will do something with a string.
    /// </summary>
    public delegate void AcceptString(string s);

    public class Program
    {
        static void Main(string[] args)
        {
            //create the delegate using an anonymous method
            //in other words, this object is really a method
            AcceptString writeConsole = delegate(string s)
            {
                Console.WriteLine(s);
            };

            //call the object/method
            writeConsole("Hello World!");
        }
    }
}

Connections

On a coworkers recommendation, I downloaded and used XsdObjectGen from Microsoft's web site. I opened up the documentation and saw that one of the principal authors of the tool was Colin Cole. I worked with Colin on a project a not too long ago...shook his hand, had a beer with him even. I feel so special.

No Private Methods

Jaybaz writes about a programming concept that intrigued me: no private methods. If you ever need to encapsulate something into a private method, you should make it an object instead with a public interface. He describes it as performing Extract Class until there are only public methods left. Private fields are okay, but methods must be public.

It's intriguing.... It would be a little bit of overhead, extra work, sure, but it leads to some cool ideas. It pushes the idea of design encapsulation. It should lead to better code reuse. And better reuse means less bugs over time: you fix it in one spot and everything that uses that object is fixed, too.

Of course if you define your object boundaries poorly, refactoring might become a nightmare. But if they're defined well, refactoring might become a breeze.

I haven't made up my mind on this yet. I want to try it and see if I like it. Will I stick with it? Will the overhead and extra work be outweighed by the encapsulation and reusability prospects in that code? Will it be an end to or a cause for refactoring?

Ignorance Isn't Bliss

In my never ending quest to browse the entire Internet, I came across a message thread in a board for a really cool app. Some misinformed kid was bashing .NET. I decided to set the kid straight. To save you the trouble if clicking, I'll reproduce the conversation here.

ProfessorCRX: Can you tell me why .net has to be installed to make this work? I've got major problems with M$ .net.

In my eyes, Security > convience [sic]. Ms seems to see it the other way around. Is there ANY way possible to use this program without it? Or will there be? It looks pretty ill, but I just don't know about the.net BS. I think that needs to be rethought.

Travis: .NET is all about security. In fact, it makes security extremely convenient. Microsoft is making a huge security push internally and with all of its developers. Every attendee to the PDC last October got a copy of Writing Secure Code, 2nd edition. Managed code (.NET) makes things like buffer overflows almost impossible. The app throws an exception if you go out of bounds in an array instead of writing into memory that it's not supposed to be able to write to. How many security exploits have you seen in IIS 6, one of their first releases since the security push?

Basically, your prejudices are unfounded and result from you being ill-informed. .NET is a great platform both to develop on and from a security-minded user perspective. Looking towards the future, MS Longhorn (the next version of Windows) will be largely written in .NET. Get used to it, buddy, .NET is the future. IMO, that's a good thing. Install the .NET runtime, try out the app, and enjoy the wealth of apps that can easily be written by using .NET.

I can't speak for the author, but I wouldn't hold your breath for a native version of this app. He would have to scrap everything he's written and start over in unmanaged C++. Not gonna happen.

It's funny to me that I didn't know anything about .NET a year ago. I thought C# was just created because of the Microsoft/Sun Java lawsuit (not entirely untrue). But now I think .NET is an amazing platform. It's so easy to get quality apps out the door. And the Visual Studio IDE makes life so easy. It's possibly Microsoft's best product. Either Studio or Office...I can't decide. But I like .NET enough to stick up for it when the masses bash it.