count vs length ( vs size)
Posted: Mon Aug 01, 2011 12:52 am
One thing that strikes me as less than optimal is that .NET has two names for methods for obtaining the number of items in something depending on the something ( how sensible is that)
Arrays and strings use .length
Collections(lists and Maps, etc) use .count
For common usage I find this tends to make a bit of a cognitive dissonance with use of Strings vs everything else
along the lines of a mind-check
'must use .count to get the size of anything except if its a String use .length'
....
'aaaaaaaaaaaarghh'
( as an aside Java does something similar though here its .length vs .size and best practices suggest use of .count for user code.
insert-smiley-for-upchuck-here ( and scream x 2 ).
Normally It would be of no import to flatten this out and add a .count to do the same thing in Strings ( and perhaps arrays though thats less of an issue ( use Lists rather than arrays)) but thats precluded since the current cobra std library already has a String extension called .count.
unaccountably ( hehehe) and unlike the most common use of .count elsewhere (like in Collections wrt .Net naming) , here it takes an arg
( bang! - brain falls over...., developer runs screaming around the room, cat takes cover)
So - checking this, the current cobra arged version uses .count(c as char) to count occurrences of a particular char in a string.
(recently changeset 2583 adds same for a substring - which is what reminded me of this purulent and cancerous lesion in cobras otherwise blemish free complexion).
Its used in a few places in the compiler each of which causes for a me a minor wtf moment when I chance across it ......
(I hate wtf moments - it causes a disturbance in my sense of oneness and general feelings of slight competence..)
The lib version is doing a count of a particular something (rather than a count of everything in the item/Object - like Collections ) so why is it not named .countOf - huh, huh, huh ??
- do you feel lucky punk - do ya ...... whoops, drifting off.
If theres any agreement to any of this I volunteer to make a patch that corrects this ( existing count-> countOf, add count alias for length , fix compiler code, add tests, sing from hilltop, dance in street, etc, etc)
(pardon the purple prose).
Arrays and strings use .length
Collections(lists and Maps, etc) use .count
For common usage I find this tends to make a bit of a cognitive dissonance with use of Strings vs everything else
along the lines of a mind-check
'must use .count to get the size of anything except if its a String use .length'
....
'aaaaaaaaaaaarghh'
( as an aside Java does something similar though here its .length vs .size and best practices suggest use of .count for user code.
insert-smiley-for-upchuck-here ( and scream x 2 ).
Normally It would be of no import to flatten this out and add a .count to do the same thing in Strings ( and perhaps arrays though thats less of an issue ( use Lists rather than arrays)) but thats precluded since the current cobra std library already has a String extension called .count.
unaccountably ( hehehe) and unlike the most common use of .count elsewhere (like in Collections wrt .Net naming) , here it takes an arg
( bang! - brain falls over...., developer runs screaming around the room, cat takes cover)
So - checking this, the current cobra arged version uses .count(c as char) to count occurrences of a particular char in a string.
(recently changeset 2583 adds same for a substring - which is what reminded me of this purulent and cancerous lesion in cobras otherwise blemish free complexion).
Its used in a few places in the compiler each of which causes for a me a minor wtf moment when I chance across it ......
(I hate wtf moments - it causes a disturbance in my sense of oneness and general feelings of slight competence..)
The lib version is doing a count of a particular something (rather than a count of everything in the item/Object - like Collections ) so why is it not named .countOf - huh, huh, huh ??
- do you feel lucky punk - do ya ...... whoops, drifting off.
If theres any agreement to any of this I volunteer to make a patch that corrects this ( existing count-> countOf, add count alias for length , fix compiler code, add tests, sing from hilltop, dance in street, etc, etc)
(pardon the purple prose).