Re: [Pharo-users] mentoring continued I hope
On Sun, Aug 30, 2020 at 10:04 PM Roelof Wobben via Pharo-users < pharo-users@lists.pharo.org> wrote:
Hello,
I have this challenge from exercism : https://github.com/exercism/pharo-smalltalk/tree/master/exercises/clock
and this function is given :
hour: anInteger minute: anInteger2 self shouldBeImplemented
Schould I make it on this class method work that the minutes will not exceed the 59 minutes So when for example when 70 min are given so hour:0 minute:70 it will be converted to hour: 1 minutes: 10
I would argue against that approach. Make it a requirement that a given API must be used with correct values. e.g. #hours:minutes: requires hours between 00 and 23 and minutes between 00 and 59. If you want to convert equivalent time values, use a specific API. For example, many time implementations publicly define a seconds-based API, such as Time class>>#fromSeconds:. You can do the same with your implementation with a class-side #fromMinutes: method. (The corresponding instance methods would be #asSeconds and #asMinutes or something similar.) or can I better do this on the instance side.
Regards,
Roelof
Roelof explicitly said that this is for an Exercism exercise. That exercise defines the API (implicitly) in the test cases. Roelof has no choice about what the API is, his job is just to make the tests pass. Your ideas about how to design an API are good ones, it's just that Exercism says what to do. On Tue, 1 Sep 2020 at 05:01, Richard Sargent < richard.sargent@gemtalksystems.com> wrote:
On Sun, Aug 30, 2020 at 10:04 PM Roelof Wobben via Pharo-users < pharo-users@lists.pharo.org> wrote:
Hello,
I have this challenge from exercism : https://github.com/exercism/pharo-smalltalk/tree/master/exercises/clock
and this function is given :
hour: anInteger minute: anInteger2 self shouldBeImplemented
Schould I make it on this class method work that the minutes will not exceed the 59 minutes So when for example when 70 min are given so hour:0 minute:70 it will be converted to hour: 1 minutes: 10
I would argue against that approach. Make it a requirement that a given API must be used with correct values. e.g. #hours:minutes: requires hours between 00 and 23 and minutes between 00 and 59.
If you want to convert equivalent time values, use a specific API. For example, many time implementations publicly define a seconds-based API, such as Time class>>#fromSeconds:. You can do the same with your implementation with a class-side #fromMinutes: method. (The corresponding instance methods would be #asSeconds and #asMinutes or something similar.)
or can I better do this on the instance side.
Regards,
Roelof
participants (2)
-
Richard O'Keefe -
Richard Sargent