SQL Server data types

Actually I have thought to write this post mainly for me as I always forget the differences of the different (yet similar) data types in SQL Server

Here is what I need to remember:

  • numeric is the same as decimal and they are both exact decimal values
  • float and real are approximate values
  • fLoat(n) complies with ISO SQL, n is the mantissa digits
  • [float(25) – float(53)] are stored in 8 bytes while [float(1) – float(24)] are stored in 4 bytes 
  • real is the same as float(24)
  • money is an exact decimal value stored on 8 bytes
  • nchar and nvarchar are the Unicode versions (2 bytes per character) while char and varchar use only 1 byte (so they can still accept UTF-8 characters but not UTF-16 like Japanese or Chinese)

That was some short notes, for the full details you can check


StyleCop for ReSharper has been released

StyleCop for ReSharper has been released last week as a plugin for ReSharper to bring StyleCop code styling issues to ReSharper real-time syntax highlighting, quick-fixes, and Code CleanUp.

Although I personally don’t like many of StyleCop rules, but like ReSharper rules, they can be turned off individually. The plugin performance can also be customized from within the ReSharper options window.

More about StyleCop:

Microsoft StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project. It is another static analysis tool by Microsoft like FxCop, but the later analyzes the compiled object code for design issues, not the source code.

More about ReSharper:

ReSharper is a Visual Studio add-in created by JetBrains (the creator of many software productivity tools like IntelliJ®IDEA the Java IDE, TeamCity™ the build integration server, and dotTrace Profiler)

I have been using ReSharper almost since I started using Visual Studio and it has always been a complement to it. Even when Visual Studio evolved from 2003 to 2005, and finally 2008, ReSharper has still much to add.

One of the features I like most in ReSharper is its ability to detect syntax and styling error while you type, refactor code quickly, suggest variable names based on classnames, highlight redundant code, make code more readible, find references and jump to it directly if only once.

There has been some talks that Visual Studio 2010 is actually 2008 + ReSharper because of a mistake they made when they posted some snapshots of Visual Studio 2010 with ReSharper menus and screens in it.

Microsoft on the other hand had been promoting one of ReSharper competitors and announced a cooperation with DevExpress to license a free version of CodeRush Express exculsively for C# developers working on Visual Studio.

kick it on DotNetKicks.com

//Comments about comments

Although they are usually enforced by coding standards, and I strongly agree, I believe code comments should be minimized for many reasons:

  • Except for XML comments of methods and classes, most comments are not affected by automatic refactoring tools
  • Most developers forget to update comments after updating code
  • Sometimes they mix with temporarily commented code
  • Every one adds one or more additional lines to the source code
  • They might make the code ugly
  • They implicitly admit that your code cannot express your ideas
  • They cannot be validated by type checking or unit testing
  • Most of the times, there are more better alternatives than comments

Yet I believe they are highly needed in these cases

  • Writing important messages to self or others
  • Writing code review comments
  • Writing //TODO tasks for self or others
  • Writing failed trials to avoid reusing them later while refactoring
  • Writing justification for code that might not appear logical at first look

And finally here are some cases when comments can be replaced by better alternatives

if (i >= 5) // number of orders
if (numOrders >= 5) // <-- better option: use meaningful var names
if (custType == 5) // credit customer
if (custType == CustomerTypes.Credit) // <-- better option: use enums

if (custCredit >= 30) // credit over 30%
if (OverCredit()) // <-- better option: use methods (or properties)

private bool OverCredit()
    return custCredit >= 30;
if (a == b)
    if (d == c)
        // ... long lines of code ...
    } // if (d == c)
} // if (a == b)

// Most decent IDEs highlight matching braces when u select one of them
// Also long lines of codes should be avoided, use methods
// begin saving data
    // ... long lines of code ...
// end saving data

#region Saving data               // <-- better option: use regions
    // ... long lines of code ...

SaveData()          // <—- another better option: extract as method
// Modified by modeeb @ Feb 6, 2009 02:32:12 PM
// better option: use a version control system that have "blame" or "annotate" functionality

The Economic Crisis and Software


A week ago there were news about Google laying off recruiters and yesterday I read More rumors of Microsoft job cuts and it is clear that the global economic crisis is going to have its impact on Software industry.

The end goal is to continue in business and to cut costs. One way to do so is by outsourcing, which is the trend of most American and European software companies now.

On a personal level, you need to save your employer’s money but doing the right job right from the first time. I know it is easily said, but also it can be easily achieved with a little concentration and a good focus on quality.

By quality I mean quality in every aspect of the process; it is not enough that it works. Quality in code includes readability, simplicity, reducing load, traffic, and waiting time.

Sometimes developers feel relaxed that a code review or a senior developer will discover their bugs. Testers are always considered a second line of defense and hence written code is not tested thoroughly by developers. In the coming years, this would not be accepted.

One of the most inspiring words in my life as a developer was in the movie Antitrust, in which a software company owner says “… this business is binary, you are a 1 or a 0 … alive or dead … there is no second place”, you need to watch this 3 min video, or watch the full movie, it really worth it 🙂

As you heard in the video, “… there is no room for idle time or second guesses … new discoveries are made hourly …” so you need to read constantly. Always read and always keep in track with what’s new in your field.

Equally important, you should build up on others experiences. No need to go through the same learning curve. Always start where others have reached. Best practices, patterns, frameworks, libraries really are time and effort savers, leaving you enough time to add something new … to innovate.

Good luck.

Scrum for Team System

It is unlikely to find an agile software project not using JIRA, Subversion, CruiseControl, or some other agile productivity suites. One of the most commonly used suites in Microsoft Environment is Team Foundation Server which combines Source Control, Task Planning, Testing, Bug and Issue Tracking, a Build Server, and a Dashboard interface to share documents and ideas in a wiki-like manner.

TFS has an out-of-the-box process template for agile projects, but this template is not fully compliant with Scrum. Since TFS is open for any custom process template, some vendors have provided free templates for Scrum.

The first effort in this area was Scrum for Team System by Conchango. Then a group of VSTS MVPs created a light-weight process template that is easier to install and configure which makes it more appropriate for small projects with small teams.The latest one is eScrum which is provided by Microsoft but as an additional download.

It was also convenient to view the sprint tasks in the form of task board with drag-n-drop capabilities to move tasks between panes. Conchango also had provided Task Board for Team System but it is commercial with one month free trial.

I personally prefer using the TFS integration with MS Office to add tasks in Excel with a running sum of used capacity and then post the tasks to TFS at once. There are many other uses for showing tasks in Excel like conditional formatting of cells to indicate different states, severity, priority and so on.

Delphi is back!

I have started my first years of Windows Development using Delphi (which I call Visual Object Pascal) and I used it for quite few years and within 3 companies before I move to C#.

“Delfee” as pronounced in Greek or “Delf-eye” as pronounced in English was the place of the Oracle in the Greek mythology. That’s why Danny Thrope (Chief Scientist) chose the name to reference it as a language to communicate with the database (Oracle at that time), hence; “If you want to talk to Oracle, go to Delphi”

It is funny to know that Danny left Borland to Google and later to Microsoft, as well as Chuck Jazdzewski (Chief Scientist and Architect), and Anders Hejlsberg (Chief Architect) who moved to Microsoft to be the Lead Architect of the C# team.

The most stable versions of it were 5 and 7 (2002) while other versions did not get much acceptance, specially after the transition to .NET and removing Win32 support. Last I heard about Delphi was that it was going to be sold.

Last week, I found an announcement and I knew the rest of the story. Borland did not get an appropriate offer, so they split the Developer Tools Group into a self-managed company called CodeGear which continued to release Delphi targeting Win32 Development after the inability to compete with C# in .NET development.

Earlier this year, Borland sold CodeGear to Embarcadero Technologies and the later decided to issue two parallel releases, one for Win32 and one for .NET based on Microsoft Visual Studio Shell.

Delphi Prism for .NET is going to compete on the area of cross-platform development as it is going to target development on .NET as well as other non Microsoft operating systems.

Dynamic Typing

In my last post, I talked about Duck Typing and I said it is one of the principle of Dynamic Typing, but don’t have to be in a dynamically typed language.

In order to discuss Dynamic Typing, we need to go thorough other typing systems and know the differences between them

Implicit Typing (or Type Inference) [C# 3.0 and later]:

It is one of the forms of Latent Typing as well as Duck Typing and Dynamic Typing. Let’s see this example

var test = 5; // test is an integer

Here, you don’t have to specify the type as the Compiler can infer from the statement that the variable will hold an integer. That’s why it cannot be used if declaration and assignment are not on the same statement…

var test; // Compilation error
test = 5;

Implicit typing is used mainly when the developer wants to use the result of a function, or an expression (as in LINQ) without the need to specify its type, as the compiler already knows the type. Also, if Explicit casting is used, there is no need for explicit typing…

var test = (int) cmd.ExecuteScalar();

Dynamic Typing [Ruby, Python, and C# 4.0]

It is another form of Latent Typing, but unlike Implicit typing, type is deduced at runtime, so, there is no type checking at compile time. The support for dynamic typing is introduced in C# 4.0 to support API calls into dynamic type languages, or the use of other non-typed data, like XML.

XElement element = XElement.Parse(@"
dynamic personXml = new DynamicXml(element);
personXml.FirstName = "Bob";

It is important to know that once a variable type is defined at runtime, it cannot be redefined later as another type. i.e. Dynamic Typing is not Weak Typing

Weak Typing (or Loose Typing) [Javascript, VB 6.0]

In javascript, this code is valid

var x = new Array(); // Any array
x[0] = "One"; // First element is a string, other elements can be any type
x[1] = "two";
x[2] = "three";
alert(x.length); // return 3
x = x.join(""); // Now x is a string not an Array
alert(x.length); // now return 11 (string length)

Weak typing is antonym to Strong Typing, while Dynamic Typing is antonym to Static Typing.

Here are some good related articles about typing systems by Bruce Eckel (author of Thinking in C++ and Thinking in Java):

Strong Typing vs. Strong Testing
About Latent Typing
How to Argue about Typing
I’m Over It

Duck Typing

While browsing the net, I found that Typemock Isolator 5.1.1 has been released, which is a mocking framework that I should try one day.

What I’m interested in is its ability to “swap” calls between real and fake objects even if they don’t implement the same interface, like this:

var duck = new Duck(); // The real, untestable class, with a Talk() method
var dummy = new Dummy(); // The fake, testable class, with another Talk() method
Assert.AreEqual("Quack", dummy.Talk()); // Then the dummy is a duck

I guess the Isolate class is “borrowed” from Ruby, but anyway, it makes testing easier.

This can be possible by applying the concept of “Duck Typing” which was named as James Whitcomb Riley said

If it walks like a duck and quacks like a duck, I would call it a duck


So, regardless of the properties and methods of both the dummy and the real duck, a dummy can be considered a duck if it satisfies the properties and methods of a real duck in the current context, or in other words; it does not have to inherit from a duck nor satisfy all behavior of a real duck, but only what we need right now [Talk()]

Duck typing is a principle of Dynamic Typing (Which I plan to blog about next), and it is a heavily used in Dynamic Languages like Python, Ruby.

It is sometimes used in Static Languages, and may be more often than we expect. Here is a blog about Duck Notation in C# in which we find out that iterators in a foreach statement use duck typing. Also in BOO you can define a variable as duck.

Currently there is an open source project to enable duck-typing in C#, and also it is planned to be in the upcoming C# 4.0

I have failed a sprint!

Welcome back everyone. I have been busy for the last month working hard trying to achieve a substantial success in this sprint as it had a special value to me; first, because it came after a long time of being idle, and second, because we had just resolved some external issues that held us back in the previous sprints.

At the beginning of the sprint we went through with a high velocity without the need for any overtime nor affecting quality which impressed me and later we had some tasks that required additional efforts than expected so we started losing velocity. We were still inline with the optimal burn-down but not for long.

I was still convinced that the remaining tasks can be squeezed in the final few days of the sprint. So we kept the hard work crossing our fingers to finish on time. Unfortunately, we had to extend the sprint for one day, ignore some features, jeopardize quality, and finally (as expected), the final build was rejected.

It is hard to admit the failure, but the bitterness of failure is the medicine that heals your weaknesses, and our sprint retrospective was really fruitful and full of lessons learned, so here are some:

  1. Pairing of tasks does not always result in dividing the effort (the famous example: nine women cannot give birth to a baby in one month).
  2. Instead of pairing, you can divide tasks into smaller ones, which have more benefits; more accurate estimation, a checklist to define what’s is meant by “done”, and less dependency of tasks.
  3. It is better to be pessimistic in you estimation till your team proves otherwise than to commit to what you are not 100% sure you can achieve.

And my personal lesson I learned was:

  1. It feels good to be superman, but it feels worse if you fails to prove it.

Planning Poker Cards

If you don’t know what are planning poker cards are, it is one of the nice ways used by Agile teams to estimate the effort of a user story, as the whole team of developers are involved in estimating the effort, not only managers.

If that estimation is done manually, you can have funny cases like these, so some would recommend doing it using cards. I personally think that a nice deck of regular poker cards would do the job, but they might not be as interesting as the Agile version.

You can also play the planning game online here which is brought to you by agile consultants and trainers at Mountain Goat Software.