1 2 3 4 5 Previous Next 70 Replies Latest reply on Mar 10, 2010 6:33 PM by 796440 Go to original post
      • 45. Re: Ternary operator
        796440
        jduprez wrote:
        Second, if a method nevertheless both has a side effect and returns a result, disregarding that latter may be an oversight merely than a deliberate choice.
        There's only so much the compiler can expect us to protect us from ourselves. I for one am glad I don't have to clutter my code with stuff like:
        boolean ignored = list.add(foo);
        StringBuffer ignored = sb.append("abc");
        • 46. Re: Ternary operator
          jduprez
          jschell wrote:
          ++++;
          Thanks for comforting.
          But I know why you came to this thread :o)
          • 47. Re: Ternary operator
            843807
            jverd wrote:
            atch7 wrote:
            It's another of java's illogicalities. In my code mentioned in original post if I have to use a ternary operator to do what I want it to do:
            1. I have to make sure that I'm using methods which return some value different than void and
            2. I have to assign it to some completely unnecessary variable.

            So following this logic I can't say:

            int == 0 ? setVisible(true) : setVisible(false);

            but providing that I have method definition:

            int setSelectable(int a)
            {
            //do something
            //and just for sake of making this to work I have to have return statement
            return a;
            }

            having that now I can write

            int a = i == 0 ? setSelectable(1) : setSelectable(0);

            Pathetic, illogical and completely java like behavior.
            This is the rant of a child who's bitter because the world doesn't work the way he assumes it should.

            The behavior only seems illogical to you because you have the mistaken assumption that the purpose of the operator is to be an equivalent to an if statement. That's not its purpose.
            Quote from sun's website:
            "Another conditional operator is ?:, which can be thought of as shorthand for an if-then-else statement"
            So who is wrong you or they?
            Here you have link if you'd like to check it:
            "http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op2.html"
            • 48. Re: Ternary operator
              843807
              jverd wrote:
              atch7 wrote:
              kevinaworkman wrote:
              atch7 wrote:
              Another thing is that it is an operator just like '+++' or '-' and as long as it have correct operands on each of its side it should work without making any problems.
              What? Why? Says who? This doesn't make any sense.
              Exactly. Who and What. As Java never has been standardized and for some strange reasons it doesn't look like it will be in near by future.
              What do you even mean by this? In what way is Java "not standardized" that C++ is?
              Are you really serious asking this question? Java isn't standardized, C++ is. Nothing more to say. If you don't understand what does it mean - STFW;
              • 49. Re: Ternary operator
                843807
                jverd wrote:
                atch7 wrote:
                Another thing is that it is an operator just like '+' or '-' and as long as it have correct operands on each of its side it should work without making any problems.
                And that's exactly what it does.

                What you're attempting is the equivalent of this:
                public class Foo() {
                public void x() {}
                
                public void y() {}
                }
                
                ...
                
                Foo foo = new Foo();
                int z = foo.x() + foo.y();
                No, it is not equivalent to this.
                • 50. Re: Ternary operator
                  843807
                  jverd wrote:
                  atch7 wrote:
                  jduprez wrote:
                  AFAIC, I'm happy that you're giving your point of view about your personal preference, or style. But I side with the others that there is nothing illogical in this design choice of the Java language per se (what is somewhat illogical is that the way return values can be silently ignored is not consistent with this).
                  1+1
                  Because what is java supposed to do with it?
                  Well, just execute it
                  Execute what? an operation that has no side-effect whatsoever?
                  Well, maybe I would like to check how fast adding is executed without assigning?
                  So, the language should support useless syntax in order to enable you to do a useless benchmark?
                  So if the language doesn't support useless syntax why on the other hand I'm allowed to write something like this:
                  void f()
                  {}
                  while(true)
                  {
                  f();
                  }
                  I'm sure that you have java like reasoning for this behavior as well. And I'm also sure that you don't see anything wrong that java allows this syntax but forbids the former.
                  • 51. Re: Ternary operator
                    843807
                    jschell wrote:
                    atch7 wrote:
                    I want to say that I'm not trolling. Just because I have objection to some constructs being preferred in java and slightly criticizing it for being illogical sometimes it doesn't mean that I'm trolling. Secondly, guys with full respect but how unsure you have to be if on the slightest criticism you react like little weak boys from prime school. I program mostly in C++ and I love this language but I also now that there are some bad things in C++. If someone would pointed out to me that, I definitely wouldn't get agitated or feel attacked by this person, especially if that person would explain why he/she think so. But you guys have some issues, probably because in the deepest of your heart, you know that java is just mediocre, quite weak language with many unsolved and unsolvable problems. I pity guys like you, who can't take bit of criticism.
                    So if you do a code review in C++ an you see the following statement you pass on it without comment?

                    i+1;

                    And you expect those that review your code to do the same?

                    Having previously programmed in C++ for years and C before that I can assure you that if I was reviewing your code and the above was in your code I would file a bug on it.

                    And I would file a bug if you used the ternary operator the way that you want to as well. In that case it is much better to use an if.

                    The fact that both C++ and java both allow the following syntax means absolutely nothing to me in terms of writing "logical" code because in both languages the author is wrong to attempt it and further doesn't know how to write maintainale code.

                    i = i++;
                    As a matter of fact this kind of way is used all the time in C++ code and it's even preferred to if/then/else structure. So you would be entirely wrong if you would file it as a bug. Obviously you prefer to drive fiesta to ferrari.
                    • 52. Re: Ternary operator
                      843807
                      jschell wrote:
                      atch7 wrote:
                      I want to say that I'm not trolling. Just because I have objection to some constructs being preferred in java and slightly criticizing it for being illogical sometimes it doesn't mean that I'm trolling. Secondly, guys with full respect but how unsure you have to be if on the slightest criticism you react like little weak boys from prime school. I program mostly in C++ and I love this language but I also now that there are some bad things in C++. If someone would pointed out to me that, I definitely wouldn't get agitated or feel attacked by this person, especially if that person would explain why he/she think so. But you guys have some issues, probably because in the deepest of your heart, you know that java is just mediocre, quite weak language with many unsolved and unsolvable problems. I pity guys like you, who can't take bit of criticism.
                      So if you do a code review in C++ an you see the following statement you pass on it without comment?

                      i+1;

                      And you expect those that review your code to do the same?

                      And at what point did I say anything about reviewing code? I would only like to have the freedom to write what I want as long as syntax is correct. And if I see something that is illogical I just say so. And just because Sun says that return value of ?: has to be assigned somewhere it doesn't necessary mean that it does make sense.
                      • 53. Re: Ternary operator
                        843807
                        jschell wrote:
                        atch7 wrote:
                        jduprez wrote:
                        Your example is another sort of Java's stronger checking, I see nothing awkward in it, but my mind is sure formatted after working with Java for a while (with a C >background mind you, and I'm happy I made the shift).
                        I'm sorry but if someone tells me that s/he is happy after switching from C/C++ to Java/C# etc. I just feel like they choosing easy, safe ride which is unfortunately also very boring and without any excitement (just like driving ford fiesta) on the other hand, yes, driving ferrari (read C/C++) you may injure yourself or even die, but the emotions and power is something that is worth dying for. Thats why I prefer to drive ferrari to ford fiesta.
                        I suspect that you would also attempt to go four wheeling in your ferrari while pulling a horse trailer.

                        Others might prefer to pick a vehicle based on the needs of the journey rather than blindly insisting on a single one.

                        Not to mention of course that there are probably many more people that can claim that they can drive a ferrari versus those that can actually do so in a way that actually uses the power appropriately.
                        Following your reasoning you would prefer pulling a horse trailer with ford fiesta. Bravo. Good choice.
                        And with Ferrari at least I have a chance (if I'm not good enough) to experience something and at least I'm given a chance to improve my style and techniques and I'm free with my choice of thinking.What can you expect from driving a fiesta? I'm not constrained to one and only correct way of thinking (designed by Sun). I can drive slow, I can drive fast - I decide, well you don't have this choice driving fiesta.
                        • 54. Re: Ternary operator
                          jduprez
                          So if the language doesn't support useless syntax why on the other hand I'm allowed to write something like this:
                          void f()
                          {}
                          while(true)
                          {
                          f();
                          }
                          I'm sure that you have java like reasoning for this behavior as well. And I'm also sure that you don't see anything wrong that java allows this syntax but forbids the former.
                          My brain has probably been manipulated by too many years of Java propaganda. But yes there is a good reason: a subclass can override method f to do something observable.
                          • 55. Re: Ternary operator
                            jduprez
                            Has it been mentioned already that this whole discussion has nothing to do with Swing itself?
                            And that the very act of posting this question in the Swing forum says a lot about the poster's understanding of the language?
                            • 56. Re: Ternary operator
                              843807
                              jduprez wrote:
                              Has it been mentioned already that this whole discussion has nothing to do with Swing itself?
                              How else could we get yawmark, jverd, and jschell to come slumming here?
                              And that the very act of posting this question in the Swing forum says a lot about the poster's understanding of the language?
                              I dismissed the OP as a troll a long time ago.
                              • 57. Re: Ternary operator
                                843807
                                You've convinced me. I'm abandoning this useless language forthwith. What a waste of my career this has been. Anybody know where I can buy a sheep farm?
                                • 58. Re: Ternary operator
                                  843807
                                  georgemc wrote:
                                  You've convinced me. I'm abandoning this useless language forthwith. What a waste of my career this has been. Anybody know where I can buy a sheep farm?
                                  A sheep farm? Your Ferrari will get soooooo dirty.
                                  • 59. Re: Ternary operator
                                    jschellSomeoneStoleMyAlias
                                    atch7 wrote:
                                    The behavior only seems illogical to you because you have the mistaken assumption that the purpose of the operator is to be an equivalent to an if statement. That's not its purpose.
                                    Quote from sun's website:
                                    "Another conditional operator is ?:, which can be thought of as shorthand for an if-then-else statement"
                                    So who is wrong you or they?
                                    Here you have link if you'd like to check it:
                                    "http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op2.html"
                                    The tutorial is not an authorative source - not even close.