Sep 30 2014

A Quote about Best Practices

Category: Quotes ashish sheth @ 20:28

Obeying best practices blindly is not a best practice.

From this answer on stackoverflow

Tags:

Sep 18 2014

Tackling the Arrow head Anti-Pattern

Category: .Net | C# | Design Principles ashish sheth @ 00:13

Frequently you will see following type of code in your code base.

if(result != 1)
{
    if(someOtherResult == 101)
    {
        if(anotherValue == 500)
        {
            // do something
        }
    }
    else
    {
        // do some other thing
    }
}

return;

Here the code forms a shape of an arrow-head, as below:

if
    if
        if
            if
                do something
            end
        end
    end
end

If you see, the main logic is deep down into the nested condition, it increases the cyclomatic complexity of the code.

A better version of the same code could be as below:

if(result == 1)
{
    return;
}

if(someOtherResult == 101 && anotherValue == 500)
{
    // do something
    return;
}

// do some other thing

return;

The above code does a number of things to flatten the code and make it better:

  1. Validations are performed first and it returns at the first opportunity.
  2. Multiple nested conditions are combine into one (with “&&”(logical And) operator. If there are multiple expressions forming one such condition, they can be moved to a separate method returning boolean. That method can then be use in the if condition as below:
if(IsValidResult(someOtherResult, anotherResult)
{
    // do something
    return;
}

bool IsValidResult(int someOtherResult, int anotherResult)
{
    if(someOtherResult == 101 && anotherValue == 500)
    {
        return true;
    }
    return false;
}

Tags: , ,

Sep 16 2014

Podcast that I listen

Category: .Net | Learning | miscellaneous ashish sheth @ 00:45

In the big sea of web, you will find many people telling you the podcast that every developers should listen. Here is my list, and yes, I too think these are the podcast every developer(.Net developer) should listen.

  1. .Net Rocks: This is more than a decade old talk show focusing on Microsoft .Net Technologies. Earlier it used to be a weekly show, but now it has three show a week. Apart from covering anything and everything related to .Net, it also covers mobile app development on Android and iOS.
  2. Hanselminutes: This is the show by Scott Hanselman, which focuses on technology including Microsoft .Net Technology.
  3. HerdingCode: This is a show where discussion goes into nitty-gritty of development tasks. As with the above two, not just the .Net technology, but other aspects of Software development practises are also discussed.
  4. Software Engineering Radio: This is a monthly podcast targeted towards not just .Net developers, but to all software developers in general. So it covers topics which include Software Engineering practises, architecture, design patterns, etc. It also has a rather academic feel and many a times the guests include leading researchers in the field of Computer Science.
  5. MS Dev show: This is relatively a new podcast for Microsoft developers focussing fully to Microsoft technology including topics such as Azure/Cloud, Windows, Windows Phone, .Net etc.
  6. IEEE Software’s On Computing: In this podcast Grady Booch reads from his column “On Computing” in the IEEE Software magazine. In this, he talks software’s impact on humanity.
  7. IEEE Software’s Tools of the Trade: This is again the podcast of an on going column in IEEE Software with the same name. In every episode, it covers software tools to be used within a certain aspect of Software Development, such as documentation, debugging, testing, etc.
  8. HBR IdeaCast: This is a weekly podcast from HBR.org and it is mostly about analysis and advice from leading minds in management.

Let me know what you listen to.

Tags: ,