May 7, 2012

.Net: .Any vs .Count

I was reviewing some code and resharper threw up a hint to use

if(myList.Any()){ //conditional code }

instead of

if(myList.Count > 0) { //conditional code }

However, if a line of code is written like the following, it does not throw the same hint

if(myList.Count == 0) { //conditional code }

Of course, upon further review I realized that the developer was only interested to check and continue if the list was empty.

.Any() returns a boolean value which is a semantically better option than the .Count counterparts.

I was curious to know the performance impact and found an interesting response on stackoverflow.com. My understanding from the answer marked correctly is that it is a better option to use when working with IEnumerable types.

Given that in our organization we work a lot with generic lists, .Any() seems to be a good option when all that we want to know is whether the list is empty or not.

May 6, 2012

.NET 4: IsNullOrEmpty vs IsNullOrWhiteSpace

You might be familiar with the following lines of code and may have used it often in your code when validating string values for null, empty or whitespace:

return String.IsNullOrEmpty(value) || value.Trim().Length == 0;

Now, .NET framework 4.0 provides a new API, IsNullOrWhiteSpace which does the same in a much neater way

return String.IsNullOrWhiteSpace(value);

It may not look like a big change, but makes code much more readable, especially if you have multiple string values to check in one if statement.

October 1, 2011

Key benefits of a domain-driven development model for Business Automation

Let me be honest upfront! I have a bias towards working on a domain-driven development model. Yes! I do mean customized, strongly typed entities and not .NET CLR types (typed datasets, datatables, etc). Yet for years, due to preexisting project infrastructure and libraries I have had to develop and enhance software that follow a loosely typed development model along with all its pitfalls.

It took the introduction of Microsoft’s Entity Framework and ASP.NET MVC for the same powers that be, to suddenly wake up and espouse all about domain-driven development. Naturally, I am not the one complaining. ;-)

I am currently reading Phil Haack’s co-authored book, Professional ASP.NET MVC 3, enjoying and referencing it for my current projects.

Finally I am being able to develop software with renewed passion!

The standard joke about software development is regarding the lack of understanding between stakeholders and the software developers. These days, Agile methodology of software development is the rage. This requires a close interaction between a domain expert and the development team in short multiple iterations. As a result, the amount of documentation done for recording requirements is lesser than in the waterfall approach.

Software systems like the business domain have objects that have properties, behavior and interaction. In Domain-driven development, the key aspect is to conceptualize software objects similar to the business domain, using the terminology that domain experts use.

It also pertains to the “strong typing” of these software objects so that the business domain is explicit to the development team. Business stakeholders will always use terminology they understand. If the development team embraces the same terminology while conceptualizing the system, it will result in a domain-driven system that will be very close to the real world business model. There may be concepts for which it may not be easy to use common terminology. In such cases, the stakeholders and development team members must arrive at a consensus.

For example, the domain expert for a healthcare domain sees pharmacist, physician, administrator, nurse, care manager as separate and distinct entities. They have their own behavior and distinct interactions. However, a development team following a domain agnostic approach may just see a “user” entity and assign role as an attribute (and in some cases, a collection of roles for the same user). Such an approach may lead to confusion during development and user acceptance. The focus would shift from the software matching the domain and its workflow to making the client adjust to so-called reusable software developed. A very strong proof of such software is when the end user requires explicit training to use the software.

In the last decade, the datatables have been really popular because their attributes can be changed dynamically at runtime. This flexibility comes at the cost of making it confusing for developers to understand the business model since it is no longer explicit. Datatables also cannot prevent the violation of the principles of “SOLID” OOPS.

My personal opinion is that use of datatables has resulted in a lot of domain-agnostic code written under the perception of software reuse.

Listed below are some of the key benefits that I see in a domain-driven development model. I may have missed a few benefits, while there may be some who would argue against those listed below. Please feel free to share your thoughts with me! :-)

Key Benefits

  • When a development team is attempting to translate the requirements in terms of the business domain, chances are good that the analysis is leading to objects that closely model the business domain, tailored to the end user’s needs. This is opposed to a domain-agnostic approach in which we, as developers, start generalizing beyond the end user’s needs to develop the Utopian ”one-tool-fits-all” software
  • Requirements are always explained from a domain perspective. Conceptualizing the software system in terms of the business domain reduces the risk of misunderstandings between the domain experts and the development team. This also reduces the risk of ‘back-and-forth’ while freezing requirements
  • When everyone is using the same terminology, keeping track of requirement implementation becomes a simpler task
  • It becomes simpler for the domain expert to establish whether the software features map the business requirements in every release cycle (iterations in Agile)
  • The direction of development is closer to the client’s needs
  • The project has lesser chances of going off-track. This is usually established in UAT phases or showcases
  • The coordination is more people driven (since everyone is using the same terminology) that is less top driven, ensuring fewer bottlenecks
  • For a new development team member, learning the domain information can actually be less confusing because they will be able to visualize the domain in the software and be able to co-relate
  • Last but not the least – when we develop domain driven, we end up with more readable code and lesser duplication. As an esteemed colleague of mine commented – “Code should be readable like a newspaper!

 

Please feel free to share your thoughts me! Your suggestions may get incorporated into this blog (with due credits of course!)

September 20, 2011

A bad picture is worth a thousand long discussions. (via Doug Seven)

I agree with Doug that boxes can never represent architecture or information flow although its still necessary for a big picture. This big picture is important for developers for the METRO UI

A bad picture is worth a thousand long discussions. While here at Build I've been in lots of conversations with customers, other attendees, Microsoft MVP’s, Microsoft Regional Directors, and Microsoft engineering team members. One of the recurring topics that I've been talking about ad nausium is the “boxology” diagram of the Windows 8 Platform and Tools (shown here). Now let me tell you, I have drawn a lot of these “marketecture” diagrams in my time and its not easy. These kind of diagrams are ne … Read More

via Doug Seven

September 8, 2011

Browser Usage: IE6 and IE9 predictions

For all of nearly last 7 years that I have worked on web applications, IE6 has tormented me and all my colleagues alike. While the client’s expectation in terms of feature richness has multiplied, IE6 continues to be the standard on which the development has to be based!

I have been following browser usage statistics for the last couple of years at gs.statcounter.com. Although predictions can always swing 10-15% either ways, I am still venturing out to predict the changing scenario of IE 6 to IE 9 in the next 6 months in U.S.

  • As per my analysis, IE 6 will fall below 50% by the end of this year and become negligible by March 2012.
  • IE8 and IE9 will be almost level by March 2012.
  • The rate of change could have been much more rapid had the adoption rate for Windows 7 not been so sluggish (and mostly due to budget constraints).
  • Another key point to note is that there is a great chance that overall share of IE could come down from around 44% to around 41.5% in the next 6 months.
Date IE 6.0 IE 7.0 IE 8.0 IE 9.0
avg +/-

0.16

0.54

1.11

-1.26

2011-10

0.78

4.28

25.95

13.67

2011-11

0.62

3.74

24.84

14.93

2011-12

0.47

3.20

23.73

16.19

2012-01

0.31

2.66

22.62

17.45

2012-02

0.15

2.12

21.51

18.71

2012-03

-0.01

1.58

20.40

19.97

Avg +/- denotes average increase or decrease expected.

March 27, 2011

HTC Desire HD Review

First things first! Lets get started with a screenshot! This is a 4.3 inch screen!

HTC Desire HD

HTC Desire HD

If you are interested in understanding HTC Desire features, please feel free to visit http://www.htc.com/www/product/desirehd/overview.html

Let me talk about the non-technical stuff. I have not been able to explore all the features as yet (which is a good thing) but I have explored the following:

  1. Camera – Although it is 8 Mega Pixels, it works best in cases where objects are not moving. I like the editing stuff.
  2. Contact Management System – This is awesome. It helps you connect your contacts across Facebook, google and regular phone contacts.
  3. Multi-tasking – Except when I use Skype,  I am able to multi-task with ease
  4. HTC Sense – Even iPhone owning colleagues drool at its touch capability
  5. Maps – Pretty good, but need to explore more
  6. Browser – Great experience. I plan to try other browsers
  7. Push Mail – very good, especially the suggestions they give on typing. I have not tried the mike much but it looks promising
  8. Facebook, Twitter, Gmail integration is great. I can share anything at any point of time to multiple options.
  9. Internet connectivity – the USB tethering based internet connection works great! The wireless hotspot also works.
  10. WiFi connectivity – Works seamlessly. Skype works great on wi-fi. In fact, it feels I am speaking on a normal phone connection. On 3G, due to the inconsistent connectivity, the experience was not so smooth.

This is just the beginning, but one thing is sure. This is no poor man’s iPhone. It stands out on it own!

A small mention must be made about the battery life. While it does not get drained so fast on wi-fi or 2G; 3G seems to be drinking its battery.

February 16, 2011

Who cares about modern browsers?

Firefox recently took IE9 and its modern browser claims head on in an article, “Is IE9 a modern browser?”.

Microsoft then retorted with “A Modern Browser”.

The only point the two have proven is eloquence of words. In reality Google’s chrome is the one proving the technical point.

Take for instance that Firefox’s much touted version 4 is still not out. Their adoption rate for new versions is next only to IE. Firefox 3.6 has the majority, but there are still many users for 3.5, 3.0 and a few beta users of 4.0. IE, as every one knows has IE8, IE7 and IE6 all being used in significant numbers. Look at chrome. Chrome 9 and chrome 8. No trace of the lower versions. This will be a very important aspect from a modern browser’s perspective.

Today a developer targeting IE has to cater to too many differences that are there between IE 6, 7 and 8.

The other challenge is that despite all the success of Windows 7, even in U.S., the number of WIN7 users has still not crossed WINXP. Even if IE9 comes out in a few months, it will take at least 2-3 years to become the standard browser when WINXP becomes a minority that no one is really worried about. The current trends for U.S. are less than 1% decrease for WINXP per month over the last 13 months. Currently around 32%, and at this rate, it will not take less than 30-36 months before it comes below 2-3% in U.S. (see http://gs.statcounter.com/#os-US-monthly-201002-201102)

For Firefox, the challenge will remain on how quickly they can bring out the stable version of 4.0 as user patience is very thin these days. Firefox was around 32.8% worldwide 13 months back. Today it is 30.5% worldwide. All the efforts of Firefox are not really leading to an increase in share. They too are taking a step in the right direction, ;-) . However, they have a long way to go and prove that they are a better alternative to Chrome. (see http://gs.statcounter.com/#browser-ww-monthly-201002-201102)

From an end-user’s perspective, I would love to use the browser which is the fastest and most memory/processor efficient. At the moment I will still choose to use Chrome although I like both Firefox 4 and IE9.

From a developer’s perspective, I know that there is going to be a 3 way split between IE, Firefox and Chrome/Safari. The one with the least matching features is the one that will stand out like a sore thumb for me because when making browser compliant sites, we will have to choose the least common denominator. No matter what I like, I have to program to IE6 / IE7 levels and I will continue to hate IE for doing that to me till the time I have to continue doing it.

February 9, 2011

jALRichText Released! (via Assign Labs)

Nice light-weight plugin for rich text editing in a jiffy!

There are many rich text editors available already for use in applications. One of the most popular is FCKEditor. Assign Labs has made a basic rich text editor that will be cross browser compatible, themeable using jQuery UI and at the same time keeping it light weight. The road map includes enhancing the rich text editor to include the following features CSS based styling control with ability to control which CSS style sheets are used Templates … Read More

via Assign Labs

January 20, 2011

How Facebook Ships Code (via FrameThink – Frameworks for Thinking People)

Quite a few learning points for managers / organizations

I'm fascinated by the way Facebook operates.  It's a very unique environment, not easily replicated (nor would their system work for all companies, even if they tried).  These are notes gathered from talking with many friends at Facebook about how the company develops and releases software. Seems like others are also interested in Facebook…   The company's developer-driven culture is coming under greater public scrutiny and other companies are … Read More

via FrameThink – Frameworks for Thinking People

January 11, 2011

My hoped state – My country (via Pranavkaushik’s Blog)

Where the feet are strong and fast, [feet here denote the worker class] And too bold and continuous working, That state will ever last, With no disturbances or jerking. Where the hands do not harass, [hands denote the soldiers and security] And never think of any cheat, That state will always be prosperous, And never tried by anyone's beat. Where the stomach has no disorders,[stomach is the system] And things are thoroughly digested, That state h … Read More

via Pranavkaushik's Blog

Follow

Get every new post delivered to your Inbox.

Join 541 other followers