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. null vs String.Empty

null vs String.Empty

Scheduled Pinned Locked Moved The Lounge
c++visual-studiocomarchitecturequestion
49 Posts 23 Posters 3 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.
  • C Chris Maunder

    If you have a function that returns a string, and that function fails, do you prefer to return null or String.Empty? Vote 1 = null Vote 5 = String.Empty

    cheers, Chris Maunder

    CodeProject.com : C++ MVP

    M Offline
    M Offline
    Member 96
    wrote on last edited by
    #41

    Either depending on how critical it is.

    My responsibility ends where your ability to think for yourself begins.

    1 Reply Last reply
    0
    • J Judah Gabriel Himango

      Jeremy Falcon wrote:

      even if it gets bad params

      I'm a believer that once you start tolerating bad input, your whole system gets messed up. In my experience, it's best to stop when you get bad input, otherwise all sorts of things start going wrong. Of course, since you're writing C, exceptions are out of the question for you. The best you can do is return soon as you get bad input, and hope the caller checks your error code.

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: Dumbest. Movie. Title. Evaaar. The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

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

      Judah Himango wrote:

      I'm a believer that once you start tolerating bad input, your whole system gets messed up.

      Um, nobody said to tolerate it. I said to let the caller know something was bogus. And, letting the caller know a value is messing up a system, I'd wager there were really other aspects in that system(s) that lead to the issues.

      Judah Himango wrote:

      Of course, since you're writing C, exceptions are out of the question for you. The best you can do is return soon as you get bad input, and hope the caller checks your error code.

      Most people tend to use exceptions in a poor way. It's about program flow really.

      Jeremy Falcon A multithreaded, OpenGL-enabled application.[^]

      1 Reply Last reply
      0
      • C Chris Maunder

        If you have a function that returns a string, and that function fails, do you prefer to return null or String.Empty? Vote 1 = null Vote 5 = String.Empty

        cheers, Chris Maunder

        CodeProject.com : C++ MVP

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #43

        String.Empty, of course. Just like I'd always use Environment.NewLine, even though I know what it is always going to be. Any sort of constant defined by the framework is there to be used, it documents your code and it means that you're conforming to the framework, assuming that one day it may exist on anothe platform where any of those values may concievably change. Just like I'd always use SW_HIDE and not 0, I know it won't change, but it doesn't hurt to do things properly.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        S 1 Reply Last reply
        0
        • C Christian Graus

          String.Empty, of course. Just like I'd always use Environment.NewLine, even though I know what it is always going to be. Any sort of constant defined by the framework is there to be used, it documents your code and it means that you're conforming to the framework, assuming that one day it may exist on anothe platform where any of those values may concievably change. Just like I'd always use SW_HIDE and not 0, I know it won't change, but it doesn't hurt to do things properly.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          S Offline
          S Offline
          Shog9 0
          wrote on last edited by
          #44

          Christian Graus wrote:

          Just like I'd always use SW_HIDE and not 0

          Uh, i think the choice was between String.Empty (== "") and null (== null)...

          ---- Scripts i’ve known... CPhog 1.8.2 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.2 - printer-friendly forums Expand all 1.0 - Expand all messages In-place Delete 1.0 - AJAX-style post delete Syntax 0.1 - Syntax highlighting for code blocks in the forums

          C 1 Reply Last reply
          0
          • S Shog9 0

            Christian Graus wrote:

            Just like I'd always use SW_HIDE and not 0

            Uh, i think the choice was between String.Empty (== "") and null (== null)...

            ---- Scripts i’ve known... CPhog 1.8.2 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.2 - printer-friendly forums Expand all 1.0 - Expand all messages In-place Delete 1.0 - AJAX-style post delete Syntax 0.1 - Syntax highlighting for code blocks in the forums

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #45

            Oh - that's what I get for responding first thing in the morning. I *always* use string.IsNullOrEmpty to check strings, so the end result for me is the same.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

            1 Reply Last reply
            0
            • C Chris Maunder

              If you have a function that returns a string, and that function fails, do you prefer to return null or String.Empty? Vote 1 = null Vote 5 = String.Empty

              cheers, Chris Maunder

              CodeProject.com : C++ MVP

              P Offline
              P Offline
              Paul Watson
              wrote on last edited by
              #46

              Null in the Maunderverse but normally an exception in mine. I guess if it was in the context of nullable columns in a database then you could return null for a string return type. But I think a failure should be indicated by an exception, not a null that subsequent code will trip over without additional checking. Then again you could just start using Ruby and stop worrying... ;)

              regards, Paul Watson Ireland FeedHenry needs you

              Shog9 wrote:

              eh, stop bugging me about it, give it a couple of days, see what happens.

              1 Reply Last reply
              0
              • C Chris Maunder

                I love it how a discussion on programming techniques invariable leads to a general slamming of VB. Poor VB...

                cheers, Chris Maunder

                CodeProject.com : C++ MVP

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

                It was just too tempting. I don't know. It's like, bashing VB is just there for the taking. :laugh:

                Jeremy Falcon A multithreaded, OpenGL-enabled application.[^]

                1 Reply Last reply
                0
                • L led mike

                  Jeremy Falcon wrote:

                  Anyone that uses an empty string needs to lay down the VB books IMO

                  That's just foolish.

                  led mike

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

                  led mike wrote:

                  That's just foolish.

                  Unlike your foolish crap in the SB, mine was also a joke. I suspect in your attempt to "get back at me", reality escaped you. Now, so you don't seem crazy, this is where you reply saying yours was also a joke. But, we both know the reason you said it. And to that I say, next time try understanding what I'm saying when I say you're acting a fool rather than get all butt hurt and learn nothing.

                  Jeremy Falcon A multithreaded, OpenGL-enabled application.[^]

                  L 1 Reply Last reply
                  0
                  • J Jeremy Falcon

                    led mike wrote:

                    That's just foolish.

                    Unlike your foolish crap in the SB, mine was also a joke. I suspect in your attempt to "get back at me", reality escaped you. Now, so you don't seem crazy, this is where you reply saying yours was also a joke. But, we both know the reason you said it. And to that I say, next time try understanding what I'm saying when I say you're acting a fool rather than get all butt hurt and learn nothing.

                    Jeremy Falcon A multithreaded, OpenGL-enabled application.[^]

                    L Offline
                    L Offline
                    led mike
                    wrote on last edited by
                    #49

                    :laugh: Not at all. I never figured out what yours meant so the next time I saw you post I replied "That's just foolish", it doesn't mean anything. :-D

                    led mike

                    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