On Friday 03 September 2010 10:14:24 bearophile wrote:
> Jonathan M Davis:
> > Still, naming functions is a bit of an art and most function names are
> > debatable as to how good they are, so you're bound to have functions
> > in any API that aren't named the way that you think they should be.
>
>
Jonathan M Davis:
> Still, naming functions is a bit of an art and most function names are
> debatable as to how good they are, so you're bound to have functions
> in any API that aren't named the way that you think they should be.
I don't like what you say.
If you take a look at how in the last
On Friday 03 September 2010 04:35:30 bearophile wrote:
> > canFind isn't really the best possible name, is it?
>
> Some name/APIs of Phobos are not the best possible, they were often
> invented by a single person. I don't know if contains() or isIn() are
> better.
It used to be that all you had w
Pelle:
> bool isRotated(T)(T[] a, T[] b) {
> return a.length == b.length && (a.length == 0 ||
> canFind(chain(a,a), b));
> }
Nice clean solution. I suggest to add "pure" and two "const" in the signature.
> canFind isn't really the best possible name, is it?
Some name/APIs of Phobos are n
On 09/03/2010 01:35 PM, bearophile wrote:
Pelle:
bool isRotated(T)(T[] a, T[] b) {
return a.length == b.length&& (a.length == 0 ||
canFind(chain(a,a), b));
}
Nice clean solution. I suggest to add "pure" and two "const" in the signature.
canFind isn't really the best possible name, i
simendsjo:
> I agree that's much simpler, but s1 ~ s1 doesn't perform too well I
> think. Always creates a new heap allocation and copies the array..
The version written by Pelle is better. On the other hand performance is not an
absolute thing, it's "good enough" or "not good enough", and in ma
Pelle wrote:
On 09/02/2010 10:24 PM, bearophile wrote:
simendsjo:
Suggestions for D-ifying the code is welcome.
Your unit tests are not good enough, they miss some important corner
cases.
This my first version in D2:
import std.string: indexOf;
/// return True if s1 is a rotated version o
On 09/02/2010 10:24 PM, bearophile wrote:
simendsjo:
Suggestions for D-ifying the code is welcome.
Your unit tests are not good enough, they miss some important corner cases.
This my first version in D2:
import std.string: indexOf;
/// return True if s1 is a rotated version of s2
bool isRota
On 02.09.2010 22:24, bearophile wrote:
simendsjo:
Suggestions for D-ifying the code is welcome.
Your unit tests are not good enough, they miss some important corner cases.
This my first version in D2:
import std.string: indexOf;
/// return True if s1 is a rotated version of s2
bool isRotated
> bool isRotated(T)(T[] s1, T[] s2) {
A better signature for the same function, I need to train myself to use pure
and const more often :-)
pure bool isRotated(T)(const T[] s1, const T[] s2) {
Bye,
bearophile
simendsjo:
> Suggestions for D-ifying the code is welcome.
Your unit tests are not good enough, they miss some important corner cases.
This my first version in D2:
import std.string: indexOf;
/// return True if s1 is a rotated version of s2
bool isRotated(T)(T[] s1, T[] s2) {
return (s1.leng
http://stackoverflow.com/questions/2553522/interview-question-check-if-one-string-is-a-rotation-of-other-string
I created a solution, but I don't want D to look bad, so I won't post
it. It's a bit for loop heavy...
At least it's shorter than the c example, but I don't know about speed
or readab
12 matches
Mail list logo