Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Nullabilityatastic

Nullabilityatastic

Scheduled Pinned Locked Moved The Weird and The Wonderful
questionlearning
8 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Keith Barrow
    wrote on last edited by
    #1

    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

    J D B 3 Replies Last reply
    0
    • K Keith Barrow

      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

      J Offline
      J Offline
      Jeroen De Dauw
      wrote on last edited by
      #2

      Awesome code. Can I use it in my application or is it licensed?

      Jeroen De Dauw --- Forums ; Blog ; Wiki --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

      I 1 Reply Last reply
      0
      • J Jeroen De Dauw

        Awesome code. Can I use it in my application or is it licensed?

        Jeroen De Dauw --- Forums ; Blog ; Wiki --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

        I Offline
        I Offline
        Ian Shlasko
        wrote on last edited by
        #3

        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)

        1 Reply Last reply
        0
        • K Keith Barrow

          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

          D Offline
          D Offline
          Don Kackman
          wrote on last edited by
          #4

          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

          S 1 Reply Last reply
          0
          • D Don Kackman

            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

            S Offline
            S Offline
            Super Lloyd
            wrote on last edited by
            #5

            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.

            J 1 Reply Last reply
            0
            • S Super Lloyd

              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.

              J Offline
              J Offline
              Jeremy Tierman
              wrote on last edited by
              #6

              you forgot the redundant else :)

              1 Reply Last reply
              0
              • K Keith Barrow

                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

                B Offline
                B Offline
                BillW33
                wrote on last edited by
                #7

                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.

                C 1 Reply Last reply
                0
                • B BillW33

                  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.

                  C Offline
                  C Offline
                  Camilo Sanchez
                  wrote on last edited by
                  #8

                  you're missing the point, the post is not about Nullable types but Nullable people

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups