std.algorithm's remove

maarten van damme maartenvd1994 at gmail.com
Sat Aug 24 20:55:24 PDT 2013


>
>  (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.
>

While this is true, one can safely assume that a function called "writeln"
that takes a string will print that string and in the process not alter the
source. (Or at least, that's what I hope to be possible).


> 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 was timing the time it took me to go from exercise to working program. I
figured spamming immutable everywhere would only slow time down while not
increasing productivity (for small programs. If I were to write something
big, that is indeed a must)


> 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.


Hehe, I didn't knew about chomp, thanks for the tip.


> Instead of array(splitter) it's simpler to just split.

also a hidden gem. I always go for my goodies to std.algorithm, I didn't
expect there to be 'duplicates' in std.array as well.


> 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 like to spam types everywhere, it's something I've grown used to. I don't
like the concept of auto (although I do see why it could potentially
increase productivity).

I should've used a foreach loop, I can't remember why I didn't x)


> 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.
>
>
Yes, that was a bit ad-hoc decided. I was hesitating to use some kind of
bool for true-solved and false-unsolved and have the found parameter be by
ref. I came up with something that looks a bit neater now :)

http://dpaste.dzfl.pl/20034431
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130825/0b19c830/attachment.html>


More information about the Digitalmars-d-learn mailing list