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. The Lounge
  3. Is the glass half empty or half full?

Is the glass half empty or half full?

Scheduled Pinned Locked Moved The Lounge
helpquestion
23 Posts 14 Posters 2 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.
  • L Lutoslaw

    What are your error flags: optimistic or perssimistic? How do you code:

    boolean success = false;
    try {
    // ...
    success = true;
    } catch (Exception ex) {
    // ...
    }
    return success;

    or

    boolean success = true;
    try {
    // ...

    } catch (Exception ex) {
    success = false;
    // ...
    }
    return success;

    ? Just curious. ;)

    Greetings - Jacek

    K Offline
    K Offline
    Keith Barrow
    wrote on last edited by
    #10

    It's always full[^] In answer to your question:

    try
    {
    // ...
    return true;
    }
    catch (Exception ex)
    {
    // ...
    return false;
    }

    Assuming you don't return anywhere else. I don't agree with an idea that a method must have only one point of exit, and have never found code less readable as a result with modern IDEs. In your example I have to get to the bottom of the method to find out what the boolean does, and you have to worry about defensive coding. Obviously, other people will have different views on this.

    Sort of a cross between Lawrence of Arabia and Dilbert.[^]
    -Or-
    A Dead ringer for Kate Winslett[^]

    1 Reply Last reply
    0
    • L Lutoslaw

      What are your error flags: optimistic or perssimistic? How do you code:

      boolean success = false;
      try {
      // ...
      success = true;
      } catch (Exception ex) {
      // ...
      }
      return success;

      or

      boolean success = true;
      try {
      // ...

      } catch (Exception ex) {
      success = false;
      // ...
      }
      return success;

      ? Just curious. ;)

      Greetings - Jacek

      R Offline
      R Offline
      Roger Wright
      wrote on last edited by
      #11

      I have no tolerance for errors, so why catch them? They're just going to piss me off, and life has enough aggravations. A simple popup that says, "You screwed up; I'm formatting your C: drive" is usually sufficient to prevent future problems.

      Will Rogers never met me.

      OriginalGriffO 1 Reply Last reply
      0
      • R Roger Wright

        I have no tolerance for errors, so why catch them? They're just going to piss me off, and life has enough aggravations. A simple popup that says, "You screwed up; I'm formatting your C: drive" is usually sufficient to prevent future problems.

        Will Rogers never met me.

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #12

        ...only if you make sure to hide the "Cancel" button. "OK" and "OK, sure - go ahead" should be enough.

        Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        R 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          ...only if you make sure to hide the "Cancel" button. "OK" and "OK, sure - go ahead" should be enough.

          Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

          R Offline
          R Offline
          Roger Wright
          wrote on last edited by
          #13

          I've always considered 'Cancel' and 'Back' buttons to be sops for the weak-minded. In order to assist my users in growing a pair and becoming more decisive, I always leave them out of the dialog. It's my plain duty...

          Will Rogers never met me.

          OriginalGriffO 1 Reply Last reply
          0
          • R Roger Wright

            I've always considered 'Cancel' and 'Back' buttons to be sops for the weak-minded. In order to assist my users in growing a pair and becoming more decisive, I always leave them out of the dialog. It's my plain duty...

            Will Rogers never met me.

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #14

            It's worth taunting them though - A "NO! For Gods sake, NO! STOP!" button is a good idea, provided it is permanently disabled.

            Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            1 Reply Last reply
            0
            • L Lutoslaw

              What are your error flags: optimistic or perssimistic? How do you code:

              boolean success = false;
              try {
              // ...
              success = true;
              } catch (Exception ex) {
              // ...
              }
              return success;

              or

              boolean success = true;
              try {
              // ...

              } catch (Exception ex) {
              success = false;
              // ...
              }
              return success;

              ? Just curious. ;)

              Greetings - Jacek

              J Offline
              J Offline
              Joan M
              wrote on last edited by
              #15

              Typically I use the error point of view... I prefer to stop the program / action if something unhandled has happened. Of course I program machines and it can be dangerous to move something in an unhandled way...

              [www.tamautomation.com] Robots, CNC and PLC machines for grinding and polishing.

              https://www.robotecnik.com freelance robots, PLC and CNC programmer.

              1 Reply Last reply
              0
              • L Lutoslaw

                What are your error flags: optimistic or perssimistic? How do you code:

                boolean success = false;
                try {
                // ...
                success = true;
                } catch (Exception ex) {
                // ...
                }
                return success;

                or

                boolean success = true;
                try {
                // ...

                } catch (Exception ex) {
                success = false;
                // ...
                }
                return success;

                ? Just curious. ;)

                Greetings - Jacek

                C Offline
                C Offline
                Chris Maunder
                wrote on last edited by
                #16

                Success is only achieved after you've successfully completed a task. So: boolean success = false;

                cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                P L 2 Replies Last reply
                0
                • L Lutoslaw

                  What are your error flags: optimistic or perssimistic? How do you code:

                  boolean success = false;
                  try {
                  // ...
                  success = true;
                  } catch (Exception ex) {
                  // ...
                  }
                  return success;

                  or

                  boolean success = true;
                  try {
                  // ...

                  } catch (Exception ex) {
                  success = false;
                  // ...
                  }
                  return success;

                  ? Just curious. ;)

                  Greetings - Jacek

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #17

                  I'm with Chris on this one. False unless the process completes and passes all tests. That way, I'm not enumerating badness missing a test or piece that wasn't in the design.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak

                  P 1 Reply Last reply
                  0
                  • L Lutoslaw

                    What are your error flags: optimistic or perssimistic? How do you code:

                    boolean success = false;
                    try {
                    // ...
                    success = true;
                    } catch (Exception ex) {
                    // ...
                    }
                    return success;

                    or

                    boolean success = true;
                    try {
                    // ...

                    } catch (Exception ex) {
                    success = false;
                    // ...
                    }
                    return success;

                    ? Just curious. ;)

                    Greetings - Jacek

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

                    It depends on the situation. Each is better suited to different scenarios so you shouldn't code it one way all the time.

                    1 Reply Last reply
                    0
                    • C Chris Maunder

                      Success is only achieved after you've successfully completed a task. So: boolean success = false;

                      cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                      P Offline
                      P Offline
                      Paul Conrad
                      wrote on last edited by
                      #19

                      :thumbsup: This is the very idea that I teach my students in any of the programming courses I teach.

                      "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                      1 Reply Last reply
                      0
                      • D Dave Kreskowiak

                        I'm with Chris on this one. False unless the process completes and passes all tests. That way, I'm not enumerating badness missing a test or piece that wasn't in the design.

                        A guide to posting questions on CodeProject[^]
                        Dave Kreskowiak

                        P Offline
                        P Offline
                        Paul Conrad
                        wrote on last edited by
                        #20

                        Dave Kreskowiak wrote:

                        not enumerating badness missing a test or piece that wasn't in the design

                        Yes. It does make testing easier, and gives more assurance that proof of concept that the code is well designed.

                        "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                        1 Reply Last reply
                        0
                        • C Chris Maunder

                          Success is only achieved after you've successfully completed a task. So: boolean success = false;

                          cheers, Chris Maunder The Code Project | Co-founder Microsoft C++ MVP

                          L Offline
                          L Offline
                          Lutoslaw
                          wrote on last edited by
                          #21

                          Agreed. But that "boolean success = false;" at the very beginning of a method looks so sad... :((

                          Greetings - Jacek

                          P 1 Reply Last reply
                          0
                          • L Lutoslaw

                            Agreed. But that "boolean success = false;" at the very beginning of a method looks so sad... :((

                            Greetings - Jacek

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

                            Which is why it should be named result.

                            L 1 Reply Last reply
                            0
                            • P PIEBALDconsult

                              Which is why it should be named result.

                              L Offline
                              L Offline
                              Lutoslaw
                              wrote on last edited by
                              #23

                              PIEBALDconsult wrote:

                              Which is why it should be named result.

                              Where result says whether it is going to rain on wensday? Or that user is pregnant? Or maybe... ekhm, nevermind. :zzz:

                              Greetings - Jacek

                              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