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 Insider News
  4. Into the Void: Why void is a bad idea

Into the Void: Why void is a bad idea

Scheduled Pinned Locked Moved The Insider News
discussionquestioncareer
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.
  • T Offline
    T Offline
    Terrence Dorsey
    wrote on last edited by
    #1

    Tech.Pro[^]:

    I've been doing this programming thing for a long time now (8 professional years), and during that time I have accumulated a lot opinions (some are right, some are probably wrong). In this phase of my career I am looking at what programming constructs can I use to make my life easier. One thing that sticks out to me as a sore point is the keyword void.... To state it simply, void is useful when I want to perform an action on an object and don't expect a result returned. In theory it sounds great, but if I don't expect a single result back, I am most likely going to want to inspect the object itself, or perform another action on the object.

    To void or not to void... what do you think?

    B J P W S 7 Replies Last reply
    0
    • T Terrence Dorsey

      Tech.Pro[^]:

      I've been doing this programming thing for a long time now (8 professional years), and during that time I have accumulated a lot opinions (some are right, some are probably wrong). In this phase of my career I am looking at what programming constructs can I use to make my life easier. One thing that sticks out to me as a sore point is the keyword void.... To state it simply, void is useful when I want to perform an action on an object and don't expect a result returned. In theory it sounds great, but if I don't expect a single result back, I am most likely going to want to inspect the object itself, or perform another action on the object.

      To void or not to void... what do you think?

      B Offline
      B Offline
      Brisingr Aerowing
      wrote on last edited by
      #2

      Interesting. Not sure I totally agree. For instance (no pun intended), what about a class that abstracts out logging? Would those methods really need to return the class instance? I don't really see what there is to gain there.

      Gryphons Are Awesome! ‮Gryphons Are Awesome!‬

      1 Reply Last reply
      0
      • T Terrence Dorsey

        Tech.Pro[^]:

        I've been doing this programming thing for a long time now (8 professional years), and during that time I have accumulated a lot opinions (some are right, some are probably wrong). In this phase of my career I am looking at what programming constructs can I use to make my life easier. One thing that sticks out to me as a sore point is the keyword void.... To state it simply, void is useful when I want to perform an action on an object and don't expect a result returned. In theory it sounds great, but if I don't expect a single result back, I am most likely going to want to inspect the object itself, or perform another action on the object.

        To void or not to void... what do you think?

        J Offline
        J Offline
        jfriedman
        wrote on last edited by
        #3

        I think void is a representation anything which is something. The way I see it NULL cannot be void but the void can be NULL if that makes sense...

        1 Reply Last reply
        0
        • T Terrence Dorsey

          Tech.Pro[^]:

          I've been doing this programming thing for a long time now (8 professional years), and during that time I have accumulated a lot opinions (some are right, some are probably wrong). In this phase of my career I am looking at what programming constructs can I use to make my life easier. One thing that sticks out to me as a sore point is the keyword void.... To state it simply, void is useful when I want to perform an action on an object and don't expect a result returned. In theory it sounds great, but if I don't expect a single result back, I am most likely going to want to inspect the object itself, or perform another action on the object.

          To void or not to void... what do you think?

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          I didn't read it, but it seems to be something I agree with. There are many cases where I'd like to chain calls together but can't because the method is void.

          1 Reply Last reply
          0
          • T Terrence Dorsey

            Tech.Pro[^]:

            I've been doing this programming thing for a long time now (8 professional years), and during that time I have accumulated a lot opinions (some are right, some are probably wrong). In this phase of my career I am looking at what programming constructs can I use to make my life easier. One thing that sticks out to me as a sore point is the keyword void.... To state it simply, void is useful when I want to perform an action on an object and don't expect a result returned. In theory it sounds great, but if I don't expect a single result back, I am most likely going to want to inspect the object itself, or perform another action on the object.

            To void or not to void... what do you think?

            W Offline
            W Offline
            Wonde Tadesse
            wrote on last edited by
            #5

            Terrence wrote:

            To void or not to void... what do you think?

            It depends. Based on the example provided, it makes sense to apply Fluent Interface and to avoid void. However there are numerous cases which don't need an instance to be returned. And hence a void method is not a bad idea.

            Wonde Tadesse

            1 Reply Last reply
            0
            • T Terrence Dorsey

              Tech.Pro[^]:

              I've been doing this programming thing for a long time now (8 professional years), and during that time I have accumulated a lot opinions (some are right, some are probably wrong). In this phase of my career I am looking at what programming constructs can I use to make my life easier. One thing that sticks out to me as a sore point is the keyword void.... To state it simply, void is useful when I want to perform an action on an object and don't expect a result returned. In theory it sounds great, but if I don't expect a single result back, I am most likely going to want to inspect the object itself, or perform another action on the object.

              To void or not to void... what do you think?

              S Offline
              S Offline
              StM0n
              wrote on last edited by
              #6

              Khalid Abuhakmeh wrote:

              Now what happens when I change void to return this, or the instance of the object that I am using?

              If I'm not using fluent interface, I won't win a thing... I'm with Brisingr Aerowing[^] like the idea (I like fluent interfaces :)), but it depends...

              (yes|no|maybe)*

              1 Reply Last reply
              0
              • T Terrence Dorsey

                Tech.Pro[^]:

                I've been doing this programming thing for a long time now (8 professional years), and during that time I have accumulated a lot opinions (some are right, some are probably wrong). In this phase of my career I am looking at what programming constructs can I use to make my life easier. One thing that sticks out to me as a sore point is the keyword void.... To state it simply, void is useful when I want to perform an action on an object and don't expect a result returned. In theory it sounds great, but if I don't expect a single result back, I am most likely going to want to inspect the object itself, or perform another action on the object.

                To void or not to void... what do you think?

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                Unless you really, really think your code is going to be chained together, YAGNI.

                I was brought up to respect my elders. I don't respect many people nowadays.
                CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier

                1 Reply Last reply
                0
                • T Terrence Dorsey

                  Tech.Pro[^]:

                  I've been doing this programming thing for a long time now (8 professional years), and during that time I have accumulated a lot opinions (some are right, some are probably wrong). In this phase of my career I am looking at what programming constructs can I use to make my life easier. One thing that sticks out to me as a sore point is the keyword void.... To state it simply, void is useful when I want to perform an action on an object and don't expect a result returned. In theory it sounds great, but if I don't expect a single result back, I am most likely going to want to inspect the object itself, or perform another action on the object.

                  To void or not to void... what do you think?

                  L Offline
                  L Offline
                  Leslie Sanford
                  wrote on last edited by
                  #8

                  Terrence Dorsey wrote:

                  but if I don't expect a single result back, I am most likely going to want to inspect the object itself

                  Why? To ensure that the state of the object is correct? That's the job of the object itself.

                  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