Should this work?

Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com> Ola Fosheim Grøstad" <ola.fosheim.grostad+dlang at gmail.com>
Wed Jan 22 13:12:11 PST 2014


On Monday, 13 January 2014 at 12:53:08 UTC, Regan Heath wrote:
> or less what you might call std.string.contains (which does not 
> exist - instead we'd use indexOf != -1.. I think).

Just a side track:

What I dislike about return values as error-indicators is that 
they are arbitrary so you have to memorize "-1", "0", null, 
throws…

I think it is often useful to have user-supplied default and 
sensible naming like having functions that allow testing for 
"0","false","null" as failure ending with "OK" in their name. And 
functions that throws ought to have some kind of assertive name 
like "validate" or a name that explicitly hints at exceptions.

"-1" is really a horrible error value since it fails the "boolean 
test", and e.g. if you want the non-query part of an url, you 
want string length to be the "not found value" when searching for 
"?", not -1:

"http://server.com/page"
"http://server.com/page?query=xyz"


More information about the Digitalmars-d mailing list