otl_stream manipulation (set_if_not_null)

3 12 2010

To read from any input_stream like OTL (otl_stream), you need to first read a value, and then test. Sometimes like in case of otl_stream test if the value was really NULL. The database could have had null value in the field, however, since otl_stream needs to set some value in your variable, it would set the default, it deems fit. for eg:

otls >> some_float;

The some_float is actually a float, so how would otl_stream set null in it? Instead it sets 0.0F.

After having read the field, you need to check with the otl_stream object, if the read value was actually a null:

otls.is_null()

If you wanted to have a different value as default, then you need to write it this way:

float tmp;
otls >> tmp;
if(!otls.is_null())
    some_float = tmp;

There are 2 issues with this approach:

1. you cannot do something like this:
otls >> some_bool >> some_float >> some_std_string;

2. Consider if you had many more objects for which you need to first check if the database had null for it, there would be too many such checks and tmp variables of different kind.

So how about using template class for doing this to avoid writting code for different types of objects which essentially does the same thing for every type?

With template classes the ugliness of the code increases, because you need to specify the template parameter for any object and you could end up with a lot of intimidating angular brackets “< >”:

otls >> SomeClass<bool>(some_bool) >> SomeClass<float>(some_float) >> SomeClass<std::string>(some_std_string) >> var1 >> var2;

This problem can be handled through a template function.

Consider:
otls >> set_if_not_null(some_float);

Here’s the code for it:

template <class T>
struct SINN //Set If Not Null
{
    T& dest_;
    SINN(T& dest) : dest_(dest) {}
};
template <class T>
otl_stream& operator >> (otl_stream& otls, SINN<T>& sinn)
{
    T temp;
    otls >> temp;
    if(!otls.is_null())
        sinn.dest_ = temp;
    return otls;
}
template <class T>
SINN<T> set_if_not_null(T& dest)
{
    return SINN<T>(dest);
}

This solution address both the issues discussed above and you could peacefully write code like this:

otls >> set_if_not_null(some_bool) >> set_if_not_null(some_float)
     >> set_if_not_null(some_std_string) >> var1 >> var2;





Developing Great Software Products

5 05 2010

Hi!

My name is Alok Ashtikar, and I help software companies with their needs of technical trainings and undertake assignments as a technical architect and a freelance developer. I have worked on software product development for over 13 yrs. During this time I had the opportunity to experience all the different roles needed for successful  product development. I have come across products that are atleast 10 to 15 yrs old and are still bringing in huge revenue for the company, as well as products that are not so successful. I have created a training program which details the essential ingredients for successful software product development.

There are so many software companies that have great product ideas. They start building the product without following any system or methodology of development and continue to do so even after a few years. The probability of these products bringing in revenue after 10 to 15 yrs is very low. Also, product development is significantly different from bespoke development (custom development for clients). There are quite a few threats to a company if the “product development” neglected some aspects. The biggest one is legal set backs due to negligence of third part software license terms; and then there could be reasons for a full rewrite of software due to technical reasons. Moreover, to support your product, you cannot keep hiring as you would do for custom development projects, simply because the number of clients could be very large. Also, you cannot afford to lose a customer due to either not meeting SLAs or poor quality. It is a significant loss of efforts, time and money, just because some small aspect of product development was neglected. It is an even bigger threat to the company, if the company is VC funded.

However, by following a system of development that successful product companies have been practicing, the chances of success become brighter. The training program “Developing great software products”, helps companies understand this system of development, and provides necessary pointers to evolve the existing system if any is being followed.

In the complete program we will walk through the following modules of “Developing Great Software Products”: (You can download the presentation with far more details here. Please fill up a 1 minute questionnaire to download the presentation for free.)

  • The Product Definition
  • The Product Mindset
  • The Processes & People
  • Product Design and Development
  • Development Framework
  • Software Quality
  • Metrics
  • Conclusion

You can also select a few modules that you would be interested out of the ones mentioned above.

You can download the presentation with far more details here. Please fill up a 1 minute questionnaire to download the presentation for free.

thanks,

Alok.








Follow

Get every new post delivered to your Inbox.