Wheels that keep on turning..
-
..and reinventing themselves. It's as if I can take any random file in the solution today and find parts of the CLR reimplemented. Some more totally pointless gems:
public static List<T> GetList<T>(params T[] items) { List<T> list = new List<T>(items.Length);
list.AddRange(items); return list;
}
public static int GetCount<T>(IEnumerable<T> enumerable) { int count = 0;
// This construction avoids the "Local variable not used" // warning that shows up when using foreach. using (IEnumerator<T> enumerator = enumerable.GetEnumerator()) { while (enumerator.MoveNext()) ++count; } return count;
}
public static T[] ToArray<T>(IEnumerable<T> items) { List<T> list = new List<T>(items);
T[] oidArray = new T[list.Count]; list.CopyTo(oidArray); return oidArray;
}
What's really disappointing is the fact that nobody wrote any unit tests for these. We've got a number of devs who simply don't trust the CLR and will happily write unit tests for public static auto getters, so why were these missed?
-
@JimLahey said:
public static List<T> GetList<T>(params T[ items)
{
List<T> list = new List<T>(items.Length);list.AddRange(items); return list;
}
You're right - this is a bunch of people who don't trust the CLR and (worse) won't read the documentation.
This function was, I guess, created because the think that ToList() retuns the original list, rather than a copy.
-
Actually there was no .ToList() in.Net 2.0. There was, however, a List<T> constructor that takes an IEnumerable as input... Though it doesn't accept its input as params.
There was no enumerable counting method in .Net 2.0 either. One of the reasons was probably that some enumerables can only be enumerated once.
However, the third example has no excuse for not using List<T>.ToArray()!
-
@Medinoc said:
ctually there was no .ToList() in.Net 2.0.
My bad, I forgot to add that it's a 3.5 app.
-
@JimLahey said:
but did it start life in a older version?@Medinoc said:
ctually there was no .ToList() in.Net 2.0.
My bad, I forgot to add that it's a 3.5 app.
-
@JimLahey said:
@Medinoc said:
ctually there was no .ToList() in.Net 2.0.
My bad, I forgot to add that it's a 3.5 app.
Has it always been a 3.5 app, or was it 2.0 upgraded to 3.5? I've seen similar constructs in those situations.
-
And now for something completely different: Assimilator, what is your icon?
-
@The_Assimilator said:
Has it always been a 3.5 app, or was it 2.0 upgraded to 3.5? I've seen similar constructs in those situations.
That's a good question. As far as I and SVN are aware, it started out as a 3.5 app. There is however, a very good chance that the offending code was copypasted from a 2.0 app though - copy paste and code reuse are two completely interchangeable terms at our place.
-
-
@flabdablet said:
@dhromed said:
Assimilator, what is your icon?
Loving Google image search!
That is some awesome magicks I have lernt today.
-
First prize to flabdablet. And yes, I <3 Motoko Kusanagi.
-
@dhromed said:
That is some awesome magicks I have lernt today.
An alternative (TinEye) - which shows these results.
Available as a handy browser plugin for those right-click moments.
-
Woo!
-
@dhromed said:
And now for something completely different: Assimilator, what is your icon?
It appears to be animes. I've seen a lot of animes in my day and I think that's animes.
-
@blakeyrat said:
It appears to be animes. I've seen a lot of animes in my day and I think that's animes.
I like to call it Japanimation sometimes just to rile people up.
-
@Nexzus said:
@blakeyrat said:
It appears to be animes. I've seen a lot of animes in my day and I think that's animes.
I like to call it Japanimation sometimes just to rile people up.
Racist! You don't call Disney cartoons Honkyanimation!