Would you laugh or cry?
-
Lol, awesome. Though I can imagine at least a few reasons why this would sort of make sense.
- If somebody moved all the string handling functions to a single class so they don't have to remember the location of all of them, that would make some sense. Not much, but some.
- If somebody was working with a tool that requires a function be exposed by a custom class in order to make use of it. For example, I work with an open source tool called Umbraco, and it makes heavy use of XSLT. In order to use a built-in .Net Framework function from XSLT, I have to create a wrapper function and change some configuration settings to let the XSLT know which DLL to use.
- IsNullOrEmpty was new to .Net Framework 2.0. If they were using a version of .Net before 2.0, they may have created their own implementation, then replaced it with the .Net version.
Option #1: If I were the boss and this was the case, the guy who did this would be gone (if I could find out who it was, that is) :-D Option #2: Pretty sure that's not the case here; it is actually a class inside a framework used for building other apps. Option #3: Perhaps yes. I suppose this could explain it. Although as far as I am aware, I believe it was originally written in .NET 2 already. Maybe the guy came from using .NET 1 and didn't realise this was there in 2.0. :-s LOL.
-
Not so long ago, I came across this:
public class StringUtils
{
public bool IsNullOrEmpty(string s)
{
return string.IsNullOrEmpty(s);
}
}What a gem, hey? I don't know whether to laugh or cry...
-
The simple idea of making this kind of stuff is simply horrid, but the fact that this horrid method is not static is still more horrifying.
-
LOL. Actually, my bad; I was quickly writing it up out of memory - I do believe it was static. I dont think anyone can be that idiotic. If I find someone like that, I'm definitely packing my bags and moving on to other things! :-D
gordon_matt wrote:
I dont think anyone can be that idiotic.
Be careful when you say that. Code is like the Darwin Awards... You never know when some moron with a PhD comes up with what they "think" is a great idea...
I wasn't, now I am, then I won't be anymore.
-
LOL. Actually, my bad; I was quickly writing it up out of memory - I do believe it was static. I dont think anyone can be that idiotic. If I find someone like that, I'm definitely packing my bags and moving on to other things! :-D
in that case, could it be that it was written like this:
public static class StringUtils
{
public static bool IsNullOrEmpty(this string s)
{
return string.IsNullOrEmpty(s);
}
}then you can simplify the calling code a bit:
string a = "11";
string b = "";
string c = null;
Console.Out.WriteLine("a -> {0}, b -> {1}, c -> {2}", a.IsNullOrEmpty(), b.IsNullOrEmpty(), c.IsNullOrEmpty());instead of
Console.Out.WriteLine("a -> {0}, b -> {1}, c -> {2}", string.IsNullOrEmpty(a), string.IsNullOrEmpty(b), string.IsNullOrEmpty(c));
I wouldn't argue if this is a bad practice or not, but it makes some sense at least (ignoring the issue of calling a seemingly instance method on null reference)
-
in that case, could it be that it was written like this:
public static class StringUtils
{
public static bool IsNullOrEmpty(this string s)
{
return string.IsNullOrEmpty(s);
}
}then you can simplify the calling code a bit:
string a = "11";
string b = "";
string c = null;
Console.Out.WriteLine("a -> {0}, b -> {1}, c -> {2}", a.IsNullOrEmpty(), b.IsNullOrEmpty(), c.IsNullOrEmpty());instead of
Console.Out.WriteLine("a -> {0}, b -> {1}, c -> {2}", string.IsNullOrEmpty(a), string.IsNullOrEmpty(b), string.IsNullOrEmpty(c));
I wouldn't argue if this is a bad practice or not, but it makes some sense at least (ignoring the issue of calling a seemingly instance method on null reference)
-
Not so long ago, I came across this:
public class StringUtils
{
public bool IsNullOrEmpty(string s)
{
return string.IsNullOrEmpty(s);
}
}What a gem, hey? I don't know whether to laugh or cry...
As it turns out, the company was using this framework for building apps for a particular customer, but that wasn't good enough, they wanted to sell the framework as well, so basically the devs were told to beef up the package a bit... *speechless* This certainly explains a few oddities in this "Framework"... Moral of the story: if you're going to outsource, get a dev to review the code before paying for anything. LOL & shaking head at same time...
-
As it turns out, the company was using this framework for building apps for a particular customer, but that wasn't good enough, they wanted to sell the framework as well, so basically the devs were told to beef up the package a bit... *speechless* This certainly explains a few oddities in this "Framework"... Moral of the story: if you're going to outsource, get a dev to review the code before paying for anything. LOL & shaking head at same time...
-
Option #1: If I were the boss and this was the case, the guy who did this would be gone (if I could find out who it was, that is) :-D Option #2: Pretty sure that's not the case here; it is actually a class inside a framework used for building other apps. Option #3: Perhaps yes. I suppose this could explain it. Although as far as I am aware, I believe it was originally written in .NET 2 already. Maybe the guy came from using .NET 1 and didn't realise this was there in 2.0. :-s LOL.
-
Option 1: If you can't find out who did it, the code is the least of your problems. Has your boss ever heard of source control :omg:
-
Not so long ago, I came across this:
public class StringUtils
{
public bool IsNullOrEmpty(string s)
{
return string.IsNullOrEmpty(s);
}
}What a gem, hey? I don't know whether to laugh or cry...