Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » The problem with 'Null'
Re: The problem with 'Null' [message #20469 is a reply to message #20467] Fri, 20 March 2009 09:52 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14265
Registered: November 2005
Ultimate Member
gridem wrote on Fri, 20 March 2009 03:16

Thank you very much for detailed answers! It's very useful for me to understanding intrinsics of Upp.

But let's me to understand my opinion. I think that Null approach is not narrow-minded but generic. It uses for Value, it uses for many simple types.

Because I use a lot the templates, overloaded functions and code generation I have to utilize the generic methods for every types that I want to use. And I use Null as some kind of parameter state that I can treat as:
1. Init/Non init
2. Error on function return.
3. Default values to call the function to distinguish it from nondefault values:
void some_fun(int a, int b = Null, bool c = Null, ...)
{
  if (b == Null)
    b = some_complex_calculated_value(a);
  ...
}

etc



Two notes:

You cannot really define Null for bool, as it has only 2 values..

It is more correct to use "IsNull" instead of "== Null".

Quote:

So to see this approach for String's and Vector's I have to do workaround. May be I should not use the generics but another mechanism?


Well, I can see where you are heading, but I do not really like that path Smile

My only apology at this moment is that U++ is "practice driven", and in the whole history (which now spans abuot 10 years), we never missing IsNull for containers...

BTW, as you have noticed, there is the small issue with String Null - empty string is considered Null.

I agree this is sort of controversial decision. Indeed, a couple of years ago, we identified it as mistake and tried

IsNull(String()) == false
IsNull(String(Null)) == true
String(Null) == String()

variant. Well, what happened is that in practice, this was found to be rather unfortunate. I guess the primary problem is that it is very convenient and natural, when working with databases and GUI, that all empty String gui fields are inserted as Nulls. With above, you would need to have additional GUI buttons to say whether the field is empty or whether it is null.

Similar issues can be found across the code. That is why we went back to

IsNull(String()) == true

As a sidenote, this equivalence was originally taken from Oracle.

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: In some cases CParser can be out of buffer
Next Topic: Possible bug/clarification only callback2 was changed for const Object*
Goto Forum:
  


Current Time: Sat Jul 12 11:35:12 CEST 2025

Total time taken to generate the page: 0.05498 seconds