how to get out of this mess

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

how to get out of this mess

Roelof Wobben
Hello,

I tried another way to solve this but the code is a mess now.

I can update a record but the record is not updated.
And I have to do a lot of the same steps for every team.

Anyone who can help me to get out of this mess.

Code so far:  https://github.com/RoelofWobben/tournament

Roelof


Reply | Threaded
Open this post in threaded view
|

Re: how to get out of this mess

Roelof Wobben
hello,

I think I have to reconsider my classes and reponsibilities

Right now Im thinking of this

Team :  responsinble for team properties
Ranking : reponsibilities  for checking if a team is in the ranking and
updating the team statics
Tournament :  parsing the ganes and call the right functions on Ranking

Can this work or am In making to much classes

Roelof




Op 24-3-2019 om 19:02 schreef Roelof Wobben:

> Hello,
>
> I tried another way to solve this but the code is a mess now.
>
> I can update a record but the record is not updated.
> And I have to do a lot of the same steps for every team.
>
> Anyone who can help me to get out of this mess.
>
> Code so far:  https://github.com/RoelofWobben/tournament
>
> Roelof
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: how to get out of this mess

Pharo Smalltalk Users mailing list
In reply to this post by Roelof Wobben
Hi Roelof,


I probably missed your prior posts but I do have a few questions and/or
comments for you before I can be of any help!

This code is for tournaments of what sport exactly?  Hockey teams? 
Baseball teams?  Or tournaments between players (such as in chess where
the concept of Team exists only every 4 years for the chess Olympiads). 
Do you plan on handling different sports? Different tournament formats
(round robin, ladder, etc).

The whole thing seems to be centered around games/match results but you
don't have such a class in your example.  Besides, how do you handle
different results for one team for the same tournament a few years apart
(say, the 2017 Formula 1 season vs the 2018 Formula 1 season) ? 
Shouldn't tournaments also have a name and a year (or a Season object)
like they have in tennis, golf, chess, hockey, baseball, etc?

So my first impression is that you need the following classes : Team,
GameResult, Tournament and something like TournamendDirector to create
tournaments and create matches (or read/write them).

In other words, we need more info on what you are trying to do!


On 2019-03-24 14:02, Roelof Wobben wrote:

> Hello,
>
> I tried another way to solve this but the code is a mess now.
>
> I can update a record but the record is not updated.
> And I have to do a lot of the same steps for every team.
>
> Anyone who can help me to get out of this mess.
>
> Code so far:  https://github.com/RoelofWobben/tournament
>
> Roelof
>
>
--
-----------------
Benoît St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Pinterest: benoitstjean
Instagram: Chef_Benito
IRC: lamneth
GitHub: bstjean
Blogue: endormitoire.wordpress.com
"A standpoint is an intellectual horizon of radius zero".  (A. Einstein)


Reply | Threaded
Open this post in threaded view
|

Re: how to get out of this mess

Richard O'Keefe
In reply to this post by Roelof Wobben
This is a simple programming-contest sort of exercise.
You "need" only two classes.
+ a Team
  - knows its name (a String of at most 30 characters)
    * This should be passed when the Team is created;
      the rest of the program should NOT call (Team new)
      and should NEVER see an un#initialize-d Team instance.
  - knows the number of matches it has won, drawn, and lost
    (non-negative Integers, initially zero).
  - can report what it knows
  - can report the total match count and point score
  - can be told that it has won, drawn, or lost another match.
 
+ a Tournament
  - has a collection of Teams that it knows by name
    (a Dictionary)
  - and an sequence, initially undefined.
  - can read a set of match triples from a stream,
    forwarding the information about wins, draws, and losses
    to Team instances, which are created when a new name is found,
  - can convert the values of the teams collection to a
    sorted collection that is sorted by a somewhat vague order,
    I chose
      - descending on point score, then
      - descending on wins, then
      - ascending  on losses, then
      - ascending  on name.
  - can write the sorted teams to a stream in tabular form.
  ! Has a class method that does
    (self new) read: <<source>>; sort; write: <<destination>>

Frankly, formatting the output was the hardest part.

On Mon, 25 Mar 2019 at 10:00, Roelof Wobben <[hidden email]> wrote:
hello,

I think I have to reconsider my classes and reponsibilities

Right now Im thinking of this

Team :  responsinble for team properties
Ranking : reponsibilities  for checking if a team is in the ranking and
updating the team statics
Tournament :  parsing the ganes and call the right functions on Ranking

Can this work or am In making to much classes

Roelof




Op 24-3-2019 om 19:02 schreef Roelof Wobben:
> Hello,
>
> I tried another way to solve this but the code is a mess now.
>
> I can update a record but the record is not updated.
> And I have to do a lot of the same steps for every team.
>
> Anyone who can help me to get out of this mess.
>
> Code so far:  https://github.com/RoelofWobben/tournament
>
> Roelof
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: how to get out of this mess

Roelof Wobben
Thanks all

@Richard 

I did tried that way in the solution I put on the net.
But I get stuck at the point that if I update a record in the Team Class the collection at the Tournament class was not updated.

But right now , I try a new way to make it work that a new team is made and returned or a team is returned if that team is known.

Roelof



Op 25-3-2019 om 06:18 schreef Richard O'Keefe:
This is a simple programming-contest sort of exercise.
You "need" only two classes.
+ a Team
  - knows its name (a String of at most 30 characters)
    * This should be passed when the Team is created;
      the rest of the program should NOT call (Team new)
      and should NEVER see an un#initialize-d Team instance.
  - knows the number of matches it has won, drawn, and lost
    (non-negative Integers, initially zero).
  - can report what it knows
  - can report the total match count and point score
  - can be told that it has won, drawn, or lost another match.
 
+ a Tournament
  - has a collection of Teams that it knows by name
    (a Dictionary)
  - and an sequence, initially undefined.
  - can read a set of match triples from a stream,
    forwarding the information about wins, draws, and losses
    to Team instances, which are created when a new name is found,
  - can convert the values of the teams collection to a
    sorted collection that is sorted by a somewhat vague order,
    I chose
      - descending on point score, then
      - descending on wins, then
      - ascending  on losses, then
      - ascending  on name.
  - can write the sorted teams to a stream in tabular form.
  ! Has a class method that does
    (self new) read: <<source>>; sort; write: <<destination>>

Frankly, formatting the output was the hardest part.

On Mon, 25 Mar 2019 at 10:00, Roelof Wobben <[hidden email]> wrote:
hello,

I think I have to reconsider my classes and reponsibilities

Right now Im thinking of this

Team :  responsinble for team properties
Ranking : reponsibilities  for checking if a team is in the ranking and
updating the team statics
Tournament :  parsing the ganes and call the right functions on Ranking

Can this work or am In making to much classes

Roelof




Op 24-3-2019 om 19:02 schreef Roelof Wobben:
> Hello,
>
> I tried another way to solve this but the code is a mess now.
>
> I can update a record but the record is not updated.
> And I have to do a lot of the same steps for every team.
>
> Anyone who can help me to get out of this mess.
>
> Code so far:  https://github.com/RoelofWobben/tournament
>
> Roelof
>
>
>



Reply | Threaded
Open this post in threaded view
|

Re: how to get out of this mess

Richard O'Keefe
In OOP, you should not be thinking in terms of "updating a record".
You should *ask* an object to update *itself*.

      [aStream atEnd] whileFalse: [
        |fields team1 team2 outcome|
        fields := aStream nextLine subStrings: ';'.
        team1 := self teamNamed: (fields at: 1).
        team2 := self teamNamed: (fields at: 2).      
        outcome := fields at: 3.    
        outcome = 'win'  ifTrue: [team1 won.  team2 lost].
        outcome = 'draw' ifTrue: [team1 tied. team2 tied].
        outcome = 'loss' ifTrue: [team1 lost. team2 won ]].

(Extracted from a working solution.)


On Mon, 25 Mar 2019 at 19:29, Roelof Wobben <[hidden email]> wrote:
Thanks all

@Richard 

I did tried that way in the solution I put on the net.
But I get stuck at the point that if I update a record in the Team Class the collection at the Tournament class was not updated.

But right now , I try a new way to make it work that a new team is made and returned or a team is returned if that team is known.

Roelof



Op 25-3-2019 om 06:18 schreef Richard O'Keefe:
This is a simple programming-contest sort of exercise.
You "need" only two classes.
+ a Team
  - knows its name (a String of at most 30 characters)
    * This should be passed when the Team is created;
      the rest of the program should NOT call (Team new)
      and should NEVER see an un#initialize-d Team instance.
  - knows the number of matches it has won, drawn, and lost
    (non-negative Integers, initially zero).
  - can report what it knows
  - can report the total match count and point score
  - can be told that it has won, drawn, or lost another match.
 
+ a Tournament
  - has a collection of Teams that it knows by name
    (a Dictionary)
  - and an sequence, initially undefined.
  - can read a set of match triples from a stream,
    forwarding the information about wins, draws, and losses
    to Team instances, which are created when a new name is found,
  - can convert the values of the teams collection to a
    sorted collection that is sorted by a somewhat vague order,
    I chose
      - descending on point score, then
      - descending on wins, then
      - ascending  on losses, then
      - ascending  on name.
  - can write the sorted teams to a stream in tabular form.
  ! Has a class method that does
    (self new) read: <<source>>; sort; write: <<destination>>

Frankly, formatting the output was the hardest part.

On Mon, 25 Mar 2019 at 10:00, Roelof Wobben <[hidden email]> wrote:
hello,

I think I have to reconsider my classes and reponsibilities

Right now Im thinking of this

Team :  responsinble for team properties
Ranking : reponsibilities  for checking if a team is in the ranking and
updating the team statics
Tournament :  parsing the ganes and call the right functions on Ranking

Can this work or am In making to much classes

Roelof




Op 24-3-2019 om 19:02 schreef Roelof Wobben:
> Hello,
>
> I tried another way to solve this but the code is a mess now.
>
> I can update a record but the record is not updated.
> And I have to do a lot of the same steps for every team.
>
> Anyone who can help me to get out of this mess.
>
> Code so far:  https://github.com/RoelofWobben/tournament
>
> Roelof
>
>
>



Reply | Threaded
Open this post in threaded view
|

Re: how to get out of this mess

Roelof Wobben
Sorry.

Is this more the OOP way.

https://github.com/RoelofWobben/Tournament-/tree/master/Exercism-Tournament

Roelof



Op 25-3-2019 om 07:39 schreef Richard O'Keefe:
In OOP, you should not be thinking in terms of "updating a record".
You should *ask* an object to update *itself*.

      [aStream atEnd] whileFalse: [
        |fields team1 team2 outcome|
        fields := aStream nextLine subStrings: ';'.
        team1 := self teamNamed: (fields at: 1).
        team2 := self teamNamed: (fields at: 2).      
        outcome := fields at: 3.    
        outcome = 'win'  ifTrue: [team1 won.  team2 lost].
        outcome = 'draw' ifTrue: [team1 tied. team2 tied].
        outcome = 'loss' ifTrue: [team1 lost. team2 won ]].

(Extracted from a working solution.)


On Mon, 25 Mar 2019 at 19:29, Roelof Wobben <[hidden email]> wrote:
Thanks all

@Richard 

I did tried that way in the solution I put on the net.
But I get stuck at the point that if I update a record in the Team Class the collection at the Tournament class was not updated.

But right now , I try a new way to make it work that a new team is made and returned or a team is returned if that team is known.

Roelof



Op 25-3-2019 om 06:18 schreef Richard O'Keefe:
This is a simple programming-contest sort of exercise.
You "need" only two classes.
+ a Team
  - knows its name (a String of at most 30 characters)
    * This should be passed when the Team is created;
      the rest of the program should NOT call (Team new)
      and should NEVER see an un#initialize-d Team instance.
  - knows the number of matches it has won, drawn, and lost
    (non-negative Integers, initially zero).
  - can report what it knows
  - can report the total match count and point score
  - can be told that it has won, drawn, or lost another match.
 
+ a Tournament
  - has a collection of Teams that it knows by name
    (a Dictionary)
  - and an sequence, initially undefined.
  - can read a set of match triples from a stream,
    forwarding the information about wins, draws, and losses
    to Team instances, which are created when a new name is found,
  - can convert the values of the teams collection to a
    sorted collection that is sorted by a somewhat vague order,
    I chose
      - descending on point score, then
      - descending on wins, then
      - ascending  on losses, then
      - ascending  on name.
  - can write the sorted teams to a stream in tabular form.
  ! Has a class method that does
    (self new) read: <<source>>; sort; write: <<destination>>

Frankly, formatting the output was the hardest part.

On Mon, 25 Mar 2019 at 10:00, Roelof Wobben <[hidden email]> wrote:
hello,

I think I have to reconsider my classes and reponsibilities

Right now Im thinking of this

Team :  responsinble for team properties
Ranking : reponsibilities  for checking if a team is in the ranking and
updating the team statics
Tournament :  parsing the ganes and call the right functions on Ranking

Can this work or am In making to much classes

Roelof




Op 24-3-2019 om 19:02 schreef Roelof Wobben:
> Hello,
>
> I tried another way to solve this but the code is a mess now.
>
> I can update a record but the record is not updated.
> And I have to do a lot of the same steps for every team.
>
> Anyone who can help me to get out of this mess.
>
> Code so far:  https://github.com/RoelofWobben/tournament
>
> Roelof
>
>
>




Reply | Threaded
Open this post in threaded view
|

Re: how to get out of this mess

Roelof Wobben
and Ricard , I forgot to thank you for the explantion and the code.

Roelof



Op 25-3-2019 om 08:40 schreef Roelof Wobben:
Sorry.

Is this more the OOP way.

https://github.com/RoelofWobben/Tournament-/tree/master/Exercism-Tournament

Roelof



Op 25-3-2019 om 07:39 schreef Richard O'Keefe:
In OOP, you should not be thinking in terms of "updating a record".
You should *ask* an object to update *itself*.

      [aStream atEnd] whileFalse: [
        |fields team1 team2 outcome|
        fields := aStream nextLine subStrings: ';'.
        team1 := self teamNamed: (fields at: 1).
        team2 := self teamNamed: (fields at: 2).      
        outcome := fields at: 3.    
        outcome = 'win'  ifTrue: [team1 won.  team2 lost].
        outcome = 'draw' ifTrue: [team1 tied. team2 tied].
        outcome = 'loss' ifTrue: [team1 lost. team2 won ]].

(Extracted from a working solution.)


On Mon, 25 Mar 2019 at 19:29, Roelof Wobben <[hidden email]> wrote:
Thanks all

@Richard 

I did tried that way in the solution I put on the net.
But I get stuck at the point that if I update a record in the Team Class the collection at the Tournament class was not updated.

But right now , I try a new way to make it work that a new team is made and returned or a team is returned if that team is known.

Roelof



Op 25-3-2019 om 06:18 schreef Richard O'Keefe:
This is a simple programming-contest sort of exercise.
You "need" only two classes.
+ a Team
  - knows its name (a String of at most 30 characters)
    * This should be passed when the Team is created;
      the rest of the program should NOT call (Team new)
      and should NEVER see an un#initialize-d Team instance.
  - knows the number of matches it has won, drawn, and lost
    (non-negative Integers, initially zero).
  - can report what it knows
  - can report the total match count and point score
  - can be told that it has won, drawn, or lost another match.
 
+ a Tournament
  - has a collection of Teams that it knows by name
    (a Dictionary)
  - and an sequence, initially undefined.
  - can read a set of match triples from a stream,
    forwarding the information about wins, draws, and losses
    to Team instances, which are created when a new name is found,
  - can convert the values of the teams collection to a
    sorted collection that is sorted by a somewhat vague order,
    I chose
      - descending on point score, then
      - descending on wins, then
      - ascending  on losses, then
      - ascending  on name.
  - can write the sorted teams to a stream in tabular form.
  ! Has a class method that does
    (self new) read: <<source>>; sort; write: <<destination>>

Frankly, formatting the output was the hardest part.

On Mon, 25 Mar 2019 at 10:00, Roelof Wobben <[hidden email]> wrote:
hello,

I think I have to reconsider my classes and reponsibilities

Right now Im thinking of this

Team :  responsinble for team properties
Ranking : reponsibilities  for checking if a team is in the ranking and
updating the team statics
Tournament :  parsing the ganes and call the right functions on Ranking

Can this work or am In making to much classes

Roelof




Op 24-3-2019 om 19:02 schreef Roelof Wobben:
> Hello,
>
> I tried another way to solve this but the code is a mess now.
>
> I can update a record but the record is not updated.
> And I have to do a lot of the same steps for every team.
>
> Anyone who can help me to get out of this mess.
>
> Code so far:  https://github.com/RoelofWobben/tournament
>
> Roelof
>
>
>





Reply | Threaded
Open this post in threaded view
|

Re: how to get out of this mess

Roelof Wobben
In reply to this post by Roelof Wobben
I try to understand the way the streams works here.

but as far as I can see the collection is a array.


I tried to convert it with  aCollection readStream.

But then I see a error on the nextline

Anyone a hint  how I can make this work.

Roelof



Op 25-3-2019 om 08:40 schreef Roelof Wobben:
Sorry.

Is this more the OOP way.

https://github.com/RoelofWobben/Tournament-/tree/master/Exercism-Tournament

Roelof



Op 25-3-2019 om 07:39 schreef Richard O'Keefe:
In OOP, you should not be thinking in terms of "updating a record".
You should *ask* an object to update *itself*.

      [aStream atEnd] whileFalse: [
        |fields team1 team2 outcome|
        fields := aStream nextLine subStrings: ';'.
        team1 := self teamNamed: (fields at: 1).
        team2 := self teamNamed: (fields at: 2).      
        outcome := fields at: 3.    
        outcome = 'win'  ifTrue: [team1 won.  team2 lost].
        outcome = 'draw' ifTrue: [team1 tied. team2 tied].
        outcome = 'loss' ifTrue: [team1 lost. team2 won ]].

(Extracted from a working solution.)


On Mon, 25 Mar 2019 at 19:29, Roelof Wobben <[hidden email]> wrote:
Thanks all

@Richard 

I did tried that way in the solution I put on the net.
But I get stuck at the point that if I update a record in the Team Class the collection at the Tournament class was not updated.

But right now , I try a new way to make it work that a new team is made and returned or a team is returned if that team is known.

Roelof



Op 25-3-2019 om 06:18 schreef Richard O'Keefe:
This is a simple programming-contest sort of exercise.
You "need" only two classes.
+ a Team
  - knows its name (a String of at most 30 characters)
    * This should be passed when the Team is created;
      the rest of the program should NOT call (Team new)
      and should NEVER see an un#initialize-d Team instance.
  - knows the number of matches it has won, drawn, and lost
    (non-negative Integers, initially zero).
  - can report what it knows
  - can report the total match count and point score
  - can be told that it has won, drawn, or lost another match.
 
+ a Tournament
  - has a collection of Teams that it knows by name
    (a Dictionary)
  - and an sequence, initially undefined.
  - can read a set of match triples from a stream,
    forwarding the information about wins, draws, and losses
    to Team instances, which are created when a new name is found,
  - can convert the values of the teams collection to a
    sorted collection that is sorted by a somewhat vague order,
    I chose
      - descending on point score, then
      - descending on wins, then
      - ascending  on losses, then
      - ascending  on name.
  - can write the sorted teams to a stream in tabular form.
  ! Has a class method that does
    (self new) read: <<source>>; sort; write: <<destination>>

Frankly, formatting the output was the hardest part.

On Mon, 25 Mar 2019 at 10:00, Roelof Wobben <[hidden email]> wrote:
hello,

I think I have to reconsider my classes and reponsibilities

Right now Im thinking of this

Team :  responsinble for team properties
Ranking : reponsibilities  for checking if a team is in the ranking and
updating the team statics
Tournament :  parsing the ganes and call the right functions on Ranking

Can this work or am In making to much classes

Roelof




Op 24-3-2019 om 19:02 schreef Roelof Wobben:
> Hello,
>
> I tried another way to solve this but the code is a mess now.
>
> I can update a record but the record is not updated.
> And I have to do a lot of the same steps for every team.
>
> Anyone who can help me to get out of this mess.
>
> Code so far:  https://github.com/RoelofWobben/tournament
>
> Roelof
>
>
>





Reply | Threaded
Open this post in threaded view
|

Re: how to get out of this mess

Roelof Wobben
@Richard

when I use your code I see this error message




Op 25-3-2019 om 12:26 schreef Roelof Wobben:
I try to understand the way the streams works here.

but as far as I can see the collection is a array.


I tried to convert it with  aCollection readStream.

But then I see a error on the nextline

Anyone a hint  how I can make this work.

Roelof



Op 25-3-2019 om 08:40 schreef Roelof Wobben:
Sorry.

Is this more the OOP way.

https://github.com/RoelofWobben/Tournament-/tree/master/Exercism-Tournament

Roelof



Op 25-3-2019 om 07:39 schreef Richard O'Keefe:
In OOP, you should not be thinking in terms of "updating a record".
You should *ask* an object to update *itself*.

      [aStream atEnd] whileFalse: [
        |fields team1 team2 outcome|
        fields := aStream nextLine subStrings: ';'.
        team1 := self teamNamed: (fields at: 1).
        team2 := self teamNamed: (fields at: 2).      
        outcome := fields at: 3.    
        outcome = 'win'  ifTrue: [team1 won.  team2 lost].
        outcome = 'draw' ifTrue: [team1 tied. team2 tied].
        outcome = 'loss' ifTrue: [team1 lost. team2 won ]].

(Extracted from a working solution.)


On Mon, 25 Mar 2019 at 19:29, Roelof Wobben <[hidden email]> wrote:
Thanks all

@Richard 

I did tried that way in the solution I put on the net.
But I get stuck at the point that if I update a record in the Team Class the collection at the Tournament class was not updated.

But right now , I try a new way to make it work that a new team is made and returned or a team is returned if that team is known.

Roelof



Op 25-3-2019 om 06:18 schreef Richard O'Keefe:
This is a simple programming-contest sort of exercise.
You "need" only two classes.
+ a Team
  - knows its name (a String of at most 30 characters)
    * This should be passed when the Team is created;
      the rest of the program should NOT call (Team new)
      and should NEVER see an un#initialize-d Team instance.
  - knows the number of matches it has won, drawn, and lost
    (non-negative Integers, initially zero).
  - can report what it knows
  - can report the total match count and point score
  - can be told that it has won, drawn, or lost another match.
 
+ a Tournament
  - has a collection of Teams that it knows by name
    (a Dictionary)
  - and an sequence, initially undefined.
  - can read a set of match triples from a stream,
    forwarding the information about wins, draws, and losses
    to Team instances, which are created when a new name is found,
  - can convert the values of the teams collection to a
    sorted collection that is sorted by a somewhat vague order,
    I chose
      - descending on point score, then
      - descending on wins, then
      - ascending  on losses, then
      - ascending  on name.
  - can write the sorted teams to a stream in tabular form.
  ! Has a class method that does
    (self new) read: <<source>>; sort; write: <<destination>>

Frankly, formatting the output was the hardest part.

On Mon, 25 Mar 2019 at 10:00, Roelof Wobben <[hidden email]> wrote:
hello,

I think I have to reconsider my classes and reponsibilities

Right now Im thinking of this

Team :  responsinble for team properties
Ranking : reponsibilities  for checking if a team is in the ranking and
updating the team statics
Tournament :  parsing the ganes and call the right functions on Ranking

Can this work or am In making to much classes

Roelof




Op 24-3-2019 om 19:02 schreef Roelof Wobben:
> Hello,
>
> I tried another way to solve this but the code is a mess now.
>
> I can update a record but the record is not updated.
> And I have to do a lot of the same steps for every team.
>
> Anyone who can help me to get out of this mess.
>
> Code so far:  https://github.com/RoelofWobben/tournament
>
> Roelof
>
>
>