maarten van damme:

Is there any way I could've known this?

For me it was "obvious" even before reading the documentation that a remove function is meant to be in-place. But of course you could have different ideas.


(apart from reading the documentation on every single
trivial function in the std library?)

Before using every function from the standard library you have to read its documentation, this is sure. You can not assume its behavour to be exactly the same you hope it to have. This is true for languages as Python too.

Regarding your very quickly written D code, I suggest to decrease the indents size, put a space around operators, put immutable/const to everything that doesn't need to change (unless there are problems doing so). I also suggest to use UFCS chains, because they are more readable for this kind of code. Instead of the readln()[0..$-1] you could chomp, strip or do not retain newlines. Instead of array(splitter) it's simpler to just split. Instead of chain.length==0 it's better to use empty. The foreach usually doesn't need a type, and probably your for loop could written as a better foreach. I also suggest to add contracts to your code. Instead of returning a "can't be solved", probably there are stronger typed solutions, like using an Algebraic or Nullable.

Bye,
bearophile

Reply via email to