Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > proper use of .java files (layout)

Reply
Thread Tools

proper use of .java files (layout)

 
 
Arne Vajhøj
Guest
Posts: n/a
 
      12-19-2012
On 12/18/2012 12:10 AM, Gene Wirchenko wrote:
> On Mon, 17 Dec 2012 21:28:07 -0500, Arne Vajhøj <>
> wrote:
>
>> On 12/17/2012 9:18 PM, Gene Wirchenko wrote:
>>> On Mon, 17 Dec 2012 20:55:21 -0500, Arne Vajhøj <>
>>> wrote:
>>>
>>> [snip]
>>>
>>>> 13 distinct values with an order but no numeric values
>>>> seems a perfect fit for enum to me.
>>>
>>> An enum does not guarantee an order.

>>
>> In the Java I use enums have a compareTo method.

>
> And how would you handle the aces?
>
> A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
> five-high straight).


That does not relate to whether Java enum has an order
or not.

But anyway - even with a natural order, then a game
specific ordering can be allowed.

Arne


 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      12-19-2012
On 12/18/2012 11:07 AM, Eric Sosman wrote:
> On 12/18/2012 10:05 AM, lipska the kat wrote:
>> On 18/12/12 14:32, wrote:
>>
>>> I'm not exactly sure what card game I will be programming at this time.

>>
>> Interesting, what do our procedural programmer(s) make of this then.
>> The OP isn't sure what game he will be programming ....
>>
>> I suggest you start writing some code

>
> He doesn't know what he wants to do, yet your advice is
> "start writing some code?"


If we are talking about a real project that is going to end up
with XXX KLOC, then start coding would be pointless.

But for a beginner wanting to learn programming and Java, then
start coding may actually be a fine advice.

Arne


 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      12-19-2012
On 12/18/2012 12:23 PM, Patricia Shanahan wrote:
> On 12/18/2012 9:13 AM, Gene Wirchenko wrote:
>> On Tue, 18 Dec 2012 08:53:58 -0500, Eric Sosman
>> <> wrote:
>>
>>> On 12/18/2012 12:10 AM, Gene Wirchenko wrote:

>>
>> [snip]
>>
>>>> And how would you handle the aces?
>>>>
>>>> A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
>>>> five-high straight).
>>>
>>> In some "high-low" games, A-5-4-3-2 can be both a
>>> five-high straight *and* an Ace with four low cards,
>>> possibly winning both the "high" and "low" shares of
>>> the pot.

>>
>> Right. I have rarely ever played high-low and forgot about them.
>> Does anyone else have an exception to ambush us with? <g>

>
> I think that sort of issue could be handled by having game-dependent
> Comparator<Card,Card> implementations, rather than making Card Comparable.
>
> I would be more concerned about jokers, which do not follow the
> (suit,value) pattern.


An abstract Card class with two sub classes RegularCard and Joker??

Arne


 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      12-19-2012
On 12/18/2012 1:49 PM, Eric Sosman wrote:
> On 12/18/2012 12:23 PM, Patricia Shanahan wrote:
>> On 12/18/2012 9:13 AM, Gene Wirchenko wrote:
>>> On Tue, 18 Dec 2012 08:53:58 -0500, Eric Sosman
>>> <> wrote:
>>>
>>>> On 12/18/2012 12:10 AM, Gene Wirchenko wrote:
>>>
>>> [snip]
>>>
>>>>> And how would you handle the aces?
>>>>>
>>>>> A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
>>>>> five-high straight).
>>>>
>>>> In some "high-low" games, A-5-4-3-2 can be both a
>>>> five-high straight *and* an Ace with four low cards,
>>>> possibly winning both the "high" and "low" shares of
>>>> the pot.
>>>
>>> Right. I have rarely ever played high-low and forgot about them.
>>> Does anyone else have an exception to ambush us with? <g>

>>
>> I think that sort of issue could be handled by having game-dependent
>> Comparator<Card,Card> implementations, rather than making Card
>> Comparable.

>
> A comparator might have a hard time declaring "Ace is lower
> than Deuce" and "Ace is higher than Deuce" simultaneously ...
>
> And then, there are games where two identical ranks in the
> same hand can have different values. With A-A-9, for example, a
> Blackjack player would get the desired total of 21 by counting
> one Ace as a 1 and the other as an 11. (This appears to be the
> class of game the O.P. is interested in.)


If the logic can be described precisely, then it can be
implemented in code.

I somewhat suspect that stuff like this will not result
in pretty code.

Arne


 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      12-19-2012
On 12/18/2012 6:45 PM, Wayne wrote:
> On 12/17/2012 9:37 PM, Arne Vajhøj wrote:
>> On 12/17/2012 9:32 PM, Eric Sosman wrote:
>>> On 12/17/2012 9:29 PM, Arne Vajhøj wrote:
>>>> On 12/17/2012 9:25 PM, Eric Sosman wrote:
>>>>> On 12/17/2012 8:58 PM, Arne Vajhøj wrote:
>>>>>>
>>>>>> I would argue that a deck is always 52 cards, but that some
>>>>>> games use more than one deck.
>>>>>
>>>>> How come a brand-new pack of cards always has fifty-four?
>>>>
>>>> It does not always.
>>>>
>>>> It comes with 2, 3 or maybe even 4 jokers.
>>>>
>>>> So number of jokers should be a constructor argument, if
>>>> it has to be realistic.
>>>
>>> Can we say, then, that "a deck is always 52 cards, for
>>> suitable values of 52?"

>>
>> Very funny.
>>
>> A deck is 52 + number of jokers cards.
>>
>> A game may be multiple decks or maybe even a subset of a deck.

>
> That's only for a bridge/poker deck. A pinochle deck consists of two copies
> of each of the 9, 10, jack, queen, king, and ace cards of all four suits,
> for 48 cards per deck. Aces are always considered high. Pinochle follows a
> nonstandard card ordering. The complete ordering from highest to lowest
> is A, 10, K, Q, J, 9. [quoted from Wikipedia]
>
> Trying to generalize all card games with a single abstraction is probably a mistake.


Sounds right.

> If you limit the card games to those with hands that use a bridge/poker deck,
> you probably want a unique ID for each card. Then the game class should implement
> a handValue(Set<Card>) method, which may return a set of HandValues (rather
> than a single value; it depends on the game I suppose). The
> implementation can map Cards to value(s) in a given game context. The
> error seems to be trying to put the valuation logic in the Card enum; the
> values don't seem to be static enough to me.


Having game specific values does not preclude having a
natural order.

Arne


 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      12-19-2012
On 12/18/2012 8:11 PM, Arne Vajhøj wrote:
> On 12/18/2012 1:49 PM, Eric Sosman wrote:
>> On 12/18/2012 12:23 PM, Patricia Shanahan wrote:
>>> On 12/18/2012 9:13 AM, Gene Wirchenko wrote:
>>>> On Tue, 18 Dec 2012 08:53:58 -0500, Eric Sosman
>>>> <> wrote:
>>>>
>>>>> On 12/18/2012 12:10 AM, Gene Wirchenko wrote:
>>>>
>>>> [snip]
>>>>
>>>>>> And how would you handle the aces?
>>>>>>
>>>>>> A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
>>>>>> five-high straight).
>>>>>
>>>>> In some "high-low" games, A-5-4-3-2 can be both a
>>>>> five-high straight *and* an Ace with four low cards,
>>>>> possibly winning both the "high" and "low" shares of
>>>>> the pot.
>>>>
>>>> Right. I have rarely ever played high-low and forgot about them.
>>>> Does anyone else have an exception to ambush us with? <g>
>>>
>>> I think that sort of issue could be handled by having game-dependent
>>> Comparator<Card,Card> implementations, rather than making Card
>>> Comparable.

>>
>> A comparator might have a hard time declaring "Ace is lower
>> than Deuce" and "Ace is higher than Deuce" simultaneously ...
>>
>> And then, there are games where two identical ranks in the
>> same hand can have different values. With A-A-9, for example, a
>> Blackjack player would get the desired total of 21 by counting
>> one Ace as a 1 and the other as an 11. (This appears to be the
>> class of game the O.P. is interested in.)

>
> If the logic can be described precisely, then it can be
> implemented in code.


Yes. But my principal point in all of this is that it cannot
always be implemented in *simple* code. Given the variety of card
games, it is folly to try to capture the notion of "card" in a
single, game-independent way. The same holds true for many other
problem domains as well: It is fruitless to model "a card" or
"a stock market" or "a person" in isolation from the model in
which the card/market/person will be represented.

The fundamental strength of O-O is that *sometimes* such
problem-oblivious models can be created, and *sometimes* the
next problem in line will be able to re-use the model. The
fundamental fallacy of O-O zealots is that such models are
independent of the problem; they nearly always aren't.

> I somewhat suspect that stuff like this will not result
> in pretty code.


(Shrug.) If you want to model something, you choose your
own level of fidelity. An old story tells of an engineer, a
physicist, and a mathematician tasked with finding the wind
resistance of a proposed design for a railway locomotive. The
engineer suggests building a full-scale wind tunnel, putting a
mock-up of the locomotive inside, and measuring the drag with a
simple spring scale.

"Wasteful!" cries the physicist. "The whole thing is fully
explained by the following enormous system of partial differential
equations, for which we can get numerical solutions with only six
and a half months' time on the world's largest supercomputer."

"Tut-tut," says the mathematician. "You empiricists are all
alike, rushing to measurements and approximations when a simple
grasp of theory would render everything clear to the suitably
rigorous mind. Now attend: Consider a spherical train ..."

(You think I'm kidding? There exist astrophysical models of
stellar structure in *one* dimension: radial distance from center.
So much for angular momentum and solar flares, eh?)

--
Eric Sosman
d
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      12-19-2012
On 12/18/2012 8:07 PM, Arne Vajhøj wrote:
> On 12/18/2012 11:07 AM, Eric Sosman wrote:
>> On 12/18/2012 10:05 AM, lipska the kat wrote:
>>> On 18/12/12 14:32, wrote:
>>>
>>>> I'm not exactly sure what card game I will be programming at this time.
>>>
>>> I suggest you start writing some code

>>
>> He doesn't know what he wants to do, yet your advice is
>> "start writing some code?"

>
> If we are talking about a real project that is going to end up
> with XXX KLOC, then start coding would be pointless.


On the contrary: If your goal is to accumulate KLOC so you
can boast about them at your salary review, you should *never*
waste time in design!

> But for a beginner wanting to learn programming and Java, then
> start coding may actually be a fine advice.


He who is aimless can never miss.

--
Eric Sosman
d
 
Reply With Quote
 
Arne Vajhøj
Guest
Posts: n/a
 
      12-19-2012
On 12/18/2012 9:11 PM, Eric Sosman wrote:
> On 12/18/2012 8:07 PM, Arne Vajhøj wrote:
>> On 12/18/2012 11:07 AM, Eric Sosman wrote:
>>> On 12/18/2012 10:05 AM, lipska the kat wrote:
>>>> On 18/12/12 14:32, wrote:
>>>>
>>>>> I'm not exactly sure what card game I will be programming at this
>>>>> time.
>>>>
>>>> I suggest you start writing some code
>>>
>>> He doesn't know what he wants to do, yet your advice is
>>> "start writing some code?"

>>
>> If we are talking about a real project that is going to end up
>> with XXX KLOC, then start coding would be pointless.

>
> On the contrary: If your goal is to accumulate KLOC so you
> can boast about them at your salary review, you should *never*
> waste time in design!


Funny.

>> But for a beginner wanting to learn programming and Java, then
>> start coding may actually be a fine advice.

>
> He who is aimless can never miss.


If he learns to code Java, then it does not matter
much if the resulting code changes along the way.

If he starts at the top with let us say ZF, then I can
almost guarantee that he will neither learn Java nor
get any working code out of it.

Arne


 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-19-2012
On Wed, 19 Dec 2012 09:33:59 +0000, lipska the kat
<> wrote:

>On 19/12/12 02:07, Eric Sosman wrote:
>> On 12/18/2012 8:11 PM, Arne Vajhøj wrote:

>
>[snip]
>
>>> If the logic can be described precisely, then it can be
>>> implemented in code.

>>
>> Yes. But my principal point in all of this is that it cannot
>> always be implemented in *simple* code. Given the variety of card
>> games, it is folly to try to capture the notion of "card" in a
>> single, game-independent way.

>
>OK, I guess we got off on the wrong foot so I'll try again.
>I'm not trying to be condescending. I'm genuinely interested in your
>response.
>
>Can we agree that the names we give things help our understanding of
>what those things are supposed to represent ?


Sure. Remember, though, that the name is not the thing.

>In our world, it almost always the case that, sooner or later, someone
>who was not present during the design phase of our system will need to
>understand it in order to maintain it. Good names for system concepts help.


Sure. I go to the trouble of documenting them in a client
billing system that I maintain. I am likely the only one to look at
that part of the code, but I do it anyway because solid definitions
are important.

>If we think of a Card in the 'games played with cards' universe then,
>unless I've missed something a card is a small piece of cloth or
>cardboard that has some numbers, pictures or symbols on one or both
>sides. Maybe a better name would be PlayingCard
>
>The concept of a PlayingCard is fixed in our collective memory by virtue
>of the experiences we have of PlayingCards in our lives.
>Of course different cultures use cards in different ways to play
>different games but the point is, if you ask anyone on the planet what a
>PlayingCard is them I suggest that the basic concept will always be there.


But there are so many examples of definitions. I prefer to
solidify the definition that I need before coding. My program may be
a one-off so my card definition is never used elsewhere. If I suspect
that it reasonably might be reused, then I will look more generally
for that definition. At some point though, it is better to decide on
something and run with it.

>Can we also agree that any system needs a starting point and a good
>starting point might be a name that seems to capture at least part of
>what our system is supposed to do.
>
>If we agree on these few simple principles then I'd be interested to
>know what name you might use for your starting point if not PlayingCard
>(or Card).


I would not bother. Determining the name comes as part of the
design. I might even have more than one name because I might have to
handle special cases.

>I can't think of a card game that does not use PlayingCards of one sort
>or another. One might argue that Tarot is not a game yet uses Cards.
>This might mean that PlayingCard is unsuitable, so we fall back to Card
>with PlayingCard a possible later specialization.


That depends on your definition of the term. If you mean the
run-of-the-garden 52-54 or so card deck, I can think of some easily.
Gang of Four is one example.

>If the base abstraction is not Card then what else might describe what a
>Card is better than 'Card'


Who knows yet? That is what the analysis and design are for.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
Gene Wirchenko
Guest
Posts: n/a
 
      12-19-2012
On Tue, 18 Dec 2012 20:04:31 -0500, Arne Vajhøj <>
wrote:

>On 12/18/2012 12:10 AM, Gene Wirchenko wrote:


[snip]

>> A-6-4-3-2 is ace high, but A-5-4-3-2 is actually 5-4-3-2-A (a
>> five-high straight).

>
>That does not relate to whether Java enum has an order
>or not.
>
>But anyway - even with a natural order, then a game
>specific ordering can be allowed.


My point is that, in this case, there would be more than one
order.

Sincerely,

Gene Wirchenko
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What's the proper way to use SocketChannel.finishConnect()? - Java 1 07-26-2005 01:03 AM
Proper use of assertions Razvan Java 5 10-08-2004 02:39 PM
Proper way to use an imported constant under 'use strict'? H. Wade Minter Perl Misc 8 04-25-2004 12:58 AM
Proper (vs. desirable) use of Graphics object Wolfgang Java 7 01-23-2004 05:42 PM
Proper use of CharsetDecoder? Harald Kirsch Java 1 08-05-2003 07:15 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57