Stupidest code of the day

J

Jon Caldwell

Ann said:
How can 'code' be stupid?

stu·pid (st¡¹pîd, sty¡¹-) adjective
stu·pid·er, stu·pid·est
1. Slow to learn or understand; obtuse.
2. Lacking or marked by a lack of intelligence.
3. In a stupor; stupefied.
4. In a dazed or stunned state.
5. Pointless; worthless: a stupid job.
MARKED by a lack of intelligence.
 
R

ryan.a.johnston

The code is not optimal, that is for sure.

I think that is putting it a bit lightly. It isn't just that it isn't
optimal, it introduces added overhead, and for what? Code obscurity?
Sorry for him that his compiler couldn't warn him, but such is Java.
Why would it warn him? It is valid code.
 
A

akizub

dar7yl said:
I've seen this construct before in a VB program which I was forced (due to
economic pressures) to try and decipher.
Evidently, this is B.Gates' method of branding his personal stable of
programmers - totally wiping their brains, and rewriting their
semi-autonomous systems to interface with the Windows Foundation Class API.

regards,
Dar7yl

ps, replies to advocacy only, if you please.

As for subject. You can't say "stupid code" unless you know it purpose.
Simple for(int i=0;i<100000;i++); can be used for loading CPU for load
test for another thread.

The same is here. See the difference:
Foo foo=null;
System.out.println(""+foo);
or
System.out.println(foo);

So, the first one make perfect sense! When second one crashes flow.


As for second example:
Foo foo = (Foo )Foo.class.newInstance();
personally, I think it's just not genoius enough. Especially for M$ and
partners.
It gave me a lot of food for my thoughts.
But didn't help me in my quest.
See, I worked with VB too. In particular with Actuate VB. And it allows
in some way use Java Objects which was big help for me.
But! They created Objects without invoking constructor at all!
It's still mistery for me how it is possible and I tried approach
metioned above to do this. Unfortuanately it doesn't work...
Invokes default () constructor anyway or throws
java.lang.InstantiationException exception for Objects without default
constructor.

So, it's still big mistery for me how this VB creates Objects.
And this "stupid" example was good, but not good enough!
Let's have more "stupid" things and use them a lot.
Fool studies on own errors, smart - on others.

Alex Kizub.
 
J

Jesper Nordenberg

The same is here. See the difference:
Foo foo=null;
System.out.println(""+foo);
or
System.out.println(foo);

So, the first one make perfect sense! When second one crashes flow.

Neither example crashes or throws an exception, they both just print
"null". What's your point?

/Jesper
 
A

akizub

Probably System.out.println was not very good for example.
Maybe this is better:
String foo=null;
(foo).toString();
(""+foo).toString();

But difference between "null" and null is obvious.
At least you don't have NullPointerException.
 
C

Chris Smith

thufir said:
Why? It's such an arcane way of doing the hum-drum it's doubly
confusing. Is the constructor for Foo private? The cast is
unnecesary, since a Foo's returned anyhow, right?

The cast is needed prior to Java 1.5, but not needed in 1.5 because
'Foo.class' is an expression of type Class<Foo>, and the return value
for Class<Foo>.newInstance is Foo. Before 1.5, 'Foo.class' is an
expression of type Class, and the return value for Class.newInstance is
Object.

All of that relates to the type of the reference that is returned. In
both cases, that reference actually refers to an *object* of class Foo.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
C

Chris Smith

Probably System.out.println was not very good for example.
Maybe this is better:
String foo=null;
(foo).toString();
(""+foo).toString();

String.valueOf(foo);

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Ann

Probably System.out.println was not very good for example.
Maybe this is better:
String foo=null;
(foo).toString();
(""+foo).toString();

But difference between "null" and null is obvious.
At least you don't have NullPointerException.

What about 'nil' ?
 
T

The Ghost In The Machine

In comp.lang.java.advocacy, Ann
<[email protected]>
wrote
What about 'nil' ?

Eh?

Is that a Java 1.5 construct? It's not a 1.4 one.

Only other 'nil' I know of is from LISP.

In any event, foo.toString() generates a NullPointerException.
(""+foo).toString() works but requires an unseen StringBuffer
as an intermediary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,690
Members
48,796
Latest member
Greg L.

Latest Threads

Top