Working on the Exercism project to shorten generated test method names,
for comparison I reviewed the length of test method names in Pharo 7. So just for curiousity value, here is that graph (done in Excel)... Data generated by... classes := Object allSubclasses select: [ :cc | cc isKindOf: TestCase class ]. methods := c flatCollect: [ :c | c allMethods ]. tests := methods select: [ :m | m selector beginsWith: 'test' ]. lengths := tests collect: [ :m | m selector size ]. lengths asBag keysAndValuesDo: [ :len :count | Transcript crShow: len; show: ','; show: count ] cheers -ben |
Nice graph, Ben! The larger test names (selector size > 100) look more
like sentences than names ;-). On 21/06/19 6:50 AM, Ben Coman wrote: > classes := Object allSubclasses select: [ :cc | cc isKindOf: > TestCase class ]. > methods := c flatCollect: [ :c | c allMethods ]. Did you mean classes flatCollect: here? > tests := methods select: [ :m | m selector beginsWith: 'test' ]. > lengths := tests collect: [ :m | m selector size ]. select:thenCollect: can also be used here. > lengths asBag keysAndValuesDo: [ :len :count | Transcript crShow: > len; show: ','; show: count ] I find the in: selector very handy for quick commands without having to use undefined temps. e.g. ```` (Object allSubclasses select: [ :cc | cc isKindOf: TestCase class ]) in: [ :classes | (classes flatCollect: [ :c | c allMethods ]) in: [ :methods | (methods select: [ :m | m selector beginsWith: 'test' ] thenCollect: [ :m | m selector size ]) in: [:lengths | lengths asBag keysAndValuesDo: [ :len :count | Transcript crShow: len; show: ','; show: count ]]]] ```` Regards .. Subbu |
On Fri, 21 Jun 2019 at 12:43, K K Subbu <[hidden email]> wrote: Nice graph, Ben! The larger test names (selector size > 100) look more Ahh, yes. Blame evolution of the Playground code between when I used it and when I copied it here.
yes. but I was checking each stage as it grew incrementally.
cool cheers -ben |
Interesting…
I am curious about the purpose of this analysis (other than the ‘interesting-ness’ of it). Sure, some names read like sentences, but that beats the ’strcpy()’, doesn’t it? I love that in Smalltalk / Pharo, I don’t have to remember cryptic function names and can make the code optimally verbose (if there is such a thing) to express intent. If that means a method is rather long, so be it. Jerry Kott This message has been digitally signed. PGP Fingerprint: A9181736DD2F1B6CC7CF9E51AC8514F48C0979A5
|
On Mon, 24 Jun 2019 at 07:10, Jerry Kott <[hidden email]> wrote:
Its an offshoot of working on the Pharo Track of the Exercism project (https://exercism.io/tracks/pharo-smalltalk) Here we generate test-method names from their canonical data "description" (https://github.com/exercism/problem-specifications/blob/master/exercises/word-count/canonical-data.json) The original intent of that field was to generate identifiers, but sometimes the language ends up a bit flowery and we ended up with method-name 150 character long. I am in the process of slimming these down. Someone queried me "what was a recommended identifier length" and I had no clue -- so I thought the Pharo code base would be a good source of data. Having produced the graph, I thought others might find it mildly interesting. Thats all. It may be worthwhile reviewing some of the outliers, but that was not its intent. It was shared just-for-interest. The purpose is certainly not to squeeze Pharo messages down to 6 characters ;) cheers -ben P.S. I found the graph more useful showing percentages rather than absolute count. 95% less than 50 characters 99% less than 60 characters |
Quite interesting! I was wondering about the correlation to number of arguments due to the particularities of the keyword syntax which might give longer method names in the first place.
Best, Kasper |
Free forum by Nabble | Edit this page |