Why is that such a stupid function?
If ansistring.IsNullOrWhiteSpace(Expression) = False Then
That is so ugly. Why not make it a non-class function in the helper and do:
If Expression.IsNullOrWhiteSpace = False Then
The answer for this is simple:
Delphi compatibililty. Though in theory one could make an overload that works on the string value instead...
@PascalDragon
As a general remark: If you have an expression returning Boolean (like IsNullOrWhiteSpace does), then you should not use = False (or = True). Use the following instead:
Code: Pascal [Select]
if not AnsiString.IsNullOrWhiteSpace(Expression) then ...
// or (for true)
if AnsiString.IsNullOrWhiteSpace(Expression) then ...
What is your particular reasoning for this?
I prefer my verbosity. It leads to less buggy code.
Maybe PascalDragon didn't see your question so I will answer it.
I'm not checking the forum all day long. My usual time is in the morning (Central European Time) and then only once for unread messages.
And @
GypsyPrince,
440box is right when he says that this closes the door for potential bugs. For this you need to understand how the Boolean types work: From a programmer's point of view they only have the values
True and
False, however internally that isn't entirely correct. They aren't just 0 and 1 (except inside bitpacked structures), but instead they have a size of at least 1 Byte. Values of the types
Boolean,
Boolean8,
Boolean16,
Boolean32 and
Boolean64 are considered
False if their value is
0 and
True if the value is
1. Values of the types
ByteBool,
WordBool,
LongWord and
QWordBool are considered
False if their value is
0, but the
True if their value is
<> 0. If you do a comparison with
= False you do a comparison with the value of
= False, which is
0. And for
True the comparison is with
1. You can maybe already see where I'm going with that?
Now assume you have a bug in your code (or in third party code) that returns a "corrupted" Boolean value (e.g. replaced with some random value where the lowest bit is not set). Then this can mean that the
= True check will not be handled correctly.
Please note that in most cases the compiler correctly handles such comparisons by reducing them from
BoolExpr = True|False to
BoolExpr, but that is no guarantee (especially in more complex expressions).
Also it's simply more correct to use the Boolean expression directly: the
if-statements takes a Boolean expression. Any expression that returns a Boolean is automatically a Boolean expression. So why complicate things further by introducing
another Boolean expression?