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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. The Lounge
  3. Rubs the fur the wrong way

Rubs the fur the wrong way

Scheduled Pinned Locked Moved The Lounge
questioncomdiscussion
13 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.
  • M Marc Clifton

    I did not know this: Concatenating a null string is legal[^] This works:

    string s=null;
    s+="Hello World";

    Oddly (as someone in the link above points out):

    int? i = null;
    i+=1;

    results in i==null. Interesting stuff. Sort of rubs the fur the wrong way. (BTW, those that replied to my best practice question, I'll get back to you soon, the responses are awesome!) Marc

    N Offline
    N Offline
    Nish Nishant
    wrote on last edited by
    #4

    The int? behavior is the expected one. When an int? is null, its int equivalent is 0 (int's default). Since string is a reference type (with some value semantics), you'd expect its default to be null (which is so), but for concatenation they changed it to default to String.Empty. Although it does make sense to do it that way as the most useful behavior (for most or all scenarios).

    Regards, Nish


    Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview

    M C 2 Replies Last reply
    0
    • M Marc Clifton

      I did not know this: Concatenating a null string is legal[^] This works:

      string s=null;
      s+="Hello World";

      Oddly (as someone in the link above points out):

      int? i = null;
      i+=1;

      results in i==null. Interesting stuff. Sort of rubs the fur the wrong way. (BTW, those that replied to my best practice question, I'll get back to you soon, the responses are awesome!) Marc

      J Offline
      J Offline
      Jeremy Falcon
      wrote on last edited by
      #5

      Marc Clifton wrote:

      Sort of rubs the fur the wrong way.

      The thing that rubs me the wrong way in PHP is this...

      <?php
      for($x=0; $x<10; $x++)
      {
      $a = $x; // didn't declare $a at all
      }

      echo $a; // $a is totally valid here
      

      ?>

      Or...

      <?php
      for($x=0; $x<10; $x++)
      {
      $aa = $x; // whoops, a typo
      }

      echo $a; // $a is STILL totally valid here
      

      ?>

      Now I like how PHP handles types and variables to make things easy, but ya know this is taking it a bit too far.

      Jeremy Falcon

      A 1 Reply Last reply
      0
      • N Nish Nishant

        The int? behavior is the expected one. When an int? is null, its int equivalent is 0 (int's default). Since string is a reference type (with some value semantics), you'd expect its default to be null (which is so), but for concatenation they changed it to default to String.Empty. Although it does make sense to do it that way as the most useful behavior (for most or all scenarios).

        Regards, Nish


        Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #6

        Nish Sivakumar wrote:

        When an int? is null, its int equivalent is 0 (int's default).

        Which is why I don't understand why i+=1 != 1 in that case.

        Nish Sivakumar wrote:

        Although it does make sense to do it that way as the most useful behavior

        I don't know -- I would think it should throw a null reference exception. Though now that I think about it, I think other places, like in printing to the console, a null string is also handled as an empty string. Marc

        N 1 Reply Last reply
        0
        • M Marc Clifton

          Nish Sivakumar wrote:

          When an int? is null, its int equivalent is 0 (int's default).

          Which is why I don't understand why i+=1 != 1 in that case.

          Nish Sivakumar wrote:

          Although it does make sense to do it that way as the most useful behavior

          I don't know -- I would think it should throw a null reference exception. Though now that I think about it, I think other places, like in printing to the console, a null string is also handled as an empty string. Marc

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #7

          Marc Clifton wrote:

          Which is why I don't understand why i+=1 != 1 in that case.

          Ah, missed that. Yeah that does seem rather counter-intuitive.

          Regards, Nish


          Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview

          1 Reply Last reply
          0
          • M Marc Clifton

            I did not know this: Concatenating a null string is legal[^] This works:

            string s=null;
            s+="Hello World";

            Oddly (as someone in the link above points out):

            int? i = null;
            i+=1;

            results in i==null. Interesting stuff. Sort of rubs the fur the wrong way. (BTW, those that replied to my best practice question, I'll get back to you soon, the responses are awesome!) Marc

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #8

            I can live with the nullable int example. In my opinion if something starts as a null value then it can only have a new value by a specific assignment. But then what about this:

            int? inotnull = 1;
            inotnull += null;

            Inotnull ends up as null. Now that is counter intuitive IMHO.

            Peter Wasser "The whole problem with the world is that fools and fanatics are always so certain of themselves, and wiser people so full of doubts." - Bertrand Russell

            1 Reply Last reply
            0
            • J Jeremy Falcon

              Marc Clifton wrote:

              Sort of rubs the fur the wrong way.

              The thing that rubs me the wrong way in PHP is this...

              <?php
              for($x=0; $x<10; $x++)
              {
              $a = $x; // didn't declare $a at all
              }

              echo $a; // $a is totally valid here
              

              ?>

              Or...

              <?php
              for($x=0; $x<10; $x++)
              {
              $aa = $x; // whoops, a typo
              }

              echo $a; // $a is STILL totally valid here
              

              ?>

              Now I like how PHP handles types and variables to make things easy, but ya know this is taking it a bit too far.

              Jeremy Falcon

              A Offline
              A Offline
              Andy Brummer
              wrote on last edited by
              #9

              I've been doing a lot of wordpress work, which I consider a pretty solid product, my wife has a web design firm that I help out with. I think they nailed a CMS API that is really easy and straightforward to customize. HOWEVER, I f$#@$ing hate PHP. My day job involves a lot of Javascript (and WebForms) and I chose to start using AngularJS, which is a framework that seems to pick the default option that I would have picked which is awesome. PHP picked the opposite direction at every turn, except they have a decent associative array that everyone uses, that is the saving grace.

              Curvature of the Mind now with 3D

              J 1 Reply Last reply
              0
              • M Marc Clifton

                I did not know this: Concatenating a null string is legal[^] This works:

                string s=null;
                s+="Hello World";

                Oddly (as someone in the link above points out):

                int? i = null;
                i+=1;

                results in i==null. Interesting stuff. Sort of rubs the fur the wrong way. (BTW, those that replied to my best practice question, I'll get back to you soon, the responses are awesome!) Marc

                C Offline
                C Offline
                Colborne_Greg
                wrote on last edited by
                #10

                A major difference between the two examples is that you are comparing a number to an array. A string variable is an array of char, a null array is different then a number without an assigned memory space.

                1 Reply Last reply
                0
                • N Nish Nishant

                  The int? behavior is the expected one. When an int? is null, its int equivalent is 0 (int's default). Since string is a reference type (with some value semantics), you'd expect its default to be null (which is so), but for concatenation they changed it to default to String.Empty. Although it does make sense to do it that way as the most useful behavior (for most or all scenarios).

                  Regards, Nish


                  Blog: voidnish.wordpress.com Latest article: C++ 11 features in Visual C++ 2013 Preview

                  C Offline
                  C Offline
                  Colborne_Greg
                  wrote on last edited by
                  #11

                  A string is an array of char. An empty array has an assigned memory space of the structure of the array with a null stack, adding a char to an array adds the value to the array. A null int is a variable without a memory space.

                  1 Reply Last reply
                  0
                  • A Andy Brummer

                    I've been doing a lot of wordpress work, which I consider a pretty solid product, my wife has a web design firm that I help out with. I think they nailed a CMS API that is really easy and straightforward to customize. HOWEVER, I f$#@$ing hate PHP. My day job involves a lot of Javascript (and WebForms) and I chose to start using AngularJS, which is a framework that seems to pick the default option that I would have picked which is awesome. PHP picked the opposite direction at every turn, except they have a decent associative array that everyone uses, that is the saving grace.

                    Curvature of the Mind now with 3D

                    J Offline
                    J Offline
                    Jeremy Falcon
                    wrote on last edited by
                    #12

                    Andy Brummer wrote:

                    HOWEVER, I f$#@$ing hate PHP.

                    Ironically, I think it's a fantastic language. On the web, I'm a total Unix person, so it's Unix-y roots are appealing. It has a TON of functionality. It's fast. And it's dumbed down just enough for most people to use it with relative ease. But sometimes, just sometimes it would be nice to have to declare a variable.

                    Andy Brummer wrote:

                    and I chose to start using AngularJS

                    I was looking at that, but still not clear on exactly what it does. I'm assuming it's like jQuery but instead uses it's own DOM right? From what I know it's supposed to be nice to manage client-side state with right?

                    Jeremy Falcon

                    A 1 Reply Last reply
                    0
                    • J Jeremy Falcon

                      Andy Brummer wrote:

                      HOWEVER, I f$#@$ing hate PHP.

                      Ironically, I think it's a fantastic language. On the web, I'm a total Unix person, so it's Unix-y roots are appealing. It has a TON of functionality. It's fast. And it's dumbed down just enough for most people to use it with relative ease. But sometimes, just sometimes it would be nice to have to declare a variable.

                      Andy Brummer wrote:

                      and I chose to start using AngularJS

                      I was looking at that, but still not clear on exactly what it does. I'm assuming it's like jQuery but instead uses it's own DOM right? From what I know it's supposed to be nice to manage client-side state with right?

                      Jeremy Falcon

                      A Offline
                      A Offline
                      Andy Brummer
                      wrote on last edited by
                      #13

                      Angular isn't like jQuery. jQuery makes a few things easier and consistent. It adds a few functions that makes many things easier to build. AngularJS is a complete framework that completely changes the way you write interactive pages. It includes client side templating, 2 way data binding, routing, xhd wrapper, animations through attributes, and a whole host of other features. I normally hate frameworks because they end up making the easy stuff a little easier, and the hard stuff impossible. I haven't run into that with angular.

                      Curvature of the Mind now with 3D

                      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