On 2010-02-20 19:12:21 -0500, Andrei Alexandrescu
<seewebsiteforem...@erdani.org> said:
But how about others? What is the overall convention?
In my module the convention was to always start the name with
"consume". I had "consumeOneChar" with a predicate checking one
character, "consumeOneString" for matching specific strings (same as
your "startWith"), "consumeWhile" and "consumeUntil" taking a character
predicate, "consumeCount" for repeating consuming something, etc.
Through the module, "consume" is implying I am reading from the front
of the string and consuming from there.
Also don't forget that many other languages have startsWith. I don't
find hasPrefix terribly informative. a.hasAsPrefix(b) would be more
like it, but then again Yigal's fantastic consistent naming scheme
remains elusive.
Cocoa's NSString use hasPrefix (that's where I got the idea). To me
both sound right. assert("exoplanet".hasPrefix("exo")). :-)
I don't really have a problem with startWith, it just doesn't fit very
well with "consume". But if like me you assume "from the front" to be
implicitly part of the meaning of "consume", then you don't need the
"startWith" part. :-) You could use "consumeFront" to make things
absolutely clear.
--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/