Distribution of test method name length
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)... [image: image.png] 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 <kksubbu.ml@gmail.com> wrote:
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 ].
Ahh, yes. Blame evolution of the Playground code between when I used it and when I copied it here.
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.
yes. but I was checking each stage as it grew incrementally.
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 ]]]] ````
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 21-06-2019, at 2:35 AM, Ben Coman <btc@openinworld.com> wrote:
On Fri, 21 Jun 2019 at 12:43, K K Subbu <kksubbu.ml@gmail.com <mailto:kksubbu.ml@gmail.com>> wrote: 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 ].
Ahh, yes. Blame evolution of the Playground code between when I used it and when I copied it here.
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.
yes. but I was checking each stage as it grew incrementally.
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 ]]]] ````
cool
cheers -ben
On Mon, 24 Jun 2019 at 07:10, Jerry Kott <jkott@image-ware.com> wrote:
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.
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/wor... ) 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 [image: image.png]
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
participants (4)
-
Ben Coman -
Jerry Kott -
K K Subbu -
Kasper Osterbye