Ahmed’s Dev-Shop

Understand DateTime, avoid Format-Hell

Posted in .Net, Engineering, programming, software by Ahmed Siddiqui on April 15, 2009

One of the most common mistakes programmers do is to treat the DateTime as string, or in another words always assuming a specific date format.

How DateTime Works
In strong typed languages like Java and .Net, DateTime contains the
date and time value as a consolidated numeric value without any format specification.
The culture aware ToString() method of DateTime converts the time value
according to the culture/format specifications of the system and configuration.

How to use?
Always use DateTime type for date and time values especially when savin/retriving DateTime values from/to Database.
Always use command parameters with proper types for passing values from application to database.

What to avoid?
Using string to contain DateTime values can become a disaster especially in large application.
You may find yourself trapped in a Format-Hell if you are assuming any particular format in calculation or representation
Never pass Datetime values as string across platforms or contexts for instance application-to-database

Advertisements

How to get the worst of all worlds

Posted in Uncategorized by Ahmed Siddiqui on April 10, 2008

 
This is the story of ancient war between Software Scientist and Software Craftsmen on the ground of Software Engineering
The Scientists

Slogans:
   Let’s reinvent the wheel
   Complexity is charm

   Think out-of-the-box (never look inside)

Whenever company gets a project the developers are in search of well-hyped patterns and practices. Whatever the projects require, whatever the timelines are, they follow impressions, seeking complexities to passionate their lives. The problem is they want to combine the universal truths they get from their gurus, with the hypes. They get the compliance in few of the cases. It becomes a routine that start with complexity and when you stuck, let the things fly.
They often suggest the solutions they think they should learn. According to their point of view: software projects are to create a difference, even if the project fails, even if they do not add any value, if they implement state-of-the-art technologies, they consider it success.

The Craftsmen: the delivery people
Slogans:
We deliver
Quality is just a fantasy, don’t talk about it
Ad-hocism
Research is a synonym of time-wasting;


Fortunately some of the projects who comply with hyped patterns and rigid practices succeeded to achieve the timelines, thanks fortune. And now the support people are ready to show their quick solutions. They’ll show that the tasks completed by the developers in month was just a matter of days. Thanks to encapsulation; no one knows what’s inside J

Till the day the application is safe from the quick solutions of support staff, it shows some stability. And once it gets the first JUGAR—synonym for a careless ad-hoc solution in Urdu language—the application becomes more addicted to their JUGARs and provides more options for support people to prove their problem solving skills.

Why Patterns Suck?

Posted in Engineering, mindset, programming, software, Thoughts, workplace by Ahmed Siddiqui on April 10, 2008

Surprised when I heard some people saying “Patterns suck”, I was eager to know why they hate these precious guidelines which often save us from reinventing the wheel, letting us using it.

Fortunately after just few days I had to work with some confident developers, known as pattern-lovers. Having plenty of technical knowledge, they were used to count the names of patterns–and there authors–on finger tips. People, you can speak technobabble with, for not just hours but for days. I admired them and found myself among blessed people.

Later I found something strange, besides all their knowledge they had very few success stories and their management was not satisfied with their problem solving skills.

I had started observing the causes of their failure. Mean while I had to design an architecture for a coming enterprise business application. I started scaffolding by enhancing and optimizing my legacy libraries and framework with my team. I asked the experts to review my approach to let my approach become foolproof.

Geeks love technical discussions so I got a prompt response and they started highlighting the weaknesses, I was very glad as I got a chance to improve. But unexpectedly most of the issues identified were as follows:

Geeks: Aren’t you using NHibernate (a port for Hibernate for .Net)?

Me: Nope, I personally admire NHibernate for its OO approach and database independence but I think that this application does not have complex business processing, instead it mostly comprise of chatting between the user and database. It also comprises of complex reports which is not a specialty of NHibernate. While our tailored framework provides Report Factory and configuration as well as tiered approach for reporting. Another reason is that our expertise on NHibernate do not allow us to use it in a time-critical project at this stage.

Geek: What? Do you know where NHibernate came from, it’s a port of Hibernate, being used in the most powerful language “Java”. It has nothing to compete with MS’ ADO objects.

Me: Yes, I do agree that Java and it’s platforms are lot more maturer but since every language or technology has some of its own strengths and weaknesses, our framework and libraries are optimized with the strengths of .Net. Our wrapper classes exploiting some new features provide in the latest version of .Net.

Geek: Hey don’t use ADO.Net objects, they do nothing but violates layering These objects are mess. You should use pure objects that’s why I recommended you to use NHibernate.

Me: I think it depends that how are you using them, in our scenario they are completely database independent because they are boxed in generic objects and are created by abstract factories so we can enjoy Inversion of Control, Polymorphisms, and Database Independence.

Geeks: These libraries are not open source, you don’t know what they have written in it.

Me: I admire the benefits of open source but these object are rich, free, built-in, tested and performing well in enterprise applications. I do not very often use them but I found them very useful in such kind of applications.

Geeks: You incorrectly applied this pattern; let me show you the documentation.

Me: This pattern like other patterns have different applications, I am following this approach because it fits well in this scenario. This flexibility is also allowed by experts.

Geek: No, patterns should be followed as is. They are not to be compromised for performance or whatever. And remember enterprise applications, built on great technologies like EJB, looks graceful even if they are not enough performant.

Geek: Increase your number of layers like we have did in that application. You have not decoupled enough.

Me: Yes previously I did have the same number of layers but I found it as an overkill in this project, so I modified this version for medium-sized performance-hungry applications.

Geek: And why did you coupled these two major tiers, this is an unacceptable violation of N-Tier Architecture

Me: No, these are still two different layers, but I am keeping them in a single project during development as most of the developers are working on both layers. They still can be deployed on different servers.

Geek: I’m still not satisfied, a lot patterns have not been used, recommended by the gurus and we follow them because we know they are the best.

Me: They might have recommended it for some different type of project and this approach may be suitable in that particular scenario.

Geek: We found their practices the best in all type and size of projects, whatever, it’s not that simple you think it is, you have to add a lot more complexity.

Me: May be you are right as I found you very knowledgeable but I learned and believe that a complex system that works is invariably found to have evolved from a simple system that works.

… that’s how I got to know somehow why people hate patterns”