The secret to working hard

Wednesday, 19 December 2007 09:55 by Alan Mojab

Once someone asked me what was the secret that you can work this hard?

Here it is... 

  • Tie Up My Hands by Starsailor
  • Poor Misguided Fool by Starsailor
  • Stairway to Heaven by Led Zeppelin
  • Yellow by Coldplay
  • The Scientist by Coldplay
  • Such a rush by Coldplay
  • Tijuana Lady by Gomez
  • We Haven't Turned Around by Gomez
  • When A Blind Man Cries by Deep Purple
  • Soldier Of Fortune by Deep Purple
  • Working Class Hero – Ozzy Osbourne
  • Planet Caravan - Black Sabbath
  • Black Sabbath - Black Sabbath
  • Heaven And Hell - Black Sabbath
  • One Of These Nights by Eagles
  • Satisfied Mind by Jeff Buckley
  • Time Flies - Vaya Con Dios
  • So Cruel – U2
  • Gotta Serve Somebody - Bob Dylon
  • Giving Myself Away – Faithless
  • Jack and Diane - John Cougar
  • Every Strangers Eyes – Roger Waters
  • Welcome to the machine – Pink Floyd

 That’s all to it folks, if you made it rich don’t forget me.

Resharper’s bug that removes regions

Tuesday, 18 December 2007 05:34 by Alan Mojab

One of Smarties 2008 users have recently reported that when he uses Resharper’s “Code Reformat” command with “Reorder member types” checked all regions that were created by Smarties 2008 are removed.

I ran several tests first before concluded there was an annoying bug in Resharper 3.x. Smarties 2008 uses a type called EditPoint2 to insert #region directives to the documents. This type is nicer to work with but slower to use than other available types such as TextSelection since it uses buffering technique.

Somehow Resharper cannot see #regions being inserted by EditPoint2 type but it has no problem with members. There is something even more evil about this bug. If you insert regions to code files out side of Microsoft Visual Studio environment and then run the “Code Reformat” command against those files all #regions will be removed too. Discovering this ensured me this bug has nothing to do with the technique I used for inserting #regions to the document and this is just an annoying bug in Resharper.

I have contacted the support team of JetBrains and their reply was;

"By default, ReSharper should not remove existing regions inside classes. Please open ReSharper > Options > Languages > C# > Type MemberLayout and make sure 'Use default patterns' option is enabled. Please also try upgrading to the latest ReSharper 3.1 RC which is available here: http://www.jetbrains.net/confluence/display/ReSharper/Download. Thank you!

Andrey Serebryansky
Support Engineer
JetBrains, Inc"

In all my tests 'Use default patterns' was already enabled. I don’t use Resharper so I would suggest to wait until they fix the problem or alternatively you can pester them for a quick fix update.

Selecting the right tools (Add-In)

Tuesday, 18 December 2007 05:12 by Alan Mojab

These days Add-ins are all about code refactoring. What is “code refactoring” and can they bring benefits to your work?

"A code refactoring is any change to a computer program's code which improves its readability or simplifies its structure without changing its results"

Source: Refactoring

What you need to keep in mind is that “Code Refactoring” is useless without existing codes. So that means if you are not going to bother about existing projects that are dusting some where in one of your folders then “Code Refactoring” is not for you unless you have the habit of writing bad codes that you need to refactor your codes as you go along.

In software development there are techniques that can be applied to improve code structure, readability, and maintainability. I won’t be able to cover them all in one post. In my early days in software development I discovered about the encapsulation technique, the old name for Code Refactoring.

The encapsulation technique is very easy to learn. All you have to do not to rush that code to make it to work and once it does forget all about it how actually you could have improved it. Software developers would never go back to the code they write unless there is a bug or have to change it to support the new logic.

I can think of numerous occasions where I spent only few minutes more on the routine that I was working on and in return it saved me hours of work later on.

In encapsulation technique you would divide the algorithm into sub-routines where each sub-routine can be modified at later time to handle more logics without breaking the entire logic and also you would allow the same sub-routines to be used by other layers or services in your application without repeating the same logic again.

If you are writing a method/function that has a large algorithm (routines) be assured there is something wrong with your approach in solving the problem. One of the hardest things in software development is to keep the solution simple. This is something you can master only by learning from your past mistakes.

Software development is far more than learning about the language specific syntaxes, hacking the API, and how to google the algorithm you need. The bottom line is that if you are not already familiar with some of the techniques in software development then you wouldn’t know how beneficial code refactoring is.

If you are an experienced developer less likely you would benefit from the massive refactoring features are being offered by various vendors. This is because you would code from the beginning in the same manner these code refactoring features offer.

The market currently is focusing on “Code Refactoring” techniques to help the software developers on their daily tasks. I personally feel professional developers are left behind as I don’t believe all “Code Refactoring” techniques are beneficial to them as they know how to code an already refactored code from the start.

The “Code Refactoring” can be divided into two main categories;

  1. Code Enhancements
  2. Pure Productivity  

A good example for “Code Enhancements” category would be the Visual Studio’s built-in “Extract Method” refactor command. A good example for Productivity would be the Visual Studio’s built-in “Extract Interface” refactor command.

What is the difference between the two you might ask?

To answer this question fairly it would be better to talk about the benefits a command such as “Extract Interface” brings then you can compare the two by yourself. As you already know this command can extract members from existing types and creates a new interface from them. The obvious usage of this command is when at one point you decide to derive existing types from an interface. On the other hand, the not so obvious benefit is how you can work when you have such command at your disposal. Let me elaborate more on that if you will.

When you are designing a class that you would know in advance it derives from an interface most likely you would design the interface first and then the derived type second. The chances you get everything right first time are very small therefore any changes to the members of either object templates need to be synchronised between the two.

To increase your productivity you can design your actual type first without worrying about the interface part then once you are happy with the initial testing and design then within seconds you can create the interface. In this way you have saved yourself from working with two object templates at lesser time.

Tools are made because there were demands for them. You need to look at your own needs to see what tools would fit to your requirements best with the available budget.

There isn’t a perfect tool out there unless it does one thing only. Stop looking for that perfect tool, look for the tool that would have the most benefits for you.

Know your regions better

Sunday, 2 December 2007 09:12 by Alan Mojab

I’m talking about #region directives of course. Region directives have been an underestimated feature of Microsoft Visual Studio for very long time now.

Warning! #region directives are highly addictive once you become a regular user giving it up would be very difficult. Between you and I, well and the rest of the world, I’m a regular user too. So as a regular user I would like to pass on my own experiences to you.

The ability to visualise code is an important aspect of programming because it helps a better understanding of the implementation part of the object template that one is developing. You would never draw an UML diagram to visualise the implementation part. The UML diagram would only have the pre-defined members such as the object’s attributes and/or the behavioural members but not the members that developer has to create to complete the object template. Please keep this in mind for a second. 

Something as simple as having larger white spaces in the document to create members can significantly help. The more members you create the more difficult navigation becomes.

To be able to visualise, navigate, and to expand the coding area I’ve been using regions for a long time now. Grouping members by their kinds under their designated regions helped with the visualisation part as well as navigation. Surrounding members with their own regions helped expanding the coding area as well as the navigation.

Many developers choose to outline control block of members to expand coding area and to help with the visualisation. The outlining approach has its draw backs. It is much harder to manage outlined members. Outlined members are very hard to look at in particular for users with astigmatism, like me. There is no grouping capability using outlining.

On the other hand regions gives you grouping capability and you can do further grouping by creating child regions as well as expanding the coding area. You can choose different sorting order under each region something that you can’t do this easily with outlined members. Its draw back is the labour work when managing them by hand.

I’ve been creating regions by hand despite it added the additional labour work for me. The benefit I got from it was worth doing it in this manner. Gradually I developed the basic styling that I could use for all type definitions but I couldn’t do more than that for the additional labour that I had to do.

The benefit of region directives was very obvious to me and I wanted a tool that can do that for me so I can avoid the labour work but have all the benefits I wanted, selfish huh? Not exactly because I ended up developing such tool myself, I was certain there must be many developers like me wanting the same functionality. The tool I developed is called Smarties 2008 you can read more about it on my site at MojabSofware.com. Internally Smarties 2008 is known as “King of Region”, simply because it adds so many capabilities to the region directives that always were missing in Microsoft Visual Studio IDE.

The history behind Smarties 2008

Saturday, 1 December 2007 20:51 by Alan Mojab

I was originally working on a different project for 18 months, without taking a single day off, until my computer broke down and it was sent out to be amended.  

Luckily, having a laptop around I had decided to develop a simple tool to ease up my project development. I was working 16 hours a day, on average, and I was so fed up with writing the same kind of code all the time i.e. declaring properties, implementing IDisposable, ISerializable, and organising the large number of members I was writing for each type definition.

The unwanted break from my original project made me realised that I do not want to do the same amount of typing ever again. The little tool that I meant to write turned into a fully blown project called Smarties 2008. Without being a bias, I can say if I had Smarties 2008 it would have saved me from milions of keystrokes.

I have no regrets my original project didn't go anywhere as I'm personally very happy to offer Smarties 2008 to other developers instead.