Ranges suck!

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 15 00:42:27 UTC 2017


On 09/14/2017 04:53 PM, Your name wrote:

 > Why can't I simply do somestring.strip("\n")???

Actually, you can but that's a different one: std.algorithm.strip and it 
takes the element type, so you should provide a char:

     somestring = somestring.strip('\n');

(Note: I lied about element type because it's actually dchar but let's 
not go there :) )

 > import std.string would be the likely strip yet it takes a range and
 > somestring, for some retarded reason, isn't a range.

It is a range but the error messages cannot be clearer unless the 
compiler is modified.

 > strip isn't the
 > only function that does this. Who ever implemented ranges the way they
 > did needs to get their head checked!

I think this issue is more about templates. You see this more with 
ranges because they are all templates.

 > How bout you make these functions work on strings automatically so it
 > works without moronic errors. Every sane programming(not including D)
 > does not try to toy with the programmer and make them figure out
 > retarded rules that make no sense logically.

I'm sure there are strange usability issues in other programming 
languages as well. :)

 > strip is meant to be used
 > on strings in most cases so having direct and easy access to it should
 > override trying to force ranges down my throat. I'm not a porn star. No
 > other language plays these guys, why does D do it?

I think some of the reason is historical. Any organically grown thing 
necessarily has inconsistencies and compromises that are developed over 
time as new features are added, removed, or moved around. For example, 
many functions from the std.string module were moved to std.algorithm as 
those made sense for other ranges as well.

 > Ok, so I know what your saying "Oh, but strip("\n") should be strip()!
 > Your a moron RTFM!" But why then force me to strip for nothing? Why not
 > pay me? e.g., let me strip for something like strip("x")?

Now you're teasing. ;)

 > Oh, chomp? Is that the function I'm suppose to use? Seriously? Was the D
 > lib written by someone with a pacman fetish?

Agreed overall but everything has reasons that made sense at some point 
to some people. Only languages like Go that had decades of time 
borrowing ideas from other languages and learning from their mistakes 
have a chance of avoiding this but even they have issues and limitations.

Ali



More information about the Digitalmars-d-learn mailing list