Re: [Pharo-users] is this better regarding naming thigs
What is the receiver? There are two and only two relevant objects: the word and the collection. aCollection selectAnagramsOf: aString aString anagramsIn: aCollection would be good names. In a language that did not let you extend system classes, anagrams(of: aString, in: aCollection) would be good, but Smalltalk is not such a language. 'findAnagramsCandidates:subject:' is intention-revealing, but is not good English. Well, maybe the intentions could be revealed a bit better. What is the subject of an anagram? No idea. What is an 'anagramsCandidate'? No idea. What is the difference between an 'anagram' and an 'anagramCandidate'? <whatever> anagramsOf: aString in: aCollection <whatever> selectFrom: aCollection anagramsOf: aString On Mon, 6 Jan 2020 at 03:07, Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org> wrote:
Hello
In a earlier question I get a remark to think better about naming things. Now I did a challene where I have to find anagrams of a given word in a collection,
So I did this :
findAnagramsCandidates: aCollection subject: aWord | charBag | charBag := aWord asLowercase asBag. ^ aCollection reject: [ :word | (word sameAs: aWord) or: [ word asLowercase asBag ~= charBag ] ]
is my naming here better or can i improved and if so how ?
Regards,
Roelof
When I wrote "is not good English", I meant that "findAnagramsCandidates" sounds *horrible* to this native speaker of English. "findCandidateAnagrams" works. On Tue, 7 Jan 2020 at 18:12, Richard O'Keefe <raoknz@gmail.com> wrote:
What is the receiver? There are two and only two relevant objects: the word and the collection. aCollection selectAnagramsOf: aString aString anagramsIn: aCollection would be good names. In a language that did not let you extend system classes, anagrams(of: aString, in: aCollection) would be good, but Smalltalk is not such a language.
'findAnagramsCandidates:subject:' is intention-revealing, but is not good English. Well, maybe the intentions could be revealed a bit better. What is the subject of an anagram? No idea. What is an 'anagramsCandidate'? No idea. What is the difference between an 'anagram' and an 'anagramCandidate'?
<whatever> anagramsOf: aString in: aCollection <whatever> selectFrom: aCollection anagramsOf: aString
On Mon, 6 Jan 2020 at 03:07, Roelof Wobben via Pharo-users <pharo-users@lists.pharo.org> wrote:
Hello
In a earlier question I get a remark to think better about naming things. Now I did a challene where I have to find anagrams of a given word in a collection,
So I did this :
findAnagramsCandidates: aCollection subject: aWord | charBag | charBag := aWord asLowercase asBag. ^ aCollection reject: [ :word | (word sameAs: aWord) or: [ word asLowercase asBag ~= charBag ] ]
is my naming here better or can i improved and if so how ?
Regards,
Roelof
richard, fwiw Roeloff mentioned earlier that the message-name was provided by the exercise set he's following, and isn't of his invention: http://forum.world.st/is-this-better-regarding-naming-thigs-tp5109389p510947... . he sh/could fwd your note/s to the course-author ;) -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
I should have remembered that, seeing that I've done 41/42 of the Pharo exercisms, and am currently doing the F# ones in my spare time, which I have had very little of lately. I have started using the <BADNAME[: 'reason']> annotation in such cases to remind me not to fix the code. Looking back at my solution, I see that my irritation at yet another "Pharo" exercism that had no significant connection with *OOP* as such masked the irritation I should have felt at the bad name. I also recall now my annoyance at exercism.io's frequent practice of omitting key parts of specifications but including tests for them. Seriously, sometimes it's worth it to write good code and then write glue code to the required interface. On Tue, 7 Jan 2020 at 18:50, xap <xap@router.33mail.com> wrote:
richard, fwiw Roeloff mentioned earlier that the message-name was provided by the exercise set he's following, and isn't of his invention: http://forum.world.st/is-this-better-regarding-naming-thigs-tp5109389p510947... . he sh/could fwd your note/s to the course-author ;)
-- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Richard O'Keefe wrote
Seriously, sometimes it's worth it to write good code and then write glue code to the required interface.
Maybe "most of the time". Or "It's almost always worth it". Why practice bad habits? We should reinforce writing good code -- there's not enough of it out there. There's another advantage to this advice: It would be good practice with the techniques needed to extend or interface to existing codebases. We aren't going to rewrite such existing code, and we generally can't rewrite its interfaces either. So, write good code and then write glue code to the required interface. Seems to me this should be standard practice. And the exercism.io mentors might take this into account... -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
participants (3)
-
Richard O'Keefe -
tbrunz -
xap