Adam J Wolf

Syntax is my UI

Syntax Is My UI Mascot

Every team should have a mascot and Syntax is my UI has Syni. Syni is of my own design and will be making appearances in articles in the future. I hope you enjoy him.

Syni Angel Syni Apple Syni Black Syni Coder Syni Mad Syni Microsoft Syni Product Syni Ruby Syni Suprized Syni

Where Did the Syntax Is My Ui Tagline Come From?

Where did the “Syntax is my Ui” tagline come from? The name came from a presentation on CoffeeScript where the user interface of the CoffeeScript language was compared to the JavaScript language. The video was enlightening. I was struck by the realization that it’s true and took it as my mantra and tagline. No matter how slick the user interface is, what really matters is the syntax. Whether I am programming or writing documents, the words are the real user interface.

The presentation shows how some language designers understand that the user experience of a language is just as important as run-time performance. Just take a look at how Ruby and CoffeeScript have been designed for developer happiness and not the machine. After programming in Ruby and Python, now I constantly leave off the semicolon in C#. Why can’t the compiler do this for me?

Welcome to My Thoughts

My thoughts are my own and my opinions will change based upon experience, reflection and new information. I believe in the principle of strong opinions, weakly held. These pages are a collection of my experiences, opinions and knowledge gained in the pursuit of software craftsmanship. I try not to take myself too seriously and will sometimes have fun exposing my mistakes on these pages. It is my hope that you enjoy the site and come back frequently.

If you disagree with me, then you must be thinking for yourself and that’s good. These pages will not have a feedback mechanism, but if you are so inclined, I would love to discuss your point of view over a diet coke. Please contact me by heavily spam filtered email.

Syni on a Mini

For those of you that know me, you are going to be shocked when I tell you that this WordPress site is being served from a Mac. A Mac Mini no less. That’s right; this site is served from a Mac Mini running Mac OSX Snow Leopard Server. You want to know what’s even more shocking? It was the easiest server and blog I have ever set up.

The server is sitting in a colo that deals with only Minis called Macminicolo.net. Not the most original name but the service and the customer support are top notch. After ordering the server, it was up and running in a day. Setting up the Apache web server for OSX is criminally easy. Check one box and Bam! servers ready. Eat your heart out IIS.

I have tried every known .net open source blog and let me tell you, WordPress beats them all, no questions. If you are serious about blogging, WordPress is the easiest and most feature rich blogging platform. Don’t waste your time with the others, just get WordPress up and running; you will never go back. The install of the database was a check box and some configuration. The blog was a directory copy and editing one configuration file. Everything else was just admin stuff like user names and themes.

For all of you .Net Microsoft Kool-Aid drinkers out there, do me a favor and try something different like OSX, Apache, WordPress and MySql. What do you have to lose? Maybe some of that wool from over your eyes.

Single Responsibility Principle of a WCF Service

Ok, get ready, I am going to lay some knowledge on you that might one day save your WCF service. This guidance should be vetted and not taken as gospel. Think for yourself and apply this principle pragmatically.

Single Responsibility Principle (SRP) defined by wikipedia

Martin defines a responsibility as a reason to change, and concludes that a class or module should have one, and only one, reason to change. As an example, consider a module that compiles and prints a report. Such a module can be changed for two reasons. First, the content of the report can change. Second, the format of the report can change. These two things change for very different causes; one substantive, and one cosmetic. The single responsibility principle says that these two aspects of the problem are really two separate responsibilities, and should therefore be in separate classes or modules. It would be a bad design to couple two things that change for different reasons at different times. Agile Software Development, Principles, Patterns, and Practices

The single responsibility of a WCF service is to facilitate communication to the underlying business logic. A WCF service should take in messages, coordinate with delegates and return the results. That’s it, very simple, one responsibility. When applying SRP to a WCF service, we find the axis of possible change is when the service interface changes.

A pseudo WCF service
1
2
3
4
5
6
7
8
9
10
11
12
13
public Foo DoSomething(Bar a) {

    // Validate

    // Transform

    // Act

    // Transform

    // Return

}
A more concrete example
1
2
3
4
5
6
7
8
9
10
11
public Contact[] GetContacts(ContactCriteria criteria) {

    if (!criteria.isValid()) throw new InvalidCriteriaException();

    var blackbook = new AddressBook();
    var entries =  blackbook.GetEntriesByCriteria(criteria);

    var contacts = Converter.ToContacts(entries);

    return contacts;
}

This GetContacts method of the Contact service does not actually do anything except coordinate and delegate responsibilities to other objects. This service will be unaffected by changes in Contract, ContactCriteria, AddressBook, Converter and data access technique, allowing us to change them and not effect the service.

Things that do not belong in a WCF service are

  • Business Logic
  • Validation Logic
  • Data Access Logic
  • Transformation Logic
  • Logging

Adding any of the above items will greatly increase the chance of change and violate SRP.

Things that do belong in a WCF service are

  • Service coordination Logic
  • SOAP fault Logic

SRP will help you build systems that are more tolerant to change. That does not mean your service will be impervious to change just a little more nimble. We all know that 1.0 is just the first version of our system that will eventually change.

No Version Control Options

Is version control optional? Yes, if you are just fooling around and you don’t care if your hard drive takes a permanent siesta. No, for everything else.

I remember when I started out developing some years ago and we did not have version control systems (VCS). I used to make backups on to floppy disks. Do I sound old? Today, we have so many good choices for VCS like Team Foundation Server, SVN, Git and Mercurial, just to name a few. I envy the new people coming to this profession; no floppy disks required.

Now that we know we need a VCS, how should you go about picking one? Your choice is going to be dictated by what camp you belong to. If you’re in a Microsoft shop, then TFS might be a good choice due to the integration with Visual Studio. If you are in the Ruby / Rails camp, then you will probably use Git and Pythonist will choose Mercurial. These are not hard and fast rules, just an observation from this floppy shuffler.

I use TFS at work and Git for everything else including this blog post. You know that version control is for more than code, right? I prefer Git, but for some using the command line, it’s not visual enough. I also use Project Locker, a hosting service for SVN and Git repositories. Project locker gives me peace of mind knowing that my version control is under control and backed up regularly. You can also get remote Git repositories from Github.

So, what are you waiting for? Get your out of control assets into a version control system.

Freaking Out C# 2.0 Developers

Ok, what’s the deal with all the old timers bitching about people using the new features in C#? I’m not talking about C# 4.0 and the dynamic keyword. I am talking about 3.0/3.5, specifically lambdas, extension and anonymous methods. Oh, and you don’t want to get me started on all the var haters out there.

Yes, extension methods are the devil, and one day, will come and eat your babies!

Extension Method Example ####

    //Extension methods for logging
 
"This is a message to log.".LogMessage();
 
new InvalidOperationException("You did a bad thing").LogException();
  

Yes, extension methods can get sticky when upgrading your app from one version of the .Net Framework to the next. How many times in your career have you upgraded a production app to a new framework version? I have, twice! You will be able to figure out if your extension methods conflict with a framework version in 30 min, tops.

You know my friend Action and his big brother Action<T> right? How about his cousin Func? If you said no, please stop reading and follow the links for an education. Delegates are powerful but for some reason they freak-out C# 2.0 developers.

Anonymous Methods, Extensions and Lambdas, Oh My! ####

    // Boolean extension methods
var HasMoney = true;
var WillGetPaid = true;
 
HasMoney.IsTrueThen(()=> Debug.WriteLine("Spend Spend Spend."));
 
HasMoney.IsFalseThen(() => {
    Debug.WriteLine("Save your money.");
    Debug.WriteLine("Then spend your money.");
});
 
(HasMoney || WillGetPaid).IsTrueThen(() => Debug.WriteLine("Spend Spend
Spend."));
  

Combining all of these techniques can be a little overwhelming at first but chill out and read the code. Does it sound better? Is it more English like? Does it just roll of your tongue? Ok, so the ()=> is weirding you out. Well get used to the Lambda; it is here to stay. The ability to attach code blocks to event handlers and delegates is neat and all the cool kids are doing it. Come on, you know you want to try it. What’s it going to hurt, just one lambda?

Do you need to know these techniques to build software that your clients are going to love? No, you do not, but ignoring and avoiding them is like sticking your head in the sand. Part of being a craftsman is keeping your tools sharp and learning the features of your current language is part of sharpening the saw. So get back to work and learn the new and old features of C#.