Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Test yourself now! (in idle banter)

18 views
Skip to first unread message
Message has been deleted

Mike Schilling

unread,
Aug 23, 2008, 12:24:52 PM8/23/08
to
Stefan Ram wrote:
> I just made this up as a time filler:
>
> Can you see anything suspicious in the following
> Java source code without pasting it into an IDE
> or trying to compile it?
>
> Code starts after this colon:
>
> /*
>
> Every algorithm might use
> - any other algorithm (in this sense and also in this class)
> - the types int, double, boolean
> - type conversions between int and double
> - arithmetic operations +-*/%
> - boolean-arithmetic operations < > <= >= != ==
> - boolean operations & | !
> - if, while(), restricted switches, ?:
> - all interfaces
>
> An algorithm might not explicitly refer to specific classes,
> arrays or other types.
>
> */
>
> public class algorithm { /* todo */ }

Nice puzzle. Very mysterious until you spot it.


Peter Duniho

unread,
Aug 23, 2008, 12:43:37 PM8/23/08
to
On Sat, 23 Aug 2008 09:21:11 -0700, Stefan Ram <r...@zedat.fu-berlin.de>
wrote:

> I just made this up as a time filler:

Admit it. This is from a real-world scenario. :p

Joshua Cranmer

unread,
Aug 23, 2008, 12:50:50 PM8/23/08
to
Stefan Ram wrote:
> I just made this up as a time filler:
>
> Can you see anything suspicious in the following
> Java source code without pasting it into an IDE
> or trying to compile it?
>
> Code starts after this colon:

I'll admit I was looking for a feature buried deep in the JLS, only to
discover how mundane the actual error was...

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

Daniele Futtorovic

unread,
Aug 23, 2008, 1:47:08 PM8/23/08
to
On 23/08/2008 18:21, Stefan Ram allegedly wrote:
> I just made this up as a time filler:
>
> Can you see anything suspicious in the following
> Java source code without pasting it into an IDE
> or trying to compile it?

Yeah.

-.-

While we're on this subject -- we aren't really, it's just a figure of
speech --, one of my favourites is the following:


<code>
public class Main {

public static void main(String[] ss){


http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.7
for(int ii = 0; ii < 5; ii++){
System.out.println("README!");
}
}

}
</code>


--
DF.

Daniel Pitts

unread,
Aug 23, 2008, 2:05:18 PM8/23/08
to
Stefan Ram wrote:
> I just made this up as a time filler:
>
> Can you see anything suspicious in the following
> Java source code without pasting it into an IDE
> or trying to compile it?
>
> Code starts after this colon:
>
> /*
>
> Every algorithm might use
> - any other algorithm (in this sense and also in this class)
> - the types int, double, boolean
> - type conversions between int and double
> - arithmetic operations +-*/%
> - boolean-arithmetic operations < > <= >= != ==
> - boolean operations & | !
> - if, while(), restricted switches, ?:
> - all interfaces
>
> An algorithm might not explicitly refer to specific classes,
> arrays or other types.
>
> */
>
> public class algorithm { /* todo */ }
>
Easy, a */ appears in the middle of the comment, oops!

--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Peter Duniho

unread,
Aug 23, 2008, 2:11:34 PM8/23/08
to
On Sat, 23 Aug 2008 11:05:18 -0700, Daniel Pitts
<newsgroup....@virtualinfinity.net> wrote:

> Easy, a [spoiler deleted]

What? No spoiler alert or ROT-13? Tsk, tsk.

Tom Anderson

unread,
Aug 23, 2008, 2:58:35 PM8/23/08
to
On Sat, 23 Aug 2008, Stefan Ram wrote:

> I just made this up as a time filler:
>
> Can you see anything suspicious in the following
> Java source code without pasting it into an IDE
> or trying to compile it?
>
> Code starts after this colon:

Got that in about three seconds - the "after this colon" remark gives it
away immediately!

We had this problem for real at work recently. I was trying to write a
comment explaining that a document will be classified as XHTML if it has a
type matching */xhtml+xml ...

tom

--
Civis Britannicus sum.

Tom Anderson

unread,
Aug 23, 2008, 3:00:32 PM8/23/08
to

Brilliant! I'm going to be using that ASAP - it'll be a nice trick to play
on my pair-programming partner ...

Andreas Leitgeb

unread,
Aug 23, 2008, 6:51:28 PM8/23/08
to
Daniele Futtorovic <da.fut...@laposte.invalid> wrote:
><code>
> public class Main {
> public static void main(String[] ss){
> http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.7
> for(int ii = 0; ii < 5; ii++){
> System.out.println("README!");
break
http;//java.sun.com/docs/books/jls/third_edition/html/statements.html#14.7
> }
> }
> }
></code>

Isn't one request to read something enough ? :-)

Daniele Futtorovic

unread,
Aug 23, 2008, 7:42:15 PM8/23/08
to

Hey, you try to choose a number between zero and forty-two and we'll see
whether you come up one.

--
DF.

Mark Space

unread,
Aug 23, 2008, 9:28:57 PM8/23/08
to

lol. I've actually been bit by a \uxxxx invalid character in a comment
before.

Mark Space

unread,
Aug 23, 2008, 9:49:33 PM8/23/08
to
Daniele Futtorovic wrote:

>
> http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.7
> for(int ii = 0; ii < 5; ii++){
> System.out.println("README!");


See this one I don't get. http: is a label, sure, but why doesn't the
rest fail to parse? The JLS says labels have to be identifiers and this
clearly isn't. The / . and # disqualify it. So I don't get why the
compiler passes it.


JLS says:

Identifier:
IdentifierChars but not a Keyword or BooleanLiteral or
NullLiteral

IdentifierChars:
JavaLetter
IdentifierChars JavaLetterOrDigit

JavaLetter:
any Unicode character that is a Java letter (see below)

JavaLetterOrDigit:
any Unicode character that is a Java letter-or-digit (see

below)

Letters and digits may be drawn from the entire Unicode character set,
which supports most writing scripts in use in the world today, including
the large sets for Chinese, Japanese, and Korean. This allows
programmers to use identifiers in their programs that are written in
their native languages.

A "Java letter" is a character for which the method
Character.isJavaIdentifierStart(int) returns true. A "Java
letter-or-digit" is a character for which the method
Character.isJavaIdentifierPart(int) returns true.

The Java letters include uppercase and lowercase ASCII Latin letters A-Z
(\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons,
the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The
$ character should be used only in mechanically generated source code
or, rarely, to access preexisting names on legacy systems.

The "Java digits" include the ASCII digits 0-9 (\u0030-\u0039).

Arne Vajhøj

unread,
Aug 23, 2008, 9:54:23 PM8/23/08
to
Mark Space wrote:
> Daniele Futtorovic wrote:
>> http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.7
>>
>> for(int ii = 0; ii < 5; ii++){
>> System.out.println("README!");
>
> See this one I don't get. http: is a label, sure, but why doesn't the
> rest fail to parse?

What is the next two characters after colon ?

Arne

Mike Schilling

unread,
Aug 23, 2008, 10:18:39 PM8/23/08
to

Or, to ask it another way, what acts like whitespace but isn't white?


Mark Space

unread,
Aug 23, 2008, 10:43:22 PM8/23/08
to

Oh, right. OK I see it now, thanks guys. :-)

Andrew Thompson

unread,
Aug 23, 2008, 11:33:59 PM8/23/08
to
On Aug 24, 2:21 am, r...@zedat.fu-berlin.de (Stefan Ram) wrote:
...

>   Can you see anything suspicious in the following
>   Java source code without pasting it into an IDE
>   or trying to compile it?

Sure..

> ...
> public class algorithm ...

..should be Algorithm according to the common
nomenclature. For all the rest of this, I would
paste it into an IDE (or rather, TextPad, which is
good enough) to show the problem in the comment).

In any case, since the riddle has been explained
by others, I shall put the 'obvious solution'.

<sscce>
/*

Every algorithm might use
- any other algorithm (in this sense and also in this class)
- the types int, double, boolean
- type conversions between int and double

- arithmetic operations +-*<span>/</span>%


- boolean-arithmetic operations < > <= >= != ==
- boolean operations & | !
- if, while(), restricted switches, ?:
- all interfaces

An algorithm might not explicitly refer to specific classes,
arrays or other types.

*/

/** type matching *<span>/</span>xhtml+xml ... */
class TestJavaDocComment {
}
</sscce>

--
Andrew Thompson
http://pscode.org/

Joshua Cranmer

unread,
Aug 23, 2008, 11:43:57 PM8/23/08
to
Andrew Thompson wrote:
> - arithmetic operations +-*<span>/</span>%

For consistency, I would do:
- arithmetic operations + - * / %

> - boolean-arithmetic operations < > <= >= != ==
> - boolean operations & | !
> - if, while(), restricted switches, ?:

Note that the other operators have spaces between them.

Andrew Thompson

unread,
Aug 24, 2008, 12:14:38 AM8/24/08
to
On Aug 24, 1:43 pm, Joshua Cranmer <Pidgeo...@verizon.invalid> wrote:
> Andrew Thompson wrote:
> >  - arithmetic operations +-*<span>/</span>%
>
> For consistency, I would do:
>   - arithmetic operations + - * / %

Good point, but would that not also apply to..

> >  - boolean-arithmetic operations < > <= >= != ==
> >  - boolean operations & | !
> >  - if, while(), restricted switches, ?:

..?

How is '?:' used in Java (besides as a String instance)?

Knute Johnson

unread,
Aug 24, 2008, 1:04:55 AM8/24/08
to

In the JLS it is a conditional operator but I thought I remembered from
my C days that that was a ternary operator. I did, K&R page 47.

--

Knute Johnson
email s/nospam/knute2008/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

Lasse Reichstein Nielsen

unread,
Aug 24, 2008, 8:17:42 AM8/24/08
to
Knute Johnson <nos...@rabbitbrush.frazmtn.com> writes:

> In the JLS it is a conditional operator but I thought I remembered
> from my C days that that was a ternary operator. I did, K&R page 47.

It is *a* ternary operator. It's a common misunderstanding that that
is its name. The expression created using it was called "conditional
expression", but the operator didn't have a name of its own.

K&R 2nd ed, ANSI C, secion 2.11: "Conditional Expression", says:

The /conditional expression/, written with the ternary
operator "?:", provides ...

"Ternary" just means that it takes three operands, just as
multiplication is a *binary* operator. It just happens that the
conditional expression operator is the only ternary operator in
the langauge (and in most languages with syntax derived from C).

In Java, the JLS calls the operator itself the "conditional operator".

/L
--
Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'

Daniel Pitts

unread,
Aug 24, 2008, 11:17:42 AM8/24/08
to
I meant to but sent prematurely. I canceled the message ASAP, but I know
that doesn't work 100%. Sorry all, who saw my spoiler.

Roedy Green

unread,
Aug 24, 2008, 1:17:10 PM8/24/08
to
On 23 Aug 2008 16:21:11 GMT, r...@zedat.fu-berlin.de (Stefan Ram)
wrote, quoted or indirectly quoted someone who said :

>public class algorithm { /* todo */ }

You violated the coding convention. That should be Algorithm.

Here is a related one:

/*
When you are done the results will appear in E:\temp\unbroken.txt
*/
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Andreas Leitgeb

unread,
Aug 25, 2008, 3:50:29 AM8/25/08
to

I think I don't really understand what you meant, but from the context
I'd guess, that either you missed my smiley, or I miss that invisible
smiley at the end of your line.

My "criticism" on the number of iterations was just a retro-fitted
excuse for placing the "break" with the almost-URL.

Jussi Piitulainen

unread,
Aug 25, 2008, 4:28:37 AM8/25/08
to
Daniele Futtorovic writes:
> On 24/08/2008 00:51, Andreas Leitgeb allegedly wrote:
>> Daniele Futtorovic wrote:
>>> <code>
>>> public class Main {
>>> public static void main(String[] ss){
>>> http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.7
>>> for(int ii = 0; ii < 5; ii++){
>>> System.out.println("README!");
>> break
>> http;//java.sun.com/docs/books/jls/third_edition/html/statements.html#14.7
>>> }
> >> }
>>> }
>>> </code>
>> Isn't one request to read something enough ? :-)
>
> Hey, you try to choose a number between zero and forty-two and we'll
> see whether you come up one.

Interesting. I chose seventeen, which is not one. I wonder what
results other people get.

John B. Matthews

unread,
Aug 25, 2008, 5:45:01 AM8/25/08
to
In article <qotod3h...@ruuvi.it.helsinki.fi>,
Jussi Piitulainen <jpii...@ling.helsinki.fi> wrote:

"Then shalt thou count to three, no more, no less. Three shall be the
number thou shalt count, and the number of the counting shall be three.
Four shalt thou not count, neither count thou two, excepting that thou
then proceed to three. Five is right out." -- Monty Python and the Holy
Grail

Oops, wrong language. :-)

--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews

Daniele Futtorovic

unread,
Aug 25, 2008, 6:36:22 AM8/25/08
to

Pervert.

--
DF.

Daniele Futtorovic

unread,
Aug 25, 2008, 6:41:20 AM8/25/08
to
On 25/08/2008 09:50, Andreas Leitgeb allegedly wrote:
> Daniele Futtorovic <da.fut...@laposte.invalid> wrote:
>> On 24/08/2008 00:51, Andreas Leitgeb allegedly wrote:
>>> Daniele Futtorovic <da.fut...@laposte.invalid> wrote:
>>>> <code>
>>>> public class Main {
>>>> public static void main(String[] ss){
>>>> http://java.sun.com/docs/books/jls/third_edition/html/statements.html#14.7
>>>> for(int ii = 0; ii < 5; ii++){
>>>> System.out.println("README!");
>>> break
>>> http;//java.sun.com/docs/books/jls/third_edition/html/statements.html#14.7
>>>> }
>>>> }
>>>> }
>>>> </code>
>>> Isn't one request to read something enough ? :-)
>> Hey, you try to choose a number between zero and forty-two and we'll see
>> whether you come up one.
>
> I think I don't really understand what you meant, but from the context
> I'd guess, that either you missed my smiley,

> or I miss that invisible
> smiley at the end of your line.

Ah, right, it was implied :).
Just a fit of surrealism. No pun intended.

--
DF.

Jussi Piitulainen

unread,
Aug 25, 2008, 6:54:34 AM8/25/08
to

Ow. Banter hurts.

In the meanwhile, another thought occurred to me: if I had been told
that the number I'm choosing is the number of times I'll be told to
"README!", then I think I'd have chosen one, or zero.

Daniele Futtorovic

unread,
Aug 25, 2008, 7:25:57 AM8/25/08
to

Aaah.. but that's the trick, you see? You have to free your mind of all
worldly concerns. I can tell, you know, for I am in truth... Irma
Malaventura, Prof. em. of Numerology at the University of Wallamaloo.

Now, relax, and try to pick a number at random that matches most closely
the one of your credit card.

--
Irma

Leihcim

unread,
Aug 27, 2008, 9:15:08 AM8/27/08
to
/***
*
*T*H
*
R
**O*
*
W**M
*
E
*!!!
*
************
*******///***********
/*+*/ public ///**********
/*++*/ class Bomb extends//*-*
Throwable{public Bomb(){explode//*-_
();}public Bomb(String curse){ explode
();}private void explode(){for(int $=0; $
<10;++$){System.out.print("tick.......");
try{Thread.currentThread().sleep(800);}//
catch (InterruptedException bombSquad){//
System.out.println("Defused! Nooooooo!");
}}System.out.println("BOOOOOOOOOOOOOOOOO"
+"OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOM!!!");
System.exit(666);}}class Bomber{//123
public static void main(String[]//4
args) throws Bomb{new Bomb();}}//
/***...%#~~~++===%#$~(#)(#$+
********************
**********/

Found this one on a t-shirt once....


Stefan Ram wrote:
> I just made this up as a time filler:
>

> Can you see anything suspicious in the following
> Java source code without pasting it into an IDE
> or trying to compile it?
>

> Code starts after this colon:
>

> /*
>
> Every algorithm might use
> - any other algorithm (in this sense and also in this class)
> - the types int, double, boolean
> - type conversions between int and double

> - arithmetic operations +-*/%


> - boolean-arithmetic operations < > <= >= != ==
> - boolean operations & | !
> - if, while(), restricted switches, ?:

> - all interfaces
>
> An algorithm might not explicitly refer to specific classes,
> arrays or other types.
>
> */
>

Daniele Futtorovic

unread,
Aug 27, 2008, 10:12:45 AM8/27/08
to

Oh dear... considering how the intelligence level of security grunts and
pigs altogether makes you wonder whether there is such a thing as an
absolute zero, I'd be careful not to stroll into an airport with such a
shirt. You might get charged with cyberterrorism -- that the T-shirt
contains a virus which makes, uh... some device explode.

... *thinks* ...

Hmm, maybe I should buy my boss one.

--
DF.

Tris Orendorff

unread,
Aug 28, 2008, 3:56:07 PM8/28/08
to
r...@zedat.fu-berlin.de (Stefan Ram) burped up warm pablum in news:test-2008...@ram.dialup.fu-berlin.de:

> I just made this up as a time filler:
>
> Can you see anything suspicious in the following
> Java source code without pasting it into an IDE
> or trying to compile it?

> - arithmetic operations +-*/%

I would think that the "*/" in the line above would terminate the comment early.

--
Tris Orendorff
[ Anyone naming their child should spend a few minutes checking rhyming slang and dodgy sounding names. Brad and Angelina failed to do this when naming their kid Shiloh Pitt. At some point, someone at school is going to spoonerise her name.
Craig Stark ]

0 new messages