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   |
 |
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 
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
|
|
|
 |
|
The problem with 'Null'
By: gridem on Thu, 19 March 2009 08:04
|
 |
|
Re: The problem with 'Null'
By: gridem on Thu, 19 March 2009 08:42
|
 |
|
Re: The problem with 'Null'
|
 |
|
Re: The problem with 'Null'
By: mirek on Thu, 19 March 2009 09:20
|
 |
|
Re: The problem with 'Null'
By: gridem on Fri, 20 March 2009 08:16
|
 |
|
Re: The problem with 'Null'
By: mirek on Fri, 20 March 2009 09:52
|
 |
|
Re: The problem with 'Null'
By: gridem on Sun, 22 March 2009 09:15
|
 |
|
Re: The problem with 'Null'
By: mirek on Mon, 23 March 2009 23:55
|
 |
|
Re: The problem with 'Null'
By: gridem on Tue, 24 March 2009 08:41
|
 |
|
Re: The problem with 'Null'
By: mirek on Tue, 24 March 2009 11:04
|
 |
|
Re: The problem with 'Null'
By: mirek on Thu, 19 March 2009 09:16
|
Goto Forum:
Current Time: Sat Jul 12 11:35:12 CEST 2025
Total time taken to generate the page: 0.05498 seconds
|