Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #3941 > unrolled thread

Java puzzler

Started byGábor Bakos <aborgabor@gmail.com>
First post2011-05-10 16:36 -0700
Last post2011-05-11 21:49 -0700
Articles 12 — 6 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  Java puzzler Gábor Bakos <aborgabor@gmail.com> - 2011-05-10 16:36 -0700
    Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-10 20:16 -0400
    Re: Java puzzler Roedy Green <see_website@mindprod.com.invalid> - 2011-05-11 03:03 -0700
      Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-11 09:07 -0400
        Re: Java puzzler markspace <-@.> - 2011-05-11 08:10 -0700
          Re: Java puzzler Roedy Green <see_website@mindprod.com.invalid> - 2011-05-11 22:02 -0700
            Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-12 08:35 -0400
              Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 08:13 -0700
                Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-12 12:11 -0400
                  Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 18:28 -0700
            Re: Java puzzler Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-05-12 10:14 -0400
        Re: Java puzzler Roedy Green <see_website@mindprod.com.invalid> - 2011-05-11 21:49 -0700

#3941 — Java puzzler

FromGábor Bakos <aborgabor@gmail.com>
Date2011-05-10 16:36 -0700
SubjectJava puzzler
Message-ID<871987d9-1034-441d-9d33-b2dd6b4de234@glegroupsg2000goo.googlegroups.com>
Hello,

   Sorry if this is already a known behaviour, but first I found this really strange:
int x = 0;
x += 0.5;
What does the code snippet above do:
  - compile and run without error result is
      - 0
      - 1
      - depends on the strict or nonstrict computation
  - compile and ArithmeticException is thrown
  - does not compile (Type mismatch: cannot convert from double to int)
For those who want to know the answer check this[1] and this[2].
Bests, gabor

[1]: http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.26.2
[2]: http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.3

[toc] | [next] | [standalone]


#3942

FromLew <noone@lewscanon.com>
Date2011-05-10 20:16 -0400
Message-ID<iqckg3$35e$1@news.albasani.net>
In reply to#3941
On 05/10/2011 07:36 PM, Gábor Bakos wrote:
> Hello,
>
>     Sorry if this is already a known behaviour, but first I found this really strange:
> int x = 0;
> x += 0.5;
> What does the code snippet above do:
>    - compile and run without error result is
>        - 0
>        - 1
>        - depends on the strict or nonstrict computation
>    - compile and ArithmeticException is thrown
>    - does not compile (Type mismatch: cannot convert from double to int)

What happened for you when you tried it?

> For those who want to know the answer check this[1] and this[2].
> ...
> [1]: http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.26.2
> [2]: http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.3

What precisely did you find strange?

<sscce source="com/lewscanon/eegee/Conversioneer.java" >
package com.lewscanon.eegee;
/**
  * Conversioneer.
  */
public class Conversioneer
{
   /**
    * main.
    * @param args String []
    */
   public static void main( String [] args )
   {
     int x = 0;
     x += 0.5;
     System.out.println( "x = "+ x );
   }
}
</sscce>

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

[toc] | [prev] | [next] | [standalone]


#3959

FromRoedy Green <see_website@mindprod.com.invalid>
Date2011-05-11 03:03 -0700
Message-ID<jhnks6dpk9bjoh7q2gougt0m6ove9etbuq@4ax.com>
In reply to#3941
On Tue, 10 May 2011 16:36:39 -0700 (PDT), Gábor Bakos
<aborgabor@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>int x = 0;
>x += 0.5;

If it is not illegal syntax, it should be. One of the language lawyers
like Lew or Patricia will likely do a Delphi-style oracle reading on
the JLS and tell you what it is supposed to do.  If it is not what it
is doing, prepare an SSCCE and submit the bug.

See http://mindprod.com/jgloss/sscce.html
http://mindprod.com/jgloss/bug.html
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
How long did it take after the car was invented before owners understood 
cars would not work unless you regularly changed the oil and the tires?
We have gone 33 years and still it is rare to uncover a user who 
understands computers don't work without regular backups.

[toc] | [prev] | [next] | [standalone]


#3970

FromLew <noone@lewscanon.com>
Date2011-05-11 09:07 -0400
Message-ID<iqe1m8$g5e$1@news.albasani.net>
In reply to#3959
On 05/11/2011 06:03 AM, Roedy Green wrote:
> On Tue, 10 May 2011 16:36:39 -0700 (PDT), Gábor Bakos
> <aborgabor@gmail.com>  wrote, quoted or indirectly quoted someone who
> said :
>
>> int x = 0;
>> x += 0.5;
>
> If it is not illegal syntax, it should be. One of the language lawyers

Utter nonsense.  And you presume to give advice to Java programmers?

> like Lew or Patricia will likely do a Delphi-style oracle reading on
> the JLS and tell you what it is supposed to do.  If it is not what it
> is doing, prepare an SSCCE and submit the bug.
>
> See http://mindprod.com/jgloss/sscce.html
> http://mindprod.com/jgloss/bug.html

I already prepared an SSCCE half a day prior to your post, which youy 
apparently did not notice.  The OP already cited relevant sections of the JLS, 
which you apparently did not notice.

Is there something wrong with being well-educated on the rules of the Java 
language when programming Java code, as you snarkily imply?

There is no bug to submit, so that was useless advice.

The OP hasn't even explained what they dream a problem to be, which you 
apparently did not notice.

You are doing a HUGE disservice to newbies by indicating that it is not good 
to be intimately familiar with the programming rules by which one is working. 
  I thought you were all about helping the programmer, but apparently not. 
You should stop preaching the virtues of ignorance, Roedy.

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

[toc] | [prev] | [next] | [standalone]


#3976

Frommarkspace <-@.>
Date2011-05-11 08:10 -0700
Message-ID<iqe8sr$5p1$1@dont-email.me>
In reply to#3970
On 5/11/2011 6:07 AM, Lew wrote:

> Is there something wrong with being well-educated on the rules of the
> Java language when programming Java code, as you snarkily imply?


Actually I took that as a compliment.  He's saying other people know the 
language better than him.

I do agree that there's nothing wrong with trying to learn the language 
better.  Patricia's post explained the reason for (or at least gave a 
rationalization for) this oddity in the language.  Every once in a while 
I find those and have to dial them into my brain.  It's not hard to do, 
and everyone should at least try.

I figure, once I do finally learn everything there is to know, they'll 
probably chuck Java and start on something new....

[toc] | [prev] | [next] | [standalone]


#4002

FromRoedy Green <see_website@mindprod.com.invalid>
Date2011-05-11 22:02 -0700
Message-ID<bnpms6lg49p24m2l8taeo51o2pq408uprj@4ax.com>
In reply to#3976
On Wed, 11 May 2011 08:10:16 -0700, markspace <-@.> wrote, quoted or
indirectly quoted someone who said :

>Actually I took that as a compliment.  He's saying other people know the 
>language better than him.

Of course. Surely Lew knows the high esteem I hold Patricia Shanahan.
See http://mindprod.com/jgloss/who.html

I mentioned Lew in the same sentence. That is high praise.

When I read the JLS, it always seems to me extremely ambiguous.  I
would never trust my interpretation.  Others seem to understand its
language patterns more deeply and with confidence divine what it
means.  It may be that they have done more experiments and have at a
gut level learned the sort of language Mr. Gosling uses.

To me it seems highly reckless to trust my own interpretation of the
JLS.  It must be supplemented with some experiments for verification. 

I have learned that people like Patricia and Lew can make
pronouncements apparently based on nothing but the JLS that are
remarkably accurate. To me this seems an almost magical ability, like
being able to see in the pitch dark.

Lew thinks everyone should have his skill and are just being lazy if
they don't.  I think his ability is quite rare.

The basic disagreement is Lew wants people to attempt to understand
the JLS on a routine basis.  In contrast, I don't want people to trust
their interpretations.  They should do experiments too, and/or consult
people with high skill.

Interpreting the JLS is a special skill quite different from
programming.
-- 
Roedy Green Canadian Mind Products
http://mindprod.com
How long did it take after the car was invented before owners understood 
cars would not work unless you regularly changed the oil and the tires?
We have gone 33 years and still it is rare to uncover a user who 
understands computers don't work without regular backups.

[toc] | [prev] | [next] | [standalone]


#4007

FromLew <noone@lewscanon.com>
Date2011-05-12 08:35 -0400
Message-ID<iqgk77$bl9$1@news.albasani.net>
In reply to#4002
On 05/12/2011 01:02 AM, Roedy Green wrote:
> On Wed, 11 May 2011 08:10:16 -0700, markspace<-@.>  wrote, quoted or
> indirectly quoted someone who said :
>
>> Actually I took that as a compliment.  He's saying other people know the
>> language better than him.
>
> Of course. Surely Lew knows the high esteem I hold Patricia Shanahan.
> See http://mindprod.com/jgloss/who.html
>
> I mentioned Lew in the same sentence. That is high praise.
>
> When I read the JLS, it always seems to me extremely ambiguous.  I
> would never trust my interpretation.  Others seem to understand its
> language patterns more deeply and with confidence divine what it
> means.  It may be that they have done more experiments and have at a
> gut level learned the sort of language Mr. Gosling uses.
>
> To me it seems highly reckless to trust my own interpretation of the
> JLS.  It must be supplemented with some experiments for verification.
>
> I have learned that people like Patricia and Lew can make
> pronouncements apparently based on nothing but the JLS that are
> remarkably accurate. To me this seems an almost magical ability, like
> being able to see in the pitch dark.
>
> Lew thinks everyone should have his skill and are just being lazy if
> they don't.  I think his ability is quite rare.
>
> The basic disagreement is Lew wants people to attempt to understand
> the JLS on a routine basis.  In contrast, I don't want people to trust
> their interpretations.  They should do experiments too, and/or consult
> people with high skill.
>
> Interpreting the JLS is a special skill quite different from
> programming.

If you cannot even TRY to understand the JLS, you should not program in Java.

The JLS is the ultimate authority on the Java language.  You keep suggesting 
that a person shouldn't even /attempt/ to understand it unless you have a rare 
or special skill to read the specification.  Bullshit.

You think I have a special skill at reading it.  Sure - it's called "spending 
time reading, studying and thinking about the JLS".  Anyone who can program 
can do that.  Anyone who won't do that shouldn't program.

Even you, Roedy, can understand the JLS if you work at it.  I'm fairly 
confident that I'm not all that much smarter than you are.

I do NOT suggest that one use the JLS as one's only source of information. 
That would be stupid.  I urge all Java programmers to spend the time and 
effort to understand the JLS, using other works to deepen your understanding, 
show how to apply it, and explain rationales.

Telling yourself that Lew has a "magical ability" is a foolish fiction.  I 
just am not lazy about the JLS.  Maybe Patricia has one; I can believe that. 
Not me.  I'm smart, but the key is I'M AT LEAST TRYING!

Roedy, if you cannot understand the JLS you should take down your Java advice 
from mindprod.com until you do.

OK, I'm not serious, since your advice is 99% fabulous (and your picture 
reveals that you are a surprisingly handsome man, BTW), but really, Roedy, you 
do yourself a disservice let alone everyone else.  Sure, the JLS can be opaque 
in parts in its efforts at precision.  But keep at it - it is, after all, the 
only and ultimate source of Java language truth.

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

[toc] | [prev] | [next] | [standalone]


#4013

FromPatricia Shanahan <pats@acm.org>
Date2011-05-12 08:13 -0700
Message-ID<Vcudndo9OYWPZFbQnZ2dnUVZ_rKdnZ2d@earthlink.com>
In reply to#4007
On 5/12/2011 5:35 AM, Lew wrote:
...
> Telling yourself that Lew has a "magical ability" is a foolish fiction.
> I just am not lazy about the JLS. Maybe Patricia has one; I can believe
> that. Not me. I'm smart, but the key is I'M AT LEAST TRYING!

I'm not a useful data point for this discussion. The writers of the JLS
benefited from the multiple decades of language specification writing
the preceded it. For example, the syntax notation is a descendant of the
BNF notation in the Algol 60 report.

Before I started learning Java I had a combination of formal education
and practical, on-the-job experience in reading and applying programming
language specifications. When I started reading the JLS it was just a
new instance of a familiar type of document.

There is no way for any of us, myself included, to know how easy or
difficult I would have found the JLS if I had read it without that
background.

Patricia

[toc] | [prev] | [next] | [standalone]


#4014

FromLew <noone@lewscanon.com>
Date2011-05-12 12:11 -0400
Message-ID<iqh0qv$94l$1@news.albasani.net>
In reply to#4013
On 05/12/2011 11:13 AM, Patricia Shanahan wrote:
> On 5/12/2011 5:35 AM, Lew wrote:
> ...
>> Telling yourself that Lew has a "magical ability" is a foolish fiction.
>> I just am not lazy about the JLS. Maybe Patricia has one; I can believe
>> that. Not me. I'm smart, but the key is I'M AT LEAST TRYING!
>
> I'm not a useful data point for this discussion. The writers of the JLS
> benefited from the multiple decades of language specification writing
> the preceded it. For example, the syntax notation is a descendant of the
> BNF notation in the Algol 60 report.
>
> Before I started learning Java I had a combination of formal education
> and practical, on-the-job experience in reading and applying programming
> language specifications. When I started reading the JLS it was just a
> new instance of a familiar type of document.
>
> There is no way for any of us, myself included, to know how easy or
> difficult I would have found the JLS if I had read it without that
> background.

Your experience still provides a useful example.

Perhaps you or I do have a special skill at reading specifications.  If so, 
it's the special skill that distinguishes better programmers from worse ones, 
and a very powerful if not actually requisite skill.

Or perhaps we have approximately the same aptitude as nearly everyone who 
participates in this Usenet forum.

Either way, both of us - you through more years of formal education than I, 
but both of us through diligent ongoing study over years - have applied 
ourselves to the skill of reading and being clear about specifications, 
language or otherwise.  As Thomas Edison said, "Genius is 1% inspiration and 
99% perspiration."  I aver that it's the study and effort that pays off here, 
not some mysterious brain power that Roedy or most people lack.

If you who wish to (advise those who) program in Java do lack the skill to 
comprehend the JLS, or any other specification, even after diligent study and 
great effort, you may be like the tone-deaf person with a sore throat who 
hopes to audition for /American Idol/ - a touch underqualified for the job. 
But bless your heart for trying.

If you don't even try, however, then you should at least practice this phrase 
for your compatible profession:  "Would you like fries with that?"

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

[toc] | [prev] | [next] | [standalone]


#4034

FromPatricia Shanahan <pats@acm.org>
Date2011-05-12 18:28 -0700
Message-ID<SL2dnTPXp_2sFFHQnZ2dnUVZ_hWdnZ2d@earthlink.com>
In reply to#4014
On 5/12/2011 9:11 AM, Lew wrote:
> On 05/12/2011 11:13 AM, Patricia Shanahan wrote:
>> On 5/12/2011 5:35 AM, Lew wrote:
>> ...
>>> Telling yourself that Lew has a "magical ability" is a foolish fiction.
>>> I just am not lazy about the JLS. Maybe Patricia has one; I can believe
>>> that. Not me. I'm smart, but the key is I'M AT LEAST TRYING!
>>
>> I'm not a useful data point for this discussion. The writers of the JLS
>> benefited from the multiple decades of language specification writing
>> the preceded it. For example, the syntax notation is a descendant of the
>> BNF notation in the Algol 60 report.
>>
>> Before I started learning Java I had a combination of formal education
>> and practical, on-the-job experience in reading and applying programming
>> language specifications. When I started reading the JLS it was just a
>> new instance of a familiar type of document.
>>
>> There is no way for any of us, myself included, to know how easy or
>> difficult I would have found the JLS if I had read it without that
>> background.
>
> Your experience still provides a useful example.
>
> Perhaps you or I do have a special skill at reading specifications. If
> so, it's the special skill that distinguishes better programmers from
> worse ones, and a very powerful if not actually requisite skill.

I've known many really excellent programmers who never read language
specifications. They worked from a combination of good secondary
sources, experimentation, and asking questions when in doubt.

The only time I've felt programming language specification reading was a
really important skill was when I was project leader for compilers at
Celerity Computing, and had to make decisions about what features to
implement and how to implement them.

Patricia

[toc] | [prev] | [next] | [standalone]


#4009

FromJoshua Cranmer <Pidgeot18@verizon.invalid>
Date2011-05-12 10:14 -0400
Message-ID<iqgpvs$3bv$1@dont-email.me>
In reply to#4002
On 05/12/2011 01:02 AM, Roedy Green wrote:
> When I read the JLS, it always seems to me extremely ambiguous.  I
> would never trust my interpretation.  Others seem to understand its
> language patterns more deeply and with confidence divine what it
> means.  It may be that they have done more experiments and have at a
> gut level learned the sort of language Mr. Gosling uses.

The JLS is quite rigidly specified, at least in comparison to other 
specifications I have read (e.g., CSS). It is also well-organized 
compared to, say, C++, where I have to spend a lot of time trying to 
figure out which clause covers the question I have (I want to know about 
something involving default initialization of templatized POD-classes... 
only could be in about 5 sections).

> Interpreting the JLS is a special skill quite different from
> programming.

Much of the programming I have done has required me to read, write, 
comprehend, synthesize, and implement specifications, be it as long and 
dense as that for a programming language, as underspecified as an old 
RFC that predates most concerns for i18n, as formal as the formal 
project specification, or as informal as the API documentation. 
Specifications like the JLS are merely API documentation at another 
level: every token is an input to the function "Compile and run me!" 
provided by javac and java, with the JLS merely being a thorough 
exposition on the wonderous ways that tokens interact with each other.

In that vein, every programmer should have the skills to read, 
comprehend, and interpret the JLS, since they should have the same 
skills to read, comprehend, and interpret API documentation.

-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth

[toc] | [prev] | [next] | [standalone]


#3999

FromRoedy Green <see_website@mindprod.com.invalid>
Date2011-05-11 21:49 -0700
Message-ID<pdpms6p82qul2pn3g6gl9l9ueg147jspds@4ax.com>
In reply to#3970
On Wed, 11 May 2011 09:07:21 -0400, Lew <noone@lewscanon.com> wrote,
quoted or indirectly quoted someone who said :

>Is there something wrong with being well-educated on the rules of the Java 
>language when programming Java code, as you snarkily imply?


Everything I say you twist into some sort of crime.  You single
handedly cut the traffic in the Java news groups with your personal
attacks on everyone. You have them afraid to speak.  You bawl people
out for asking questions. You bawl people out for answering. Just
stick to the facts and stop commenting on motivations.

You normally nit pick just so you can find some excuse to put people
down, so I don't usually read your posts. You are knowledgeable but a
royal PITA.


-- 
Roedy Green Canadian Mind Products
http://mindprod.com
How long did it take after the car was invented before owners understood 
cars would not work unless you regularly changed the oil and the tires?
We have gone 33 years and still it is rare to uncover a user who 
understands computers don't work without regular backups.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web