Nullabilityatastic
-
Firstly, -10 points for using nulls on a green field development in my book. Then I found these fields at the top of the class:
internal class BarHelper : FooHelper
{
//....
/* --------------------------------------
* Nullable value types
* -------------------------------------*/
decimal? _decimalNull = null;
short? _shortNull = null;
int? _intNull = null;
bool? _boolNull = null;
DateTime? _dateTimeNull = null;
//....
}What are these for I wondered? A find reference on
_decimalNull
yeilds:_bazTableAdapter.InsertRow(
cashbackAmount != null ? cashbackAmount.ValueAsDecimal : _decimalNull,
cashbackAmount != null ? cashbackAmount.CurrencyAsShort : _shortNull,
billAmount != null ? billAmount.ValueAsDecimal : _decimalNull,
billAmount != null ? billAmount.CurrencyAsShort : _shortNull,
billAmount != null ? billAmount.ConversionRateAsDecimal : _decimalNull);It's all just wrong (including the DataSets and Table adapters) and just makes me want to weep. Even just using
cashbackAmount != null ? cashbackAmount.ValueAsDecimal : new Nullable<decimal>()
would have been an improvement. On the plus side, as I'm being repeatedly told, we don't have time to do it properly.CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
-
Firstly, -10 points for using nulls on a green field development in my book. Then I found these fields at the top of the class:
internal class BarHelper : FooHelper
{
//....
/* --------------------------------------
* Nullable value types
* -------------------------------------*/
decimal? _decimalNull = null;
short? _shortNull = null;
int? _intNull = null;
bool? _boolNull = null;
DateTime? _dateTimeNull = null;
//....
}What are these for I wondered? A find reference on
_decimalNull
yeilds:_bazTableAdapter.InsertRow(
cashbackAmount != null ? cashbackAmount.ValueAsDecimal : _decimalNull,
cashbackAmount != null ? cashbackAmount.CurrencyAsShort : _shortNull,
billAmount != null ? billAmount.ValueAsDecimal : _decimalNull,
billAmount != null ? billAmount.CurrencyAsShort : _shortNull,
billAmount != null ? billAmount.ConversionRateAsDecimal : _decimalNull);It's all just wrong (including the DataSets and Table adapters) and just makes me want to weep. Even just using
cashbackAmount != null ? cashbackAmount.ValueAsDecimal : new Nullable<decimal>()
would have been an improvement. On the plus side, as I'm being repeatedly told, we don't have time to do it properly.CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
-
It'll cost you 20 IQ points per line, or 50 to put in a commercial product :)
Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)
-
Firstly, -10 points for using nulls on a green field development in my book. Then I found these fields at the top of the class:
internal class BarHelper : FooHelper
{
//....
/* --------------------------------------
* Nullable value types
* -------------------------------------*/
decimal? _decimalNull = null;
short? _shortNull = null;
int? _intNull = null;
bool? _boolNull = null;
DateTime? _dateTimeNull = null;
//....
}What are these for I wondered? A find reference on
_decimalNull
yeilds:_bazTableAdapter.InsertRow(
cashbackAmount != null ? cashbackAmount.ValueAsDecimal : _decimalNull,
cashbackAmount != null ? cashbackAmount.CurrencyAsShort : _shortNull,
billAmount != null ? billAmount.ValueAsDecimal : _decimalNull,
billAmount != null ? billAmount.CurrencyAsShort : _shortNull,
billAmount != null ? billAmount.ConversionRateAsDecimal : _decimalNull);It's all just wrong (including the DataSets and Table adapters) and just makes me want to weep. Even just using
cashbackAmount != null ? cashbackAmount.ValueAsDecimal : new Nullable<decimal>()
would have been an improvement. On the plus side, as I'm being repeatedly told, we don't have time to do it properly.CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
You could write a generic helper class for that.
static class TypedNull
{
public static T GetNull<T>()
{
return null as T;
}
}billAmount != null ? billAmount.CurrencyAsShort : TypedNull.GetNull<short?>()
10 PRINT Software is hard. - D Knuth 20 GOTO 10
modified on Wednesday, December 16, 2009 4:49 PM
-
You could write a generic helper class for that.
static class TypedNull
{
public static T GetNull<T>()
{
return null as T;
}
}billAmount != null ? billAmount.CurrencyAsShort : TypedNull.GetNull<short?>()
10 PRINT Software is hard. - D Knuth 20 GOTO 10
modified on Wednesday, December 16, 2009 4:49 PM
not quite their code! How about:
public static decimal? AsDecimal(this Foo f)
{
if (f == null)
return null;
return f.DecimalValue;
}A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.
-
not quite their code! How about:
public static decimal? AsDecimal(this Foo f)
{
if (f == null)
return null;
return f.DecimalValue;
}A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.
you forgot the redundant
else
:) -
Firstly, -10 points for using nulls on a green field development in my book. Then I found these fields at the top of the class:
internal class BarHelper : FooHelper
{
//....
/* --------------------------------------
* Nullable value types
* -------------------------------------*/
decimal? _decimalNull = null;
short? _shortNull = null;
int? _intNull = null;
bool? _boolNull = null;
DateTime? _dateTimeNull = null;
//....
}What are these for I wondered? A find reference on
_decimalNull
yeilds:_bazTableAdapter.InsertRow(
cashbackAmount != null ? cashbackAmount.ValueAsDecimal : _decimalNull,
cashbackAmount != null ? cashbackAmount.CurrencyAsShort : _shortNull,
billAmount != null ? billAmount.ValueAsDecimal : _decimalNull,
billAmount != null ? billAmount.CurrencyAsShort : _shortNull,
billAmount != null ? billAmount.ConversionRateAsDecimal : _decimalNull);It's all just wrong (including the DataSets and Table adapters) and just makes me want to weep. Even just using
cashbackAmount != null ? cashbackAmount.ValueAsDecimal : new Nullable<decimal>()
would have been an improvement. On the plus side, as I'm being repeatedly told, we don't have time to do it properly.CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
-
Nullable types have their uses; this should not be one of them! :sigh:
Just because the code works, it doesn't mean that it is good code.
you're missing the point, the post is not about Nullable types but Nullable people