[squeak-dev] [Pharo-users] mentor question 4

Trygve Reenskaug trygver at ifi.uio.no
Tue May 5 09:50:31 UTC 2020


Richard,

Thank you for looking at the code. It is comforting to learn that the 
code has been executed for a large number of examples without breaking. 
The code is not primarily written for execution but for being read and 
checked by the human end user. It would be nice if we could also check 
that it gave the right answers, but I don't know how to do that.

*/The first question is: Can a human domain expert read the code and 
sign their name for its correctness?/*


When this is achieved, a programming expert will transcribe the first 
code to a professional quality program. This time, the second code 
should be reviewed by an independent programmer who signs their name for 
its correct transcription from the first version.

--Trygve

PS: In his 1991 Turing Award Lecture, Tony Hoare said: /"There are two 
ways of constructing a software design: One way is to make it so simple 
that there are obviously no deficiencies and the other is to make it so 
complicated that there are no obvious deficiencies. The first method is 
far more difficult."/

--Trygve

On tirsdag.05.05.2020 04:41, Richard O'Keefe wrote:
> As a coding experiment, I adapted Trygve  Reenskoug's code to my
> Smalltalk compiler, put in my code slightly tweaked, and benchmarked
> them on randomly generated data.
>
> Result: a factor of 6.3.
>
> In Squeak it was a factor of ten.
>
> I had not, in all honesty, expected it to to be so high.
>
> On Tue, 5 May 2020 at 02:00, Trygve Reenskaug <trygver at ifi.uio.no> wrote:
>>   A coding experiment.
>> Consider a Scrum development environment. Every programming team has an end user as a member.
>> The team's task is to code a credit card validity check.
>> A first goal is that the user representative shall read the code and agree that it is a correct rendering of their code checker:
>>
>>      luhnTest: trialNumber
>>          | s1 odd s2 even charValue reverse |
>> -----------------------------------------------
>> " Luhn test according to Rosetta"
>> "Reverse the order of the digits in the number."
>>      reverse := trialNumber reversed.
>> "Take the first, third, ... and every other odd digit in the reversed digits and sum them to form the partial sum s1"
>>      s1 := 0.
>>      odd := true.
>>      reverse do:
>>          [:char |
>>              odd
>>                  ifTrue: [
>>                      s1 := s1 + char digitValue.
>>                  ].
>>                  odd := odd not
>>          ].
>> "Taking the second, fourth ... and every other even digit in the reversed digits:
>> Multiply each digit by two and sum the digits if the answer is greater than nine to form partial sums for the even digits"
>>      "The subtracting 9 gives the same answer. "
>> "Sum the partial sums of the even digits to form s2"
>>      s2 := 0.
>>      even := false.
>>      reverse do:
>>          [:char |
>>              even
>>                  ifTrue: [
>>                      charValue := char digitValue * 2.
>>                      charValue > 9 ifTrue: [charValue := charValue - 9].
>>                      s2 := s2 + charValue
>>                  ].
>>                  even := even not
>>          ].
>> "If s1 + s2 ends in zero then the original number is in the form of a valid credit card number as verified by the Luhn test."
>>      ^(s1 + s2) asString last = $0
>> ---------------------------------
>> Once this step is completed, the next step will be to make the code right without altering the algorithm (refactoring). The result should be readable and follow the team's conventions.
>>
>>
>> P.S. code attached.

-- 

/The essence of object orientation is that objects collaborateto achieve 
a goal. /
Trygve Reenskaug mailto: trygver at ifi.uio.no <mailto:%20trygver at ifi.uio.no>
Morgedalsvn. 5A http://folk.uio.no/trygver/
N-0378 Oslo http://fullOO.info
Norway                     Tel: (+47) 468 58 625

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200505/94cad511/attachment.html>


More information about the Squeak-dev mailing list