Win a copy of GANs in ActionE this week in the AI forum
or WebAssembly in Action in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Problem with talking in java

 
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I want to indicate that my friend is a crackhead. Lately, I've been saying

you == crackhead

But this doesn't really work, as that is equivelent to saying "true." And I don't mean to say "true," I mean to say you are a crackhead. Clearly,

you = crackhead

doesn't work, as that is an assignment. This is already the case.

suggestions?
 
Ranch Hand
Posts: 985
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MyFriend myFriend = new MyFriend(getFriendInformation("Your friends name"));
CrackHead crackHead= turnObjectIntoCrackHead(myFriend);
 
High Plains Drifter
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think this is a Java problem but a function of imperative programming. You want a declarative model to satisfy your requirement.

And I can supply an example, a la Tiger's declarative library. Alas, this is MD; I'd be on the verge of teaching something. Can't have that.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

or
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The instanceof operator seems the most suitable for the relationship in question.

Alternatively, you may say that the you.equals(crackhead) will not compile because the compiler will flag it as "always true".
[ October 05, 2004: Message edited by: John Smith ]
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the instanceof operator is the same problem, it's just like saying "true".

Michael: Teach Us! Teach Us! Teach Us!
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, how about the most obvious and highly declarative "You extend a crackhead!"
 
Ranch Hand
Posts: 624
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class John extends Friend implements Crackhead {
...

}
 
Michael Ernest
High Plains Drifter
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The instanceof operator still produces a boolean result; I felt it also did not meet the original requirements. And since the failure of an assertion produces a catastrophic result, it may not be suitable. I might be astonished to find out, for example, that my friend is not a crackhead when I'm practically depending on the attribute, but still I wouldn't, say, turn off Elimidate to study the matter.

As a milder approach, I might instead try-catch for this event, treating it as a viable if rare exception. This means attempting some risky operation at runtime, for example, sending the guy out to the corner store with my last $20 bill to get Doritos. I can't see asking if my crackhead friend is on about his crackhead ways in the attributive sense -- what's he going to tell me when he sees the $20 dangling there? -- but I would like to know if I get change back. An UnexpectedMoneyBackException? yeah I'll catch it, and handle it accordingly! Woo! But if instead he ducks into his room with a girlie magazine and places "dude, there was a new video game" in my input buffer, it's nothing new under the sun and I continue on.

With that in mind, I could see implementing a Crackhead interface and declaring exception behavior along with it. The implementer then can try{} the "I/O" as conditions require, and handle it ("dude, that's my bus money") or declare it and pass it on to the appropriate caller ("hey, your purse was just sitting there, what did you think would happen?").

This approach allows for future implementations down the road that subclassing would restrict: Bedhead, Bonehead, Blockhead, Chowderhead, Deadhead, D*ckhead, Dunderhead, Eraserhead, Egghead, F*khead, Lemonhead, Melonhead, Motorhead, NappyHead, Poophead, Punkhead, Redhead, Sh*thead, etc.

Each interface could describe unique behavior, for example:

which extends polymorphism to the concrete class without limiting the number of potential headednesses.

So long as we're considering a full design, perhaps we should abstract a Headable interface at the top. All Headables, for example, might think() -- pardon for now any undue generosity with that term -- so it should be reasonable to check for that "behavior" at compile-time. The quality of that action, however is a run-time expression, as it is in life itself.

Some design limits to consider include failing to recognize corollary behaviors, like Numbskull or Sh*tface. Well, ok, maybe not "Sh*tface." I just wanted to type Sh*tface three times. But Numbskull, anyway. Or F*ckface. What to do with those?
[ October 05, 2004: Message edited by: Michael Ernest ]
 
Michael Ernest
High Plains Drifter
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Joseph George:

Michael: Teach Us! Teach Us! Teach Us!


Hmf. I have not yet been properly motivated.
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hah... chowderhead...
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Michael Ernest:
This approach allows for future implementations down the road that subclassing would restrict: Bedhead, Bonehead, Blockhead, Chowderhead, Deadhead, D*ckhead, Dunderhead, Eraserhead, Egghead, F*khead, Lemonhead, Melonhead, Motorhead, NappyHead, Poophead, Punkhead, Redhead, Sh*thead, etc.



That's true. Some Eggheads could be a real D*ckhead sometimes.
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your friend is a member of the set of all crackheads.
 
Michael Ernest
High Plains Drifter
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Anthony Villanueva:

That's true. Some Eggheads could be a real D*ckhead sometimes.


Jim Yingst and I like to volley a few lines back and forth once in a while, but I really can't have you speaking about him like this. I hereby admonish you.

Next time it will be a full-on chiding. You have been warned.
[ October 06, 2004: Message edited by: Michael Ernest ]
 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joseph,

You/crackhead = 1

No problom of assaignment.You got 100% pure crackhead.

---
basha
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Michael Ernest:
Jim Yingst and I like to volley a few lines back and forth once in a while, but I really can't have you speaking about him like this. I hereby admonish you.



Actually I was thinking about my classical mechanics professor, who is still unequivocally a D*ckhead.

Yeah, I remember playing racketball with Jim ways back myself, but no blood was drawn, and I raise my hat to one of the coolest sheriffs in the ranch. And besides, I consider the term "egghead" to be more or less concentrated to practitioners of the natural sciences, whereas the term "geek" now seems to be more appropriate for certain members of the IT profession. I mean, "computer geek" seems effortless in its direct simplicity, but "computer egghead" somehow feels clumsy and artless.

I apologize for the type mismatch.
 
Ranch Hand
Posts: 1759
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Michael Ernest:

This approach allows for future implementations down the road that subclassing would restrict: Bedhead, Bonehead, Blockhead, Chowderhead, Deadhead, D*ckhead, Dunderhead, Eraserhead, Egghead, F*khead, Lemonhead, Melonhead, Motorhead, NappyHead, Poophead, Punkhead, Redhead, Sh*thead, etc.


More Headables:

Leatherhead, Jughead, Dopehead, Masthead, Beachhead, Dreadhead, Towhead,
Meathead, Juicehead ( a heavy drinker) etc. etc.
[ October 07, 2004: Message edited by: Helen Thomas ]
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not forgetting:
Slaphead, bighead and towelhead
 
Helen Thomas
Ranch Hand
Posts: 1759
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pinhead - tee hee hee
drawhead of drawgear
muttonhead
brickhead
[ October 07, 2004: Message edited by: Helen Thomas ]
 
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Buthead from Beavis and Buthead (not sure if spelling is correct)
[ October 07, 2004: Message edited by: Axel Janssen ]
 
Ranch Hand
Posts: 1479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Adrian Wallace:
public class John extends Friend implements Crackhead {
...

}



I don't think John needs to be a new class by itself since beyound his crackheadness I don't know if it would add any new functionality or attributes. I think the Friend class already has a headType attribute and we would just need to assign the appropriate value to it.

I don't think Crackhead should be an interface without defined methods since there are well understood actions common to all Crackheads that are fairly typical (smokeCrack(); sellBodyForMoneyorDrugs(), etc) so Crackhead as an interface is not needed. But Crackhead as a class could be assigned as an object to the headType variable.



Friend John = new Friend();
John.headType = new crackHead();

or using a constructor to intialize :

Friend John = new Friend(new crackHead());


Conveniently, the Friend class overrides the toString() method so that System.out.print(John) would produce "John is a crackHead".
 
Helen Thomas
Ranch Hand
Posts: 1759
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Axel. It is Beavis and, usually, Butthead with two ts.

fathead, thickhead, skinhead, hothead, sorehead, swellhead, warhead, featherhead, screwhead.
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh man! Its all so geeky No doubt I'm too...

Regards,
Maulin
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


perhaps?
 
Ranch Hand
Posts: 820
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Helen Thomas:

More Headables:

Leatherhead, Jughead, Dopehead, Masthead, Beachhead, Dreadhead, Towhead,
Meathead, Juicehead ( a heavy drinker) etc. etc.

[ October 07, 2004: Message edited by: Helen Thomas ]



Interestingly Leatherhead is a town in Surrey in England. Seems like the Americans don't have a monopoly on silly town names. Maybe they were inspired by the English - after all we have a town called Old Sodbury, and in Cornwall there is a town called Looe (even more funny, a couple of miles from Looe is a village called Little Flushing).

While trying to look for more of these strange names, I found this very amusing page of odd town names in the US and UK: http://www.geocities.com/CapeCanaveral/Hall/8701/townname.htm
My particular favourite is Crappo, MD.
 
Helen Thomas
Ranch Hand
Posts: 1759
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interestingly Leatherhead is a town in Surrey in England.

It's also a friar bird - an australian bird. But I have no qualms in calling someone a leatherhead.

Re: funny town names Chipping Sodbury near Bristol. The place where JK Rowling was born and close to home of Prince Charles.
[ October 08, 2004: Message edited by: Helen Thomas ]
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mud Butte, SD
 
Michael Ernest
High Plains Drifter
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marblehead, MA
[ October 08, 2004: Message edited by: Michael Ernest ]
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a "Stoner's Green" in Oxfordshire (or north Berkshire) in the UK.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
crackheads.add(you);

assertTrue(you.getBehavior().equals(BehaviorFactory.get("crackhead")));
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now, in all fairness, "assert" isn't real java.

I classify it as funny java at best.
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Michael Ernest:

Hmf. I have not yet been properly motivated.



If I get 5 people to ask you, will that satisfy you?
 
Michael Ernest
High Plains Drifter
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, sure. But take your time; at the moment I'm working on an article for JR on annotations. JSR 175.
 
The harder I work, the luckier I get. -Sam Goldwyn So tiny. - this ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!