Friday, 16 March 2012

The Beauty of Console Applications

We live in an age where computers are getting faster, smaller and more powerful. We can now create beautiful user interfaces with millions of colours, with all sorts of graphics, images and swish animations. These advanced graphical user interfaces can now be found on smartphones, tablets, and all over the web. So why is it day after day I actually now prefer making this kind of application?

Getting Straight to the Code

In my job I work on an ASP.NET website, but I also do a lot of development on back-end services and applications/tools that work around the website. The website is viewed by thousands of users from all walks of life; the back-end systems are viewed by me and three other developers at most. Do I really need to create a graphical user interface for these tools?

The fact is I can create a service/tool with just a console window far faster than anything with a GUI. All I do is fire up Visual Studio, create a new Console Application project in the language of my choice and I have enough boilerplate code to start working on the actual functionality of the program instead of having to worry about what it looks like first. Working on a WebForms page, in contrast, can suck up days of my time just trying to get the logic and the interface to work together, let alone style it.

It also means I can quickly create lots of testing applications which test all the core business logic of the website without requiring a graphical front-end. I like this kind of work and I try and apply this philosophy a lot more now; having to manually click through several pages to get to the one you need and then entering enough form information to trigger your test scenario tends to get very tedious I've found.

I'm a Developer, not a Designer

If you're going to create a GUI, and a great one at that, a lot of thought needs to go into what it should look like and how it should function (the user experience). I suppose the throughput of actions could be decided by me, the developer, and I can try and add a splash of colour here and there to make it look a bit fancier than the traditional battleship grey.

But I have limits. If you want a really good looking interface, you'll need the help of a designer to do it. I know enough HTML and CSS to accomplish quite a few things like positioning and layout, but when it comes to picking colour schemes or images or adding detail to those elements I get stuck since those are design issues. If it was down to me, all backgrounds would probably be white and everything else some shade of blue (I'm not the most imaginative person when it comes to design).

I don't have this problem with a console application; the only thing it can output is text, so that's my only option.

The Learning Curve

There is also the issue of having to learn how a user interface framework works. Take the Windows Presentation Framework (WPF) for example; it is a whole different ballgame to Win32/WinForms programming that came before it. WPF has a ton of features which make it far more powerful than WinForms, but that comes at the expense of a very steep learning curve. Suddenly you have to know about XAML and additional features like dependency properties.

There was also the advent of the Model-View-ViewModel (MVVM) pattern that fitted nicely with WPF due to its advanced data binding features. I once had a go at learning both at once and really had a hard time getting my head around it. What exactly is a ViewModel? How do I bind Views to ViewModels? Where do you even start when trying to learn this pattern? And that is just the concepts you have to understand, you still have to figure out how to apply them. I've still yet to find out how to do something as simple as show a modal dialog without jumping through several unnecessary hurdles - surprisingly not a trivial thing if you're going to stick rigidly to the pattern. And I'm still not a designer, how do I make all this look as pretty as other WPF applications I've seen?

There are really only two options available to me in a console application. For output I use Console.WriteLine(); for input I use Console.ReadLine(). Consider this framework committed to memory.

Not For Everyone

There are of course a lot of cases where it simply doesn't make sense to make a command line tool. I could never imagine my mum or dad, as typical computer users who can just about manage email and web browsing, ever looking at a CLI and thinking "wow, I'd love to try that" for instance. And sometimes a wall of text as output is not the easiest thing to digest or view at-a-glance.

But there is a sense of "beauty" in the simplicity of this kind of application I think. It's not pretty to look at and not everyone wants it, but it does exactly what it needs to and nothing more. For a lot of projects I do, that suits me just fine.

Thursday, 8 March 2012

Hello World!

This is my first ever blog post, so perhaps an introduction is in order.

Who am I?

My name is Pete, a 28 year old (and growing older) guy living in Oxford, UK. I am happily married and a family man, my son being nearly a year old. Being the father of a very young child my free-time is limited now, but when I do get some time to myself I like playing computer games and watching films. And I get a lot of quality time with my wife and little boy - especially at 2am!

But my other passion in life (and my profession) is programming and software development. And that is what this blog will primarily be about.

The Infamous "Hello World" Program

Back in the day when I was starting my A Level in Computing, we were introduced to something called BASIC. This wasn't actually the first time I encountered it - I had a ZX Spectrum when I was about 9 or 10 years old and dabbled in writing my own programs, but I was just copying code from text books and was perhaps too young to fully appreciate it; the knowledge of what was happening and why never really sunk in at the time.

Anyway, A Levels were when I first looked into programming proper using BASIC, specifically QBasic since that came free with every Microsoft Windows OS disk since the dawn of time. The first program we were introduced to was the one every programmer sees at some point in their life:

PRINT "Hello World"

But it was the next one which for some reason had a profound impact on me:

INPUT "What is your name: ", Name$
PRINT "Hello "; Name$

When I wrote and ran that - despite looking incredibly simple - it suddenly sunk in: I can actually control this machine. I can tell it what to do and it will do my bidding! Maybe if I could figure some more things out, I could make it do something really cool...

That set me on my path. I was going to learn how to program, get my degree in Computer Science and find someone who would employ me to do this for a living.

Why Start a Blog Now?

I've been a professional developer for over 10 years now, yet I would never claim to be a master of my craft. I've worked in various languages (from Java to C++ and now C#), worked on vastly differing projects (financial systems, hardware, security systems and now websites) and every day there is still always something new to learn, which is what drives me forward.

The reason why I've decided to start a blog now is that I think it is time to pass on what I've learned. I've spent a lot of time discovering how things work and scouring the Internet researching new ideas, including great sites like The Code Project, and in more recent years StackOverflow, but I'd like to try explaining ideas in my own words.

You never know, someone else out there might find it useful too.