digitalmars.D.learn - Ranges suck!
- Your name (20/20) Sep 14 2017 Every time I go to use something like strip it bitches and gives
- Brad Anderson (19/33) Sep 14 2017 It's not really a range issue. It's that there are two strips.
- =?UTF-8?Q?Ali_=c3=87ehreli?= (23/42) Sep 14 2017 Actually, you can but that's a different one: std.algorithm.strip and it...
- bitwise (12/13) Sep 15 2017 I understand your frustration. The fact that "inout" is actually
Every time I go to use something like strip it bitches and gives me errors. Why can't I simply do somestring.strip("\n")??? import std.string would be the likely strip yet it takes a range and somestring, for some retarded reason, isn't a range. strip isn't the only function that does this. Who ever implemented ranges the way they did needs to get their head checked! 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. 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? 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")? Oh, chomp? Is that the function I'm suppose to use? Seriously? Was the D lib written by someone with a pacman fetish?
Sep 14 2017
On Thursday, 14 September 2017 at 23:53:20 UTC, Your name wrote:Every time I go to use something like strip it bitches and gives me errors. Why can't I simply do somestring.strip("\n")??? import std.string would be the likely strip yet it takes a range and somestring, for some retarded reason, isn't a range. strip isn't the only function that does this. Who ever implemented ranges the way they did needs to get their head checked!It's not really a range issue. It's that there are two strips. One in std.string and one in std.algorithm. The latter which lets you define what to strip rather than just whitespace is what you are looking for and works as you've written. The former is there for legacy reasons and we can hopefully get rid of it in the future to avoid this confusion. I'd also say that you don't seem to be grasping a pretty fundamental D concept yet. std.string.strip doesn't take two arguments, it takes one argument. The first set of parentheses is the template argument which is inferred from the regular argument using IFTI.[snip]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")?strip()! isn't valid syntax. If you want to strip all whitespace you can use std.string.strip (e.g., somestring.strip()). If you want to strip "x" you can use std.algorithm.strip (e.g., somestring.strip("x")). Pretty much like any other language minus the double function mess.Oh, chomp? Is that the function I'm suppose to use? Seriously? Was the D lib written by someone with a pacman fetish?chomp comes to D by way of perl. I don't know whether or not Larry Wall is into pacman or not.
Sep 14 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
Sep 14 2017
On Thursday, 14 September 2017 at 23:53:20 UTC, Your name wrote:[...]I understand your frustration. The fact that "inout" is actually a keyword makes it hard not to think that some very strange fetishes were at play during the creation of this language. As a whole though, the language is very usable, and has many great features not present in similar languages. Just this morning, I was able to replace a fairly large and ugly pile of code with this: import std.utf; foreach(c; myString.byUTF!dchar) { // ... }
Sep 15 2017