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 Offline
    L Offline
    Lutoslaw
    wrote on last edited by
    #1

    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 M Steve EcholsS OriginalGriffO T 11 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
      Dr Walt Fair PE
      wrote on last edited by
      #2

      Why would I expect an error? I'd just pop up a message saying "The luser obviously screwed up."

      CQ de W5ALT

      Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

      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

        M Offline
        M Offline
        mav northwind
        wrote on last edited by
        #3

        The glass is twice the size needed. I've used such constructs in the past, but meanwhile mostly avoid catching all exceptions and just returning true/false because in order to fix the problem you usually need to know what the exception was. Otherwise you can only say "something went wrong", without any further information about the where and why.

        Regards, mav -- Black holes are the places where God divided by 0...

        L 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

          Steve EcholsS Offline
          Steve EcholsS Offline
          Steve Echols
          wrote on last edited by
          #4

          exit(0);


          - S 50 cups of coffee and you know it's on! Code, follow, or get out of the way.

          • S
            50 cups of coffee and you know it's on!
            Code, follow, or get out of the way.
          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

            OriginalGriffO Online
            OriginalGriffO Online
            OriginalGriff
            wrote on last edited by
            #5

            Depends on what I am doing: is success to be expected, or failure?

            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

              T Offline
              T Offline
              taha bahraminezhad Jooneghani
              wrote on last edited by
              #6

              I don't look at the success like a boolean! There is a Mystery in this word! if you believe in your self its always True! but if you get doubt in your self just a little or disappointed , I things get change!

              OriginalGriffO 1 Reply Last reply
              0
              • T taha bahraminezhad Jooneghani

                I don't look at the success like a boolean! There is a Mystery in this word! if you believe in your self its always True! but if you get doubt in your self just a little or disappointed , I things get change!

                OriginalGriffO Online
                OriginalGriffO Online
                OriginalGriff
                wrote on last edited by
                #7

                Oh Boy! Have you got a major disappointment coming... Nothing in life works all the time. And if you aren't ready for when it doesn't, then it will hit you like a tonne of bricks.

                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

                T 1 Reply Last reply
                0
                • M mav northwind

                  The glass is twice the size needed. I've used such constructs in the past, but meanwhile mostly avoid catching all exceptions and just returning true/false because in order to fix the problem you usually need to know what the exception was. Otherwise you can only say "something went wrong", without any further information about the where and why.

                  Regards, mav -- Black holes are the places where God divided by 0...

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

                  mav.northwind wrote:

                  Otherwise you can only say "something went wrong", without any further information about the where and why.

                  Yes, indeed. I was responsible for keeping such a horrible application alive. When an exception occured, it was either swept under the rug in an empty catch block or it sent off a mail to me with 'An error has just occured'. Sometimes I got hundreds of those mails, all with that braindead message. How hard can it be to think of includng the message and perhaps the stack trace in that mail? For this and many other horrors this man has commited, I would just love to see him tarred, feathered, first thrown out of the guild and then thrown out of the town. :)

                  At least artificial intelligence already is superior to natural stupidity

                  1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    Oh Boy! Have you got a major disappointment coming... Nothing in life works all the time. And if you aren't ready for when it doesn't, then it will hit you like a tonne of bricks.

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

                    T Offline
                    T Offline
                    taha bahraminezhad Jooneghani
                    wrote on last edited by
                    #9

                    but the important part of that is: "some times life hit your head with a break , don't lose faith" steve jobs, stanford university!

                    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

                      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 Online
                          OriginalGriffO Online
                          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 Online
                              OriginalGriffO Online
                              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
                                          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