Monthly Archives: February 2006

Standards not maintained in implementations of standards

I just read something on Scoble’s blog which has drawn my attention. It was a response to Joel Spolsky complaining about online calendars missing obvious (for some?) functionality.
How come all these (new?) applications are missing so much of the things, that should be an obvious thing? I have seen that many times. Someone makes a new implementation of some known piece of software – be it a calendar, a word processor or a simple text box control and while it sometimes promises to be innovative in some way – it doesn’t do some basic things other implementations do. There are probably many reasons why we see that:
it might be just a simple implementation, that is not meant to do everything the other things do,
or maybe it is planned to be expanded to include that functionality in the future,
or maybe the developers behind it were not aware that behavior is a standard,
or maybe it is not a standard after all, though you use it every day?
 
What can I as a developer do something about it? I could probably write a word processor myself, but how long would it make me to catch up with MS Word? Maybe I could work on some open source implementation, but they seem to be so messed up, that I might end up rewriting it anyways. Maybe I could get Microsoft to hire me to let me work on the product? Seems like a good idea. For now though – I might try to contribute to common knowledge of standard applications and write about them. List what they should do. Maybe no one will listen, but maybe someone will notice my effort or even make some use of it?
 
If I do not want to fail – maybe I should start with something simple? Probably some research would be useful. Microsoft sure has to have some guidelines for user interfaces! And so here it is – User Interface Design and Development. There even is a book they offer. Maybe I will get it some day.
 
As for today – I want to start with something that looks most simple, but has so much within… a text box control! Let’s see if I can add more details to that Wikipedia entry

MS and UIs of 2006.

I am quite excited. There are at least two interesting products that can add something fresh to the GUIs this year. Windows Vista and Office 12. Vista promises to revolutionize the way we will develop UIs, with all new APIs and graphic accelerators support. New Office will bring some completely fresh concepts in controling an application. Many people are looking forward to it, although many are scepticals. Myself – I trust the Microsoft’s research effort.
Vista is supposed to bring fewer changes than it seemed at first and some are unhappy about it. I think the black Glass UI is nice and does not distract user’s attention from the work space, although probably the default theme will be more vivid, or will be easily customizable to satisfy the tastes of the color hungry. The fonts themselves will probably make it a real beautie and some will probably clutter their sidebar with plenty of gadgets. Myself – I will rather stick to my two dozens of shortcuts in the quicklaunch area.
Office 12 will bring the “ribbon”. I think it might become a new standard of interaction styles bringing synergy of toolbars and menus. And even more direct manipulation with the “floatie”. The world seems to start taking full advantage of all GUI concepts at last. It is becoming harder to come up with new and original functionality, so usability and user experience are the things that make a difference.
The recent most important UI breakthroughs for me? Skype with its well designed context menus, Google Earth – the first in its kind and finally AJAX, which will make the web look more like GUI. It is a completely new thing, which shouldn’t be treated as a classical web interface (hence the Web 2.0 term) and rather tries to immitate GUIs. Personally – I would rather make some use of the shdocvw.dll and build these things using a client side program rather than a web browser, which works faster and enables better and more flexible interaction. Obviously some people find it harder to design, although with .NET Windows Forms it is actually easier. Although you limit yourself to a few latest versions of Windows – you don’t have to rely on the browsers compatibility. Maybe with Vista shipped – we will see more interesting attempts here.
 
Maybe my interests in these areas will finally find some use? We’ll see.
 
I think it is time to make another UI.
 

Meta coding? Macros and regular expressions.

I have just read a short article on CodeProject about using regular expressions in coding (

http://www.codeproject.com/article.asp?tag=38295622841838755) and decided to comment on that.

In situations as in that article and especially when converting a table or list of values into a sequence of assignments, calls, declarations etc – I prefer to use macros. It is easier to record and play a macro that does something, than write a regular expression for the same thing. Sometimes only one of the two options is possible so I value them both highly, as they enable to really streamline code generation. Aside from that – it is not something they teach at those programming courses at the university (at least they did not on mine) – so it looks so pro… :]

In this example, using VS2005 I would record the macro as following…

Piece of initial text
workstation id=LEBOWSKI;packet size=4096;user id=sa;data source=LEBOWSKI;persist security info=True;initial catalog=TheInternet;password=protected

The sequence of actions to record the macro:
0. Put the cursor at the beginning of the text
1. Ctrl+Shift+R (starts recording)
2. Type: options.Add(“
3. Open a find window (Ctrl+F) and look for character ‘=’
4. Type: “, “
5. Press: Ctrl+Right Arrow (jumps to the end of the word)
6. Type: “);
7. Press Enter for new line
8. Press Delete to remove the semicolon
9. Ctrl+Shift+R to end recording

Now while holding Ctrl+Shift press P a couple of times and you’ve got your output text with sequence of function calls.
You can even see the actual VB code (Alt+F11) for the macro and edit it if you want to get something more custom, but that probably does not happen very often – at least I have not used that yet.
The key settings for macros might be different in your environment, so you might need to check them or set them up.

Using a similar technique I often generate properties in C# – just starting with a list of a few dozen words – you just have to change one word into a property, remembering to start with the caret at the beginning of the first word and ending with the caret at the beginning of the second word and using clipboard to put the word in the source of the property a few times.

That is most useful when you want to read some data from a file – e.g. an XML one. You get a list of tag names in your source code, record and use one macro to generate the properties with the same names as XML element names to store the values and then another macro to retrieve values from the XML file and assign them to these properties.
You can create hundreds of lines of tedious code in a matter of seconds. Real robust.

The reason why I prefer macros when possible is that you do not have to remember all the special characters and the syntax used in search and replace strings, which is a problem if you only need them once in a while – especially, that they differ among various editors – they even differ between VS and .NET System.Text.RegularExpressions namespace.

The macro code sample below can be used to transform a list of names separated by a new line only into a sequence of properties of a C# class, nicely enclosed in #region outlining tag. Just open the macro editor and replace the code of the RecordingModule with the one below.

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics

Public Module RecordingModule

    Sub TemporaryMacro()
        DTE.ActiveDocument.Selection.EndOfLine(True)
        DTE.ActiveDocument.Selection.Copy()
        DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstColumn)
        DTE.ActiveDocument.Selection.Text = "#region "
        DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
        DTE.ActiveDocument.Selection.Indent(2)
        DTE.ActiveDocument.Selection.EndOfLine()
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "#endregion"
        DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
        DTE.ActiveDocument.Selection.Indent(2)
        DTE.ActiveDocument.Selection.LineUp()
        DTE.ActiveDocument.Selection.EndOfLine()
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "private string m_"
        DTE.ActiveDocument.Selection.Paste()
        DTE.ActiveDocument.Selection.Text = ";"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "public string "
        DTE.ActiveDocument.Selection.Paste()
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "{"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "get"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "{"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "return m_"
        DTE.ActiveDocument.Selection.Paste()
        DTE.ActiveDocument.Selection.Text = ";"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "}"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "set"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "{"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "m_"
        DTE.ActiveDocument.Selection.Paste()
        DTE.ActiveDocument.Selection.Text = " = value;"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "}"
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.Text = "}"
        DTE.ActiveDocument.Selection.LineDown()
        DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
        DTE.ActiveDocument.Selection.LineDown()
        DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText)
        DTE.ActiveDocument.Selection.NewLine()
        DTE.ActiveDocument.Selection.DeleteLeft(2)
    End Sub
End Module