Thursday, August 13, 2009

Doing One Thing at a Time

A while ago, I started applying the Pomodoro technique in my work days, which essentially says that you must pick some tasks to do, and start doing them one by one. It talks about time-boxing, giving yourself breaks in between, handling interrupts, etc. But the main point is: do only one thing at a time, and handle all distraction in a way that they don't disrupt your focus.

It was a pretty successful experience. It increased my focus. It also helped me become more proactive, that is, doing what I think is effective to do, in the midst of all the things that world throws at me.

Now, on an entirely different planet, I was reading Michael Feathers’ book, Working Effectively with Legacy Code. In chapter 23, he says:

“I have this little mantra that I repeat to myself when I'm working: "Programming is the art of doing one thing at a time."”

This quote is from a chapter named “How do I know that I’m not breaking anything?”. So, doing this will increase the quality of the code you’re writing and decrease the possibility breaking something.

And it perfectly resonates with me. Every time I try to make many simultaneous changes to the code, it makes me more nervous, and I fall into the “code-and-pray” mode.

Even when I’m just trying to accomplish one single goal, I break it into smaller steps like "introduce a new constructor argument of type IFoo", "Write a new implementer of IFoo that does this and that", "Pass that new implementer as the constructor argument to the first class and make sure they work fine together" (ok, you get the idea),  do them separately, and make sure that the tests pass after each one of them.

From now on, I will repeat this mantra to myself and advertise it to others too: “Programming is the art of doing one thing at a time.” When you stumble upon some ugliness or some unrelated thing that you want to change in code, just note it down to do later, and continue with the task in hand. It also helps you to check-in your code more frequently, which is always a good thing.

Wednesday, August 12, 2009

Testing Syntax Highlighter

Just to check if the new syntax highlighter works:

r.InstanceOf<IDataProvider<File>>()
    .Is.OfConcreteType<NHibernateDataProvider<File>>()
    .CtorDependency<ICriteriaCreator<File>>().Is<FileDataEntryService>()
    .WithName("FileDataEntryDataProvider");

 

I’m using Alex Gorbatchev’s SyntaxHighlighter.

Friday, June 06, 2008

Quick Notes About My Experience with LiveMesh

LiveMesh logoThese are the things that caught my attention using LiveMesh for one hour:

  • Download took long (the download speed was slow (around 10KB). I don't know if this was their fault or my ISP, or … ).
  • I like the "Devices" interface! Its simple and nicely done, and gives me the feeling that I'm going to create a mesh! ;)
  • Signing up and adding a device was easy and straightforward. Just click the "Add Device" button and it starts downloading the software to the current device you're browsing from.
  • For now, you can just add a PC as a device (They say that Mac and Windows Mobile phone support is on the way). It has a 64-bit version of the software, which made me feel supported and warmed my heart ;)
  • "Product does not support running under an elevated administrator account or with UAC disabled." So I had to enable UAC and restart the system, just for the installer to start installing.
    • There is a good explanation about this strange requirement on the LiveMesh teams's blog. But I'm not sure why they *must* have used per-user COM objects. I'm not an expert on the subject, but whatever the reasoning behind that is, not sure if it is worth forcing end users enable UAC for the setup. Bear in mind that it is just the first tech preview.
  • The remote desktop functionality is great. Now we have a free application that provides us with complete remote desktop functionality, which is a huge step forward from FolderShare.
  • Speaking of FolderShare, I really miss the remote browsing (not remote desktop) feature of it. It was fast (given my Internet connection, full remote desktop over Internet is very sluggish!), and allows me to get files from my PC over the Internet. If you haven't tried it yet, forget about LiveMesh and go give it a try.

FolderShare remote access

  • Remote desktop feature is implemented using ActiveX, so it is IE only.
  • It detected that I'm trying to connect remotely to the same computer that I'm working on now and showed me a meaningful message! It was just fun to try :D
  • A synced folder has a distinguishable blue icon in windows explorer. Nice!
  • When you open a synced folder, a LiveMesh sidebar appears on its right that shows you recent "news", and devices and people that have access to this folder.

LiveMesh Sidebar

  • The "news" interface is clean and readable. I always had problem with FolderShare's activity window.
  • Members can only be Owner of a given folder in the current version. So you cannot give read-only access to someone. Then again, it is just the first tech preview of the software.
  • I'm not a fan of mimicking desktop interfaces in a web application; but in this case the Vista-ish windows in the browser were a real treat and enable the user to have a consistent experience whether he is using the web interface or browsing his local hard drive using Windows Explorer. Just look at the following screenshot, taken from the web interface, and compare it to the one above.

LiveMesh Live Desktop

  • The coolest feature of the service in the current release, is the Live Desktop. It appears as a device in your devices page and gives you about 5GB of storage space in the cloud. You can sync a folder in the Live Desktop, with a folder on your PC's hard drive and you can always access its content over the Internet no matter your home PC is on or off. And when you want to get it, you are not limited by your PC's Internet connection's speed (again, it is important for me here), you are accessing it from your Microsoft-provided online storage.

If you have a broadband connection, you owe it to yourself to try LiveMesh or FolderShare. As Soctt Hanselman says about FolderShare, "Truly change the way you use your machine. Save a file in a folder and it will always been on your other three machines when you need it. Also access files, if you like, from remote locations. And it's free."

Technorati Tags:

Sunday, May 18, 2008

The Bad Guy Has More Publicity

Warning: Not a technical post.

The other day, I was watching American Gangster. When the movie finished, knowing that the story was based on real-life events, I wanted to know more about the real persons portrayed in the film and possibly see a photo of them.

Naturally I turned into wikipedia and found the pages I was looking for: here is the police and here is the drug dealer.

If you follow the links, you'll find out that there is a photo and some good information about the bad guy; but no photo and just 6 lines of text about the good guy.

It kinda made me upset.

Wednesday, May 14, 2008

Why C# Compiler Is so Picky About Type Parameter Constraints' Positions?

Last time I wrote about how smart C# compiler is, this time I want to point at a seemingly unintelligent compile error:

The 'class' or 'struct' constraint must come before any other constraints.

or:

The new() constraint must be the last constraint specified.

For example, if you write the following code the compiler complains that you must swap the constraints' position:

class Foo<T>
where T : IDisposable, class
{
}

So how is that the glamorous C# compiler that reads my mind, demands me to change the ordering of those constraints or else!

The error message sounds like a "semantic error" and that's what kept me wondering why the compiler is so picky. I went ahead and looked up the C# language specification and found out that this is in fact a syntactic error, coming from "syntax analyzer" of the compiler, if we speak in Dragon terms.

Side note: You can find the specification in your own computer, at "%ProgramFiles%\Microsoft Visual Studio 9.0\VC#\Specifications\1033". Change the VS version, if you have an earlier version installed.

This is the syntax, pasted from the specification:

type-parameter-constraints:
    primary-constraint
    secondary-constraints
    constructor-constraint
    primary-constraint , secondary-constraints
    primary-constraint , constructor-constraint
    secondary-constraints , constructor-constraint
    primary-constraint , secondary-constraints , constructor-constraint


primary-constraint:
    class-type

  class
  struct

secondary-constraints:
    interface-type
    type-parameter
    secondary-constraints , interface-type
    secondary-constraints , type-parameter

constructor-constraint:

  new ( )

This way, the C# syntax is limited in a way that you can specify one of the three primary-constraints, any number of secondary-constraints, and a constructor (new()) constraint. There can be one or more of these three constraint types specified, but they must appear in that particular order; that's part of the syntax.

So when you write something like the Foo class that I've shown you before, the syntax analyzer sees a secondary-constraint and then a comma, now it expects another secondary-constraint or the constructor-constraint; but it encounters neither of them, so it reports an error: "Expected: interface, type-parameter, or new()." At least that's what an old-school compiler should have thrown more or less; but apparently the C# designers at Microsoft replaced the message with a more human readable error: "The 'class' or 'struct' constraint must come before any other constraints." (And I think they've done the right thing; that's way more expressive.)

Side note: If you write anything other than class or struct in there, it gives you a syntactic error: "Type expected."

When designing a language, it is a good thing that you capture as much information as you can in the syntax; and leave less for the semantic analyzer to check; it makes the specification more expressive (it's specially important when you want to submit it for standardization), and the implementation simpler. But IMHO, in this case they could have relaxed the syntax a little bit, and added some semantic rules (there already exist a lot of semantic rules in the specification of this feature, like "there must be no cycles in the dependency graph of type parameters", or "A type must not be specified more than once in a given where clause"). These new semantic rules would be something like these:

  • There must not be more that one new() constraint specified.
  • One and only one of the following constraints must be present: class, struct, class-type.

Post script: I know, it is just a tiny little thing; but I can't stop thinking about it whenever a build fails because of it (it happens a lot when people are newly introduced to this feature).

Update: Corrected a typo. Thanks Mohammad.