|
We've got them too. I have to rely on an in house component that dynamically changes the datasource in a particular GIS file type. You have to give it the path to the file you want to change and a new filename for the changed version. If you pass it two nulls or two empty strings or two strings that have never been anywhere near a valid path or filename, it runs through without a peep. If you pass it a null or empty path and a valid new file name it creates an empty file with the name you gave it. If you feed it with correct parameters it also runs through without making any noise, so every single piece of software that uses this component has to check the paths are valid and that the created file at least isn't empty.
I guess it's taking the single responsibility principle a little too far
|
|
|
|
|
Apparently, my predecessor didn't trust in the C# typing system and... there's more that's wrong with this:
[XmlIgnore]
public DateTime? SomeProperty
{
get;set;
}
public String SomePropertyXml
{
get
{
return SomeProperty.HasValue ? XmlConvert.ToString(SomeProperty.Value) : null;
}
set
{
if (String.IsNullOrEmpty(value as String))
SomeProperty = null;
else
SomeProperty = XmlConvert.ToTimeSpan(value);
}
}
Oh, and I have removed identifiable identifiers, but I haven't removed any comments
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
|
|
|
|
|
Apparently this was written before the Big Bang when the concept of time didn't exist, thus the need for a nullable DateTime property
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
|
|
|
|
|
Oh, that's not even strange in my codebase. We have many nullable DateTime, as optional parameters/informations.
For instance, we have a kind of 'last access date' for files, which is stored as a Nullable<datetime>.
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
|
|
|
|
|
You don't access it on creation? Show me, how do I bake a cake without touching it?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Ok, I'll be more precise then.
I'm working on a media player application, in which you get a list of media files from a webservice.
The DateTime of last playback is null until you have actually played the file.
Does that make sense now?
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
|
|
|
|
|
Makes sense to me ... if you don't know what date something happened on, or if it didn't happen yet, both of which are quite common.
|
|
|
|
|
Clearly your predecessor did not understand either the type system nor TimeSpans.
Just because the code works, it doesn't mean that it is good code.
modified 20-Sep-12 13:11pm.
|
|
|
|
|
Likely both.
I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image.
Stephen Hawking
|
|
|
|
|
I've seen stranger DateTime usage in the Web Service I'm working on. We use a nullable type too, but in this case it was a WTF because Microsoft handed us a WTF with WCF. Stranger is our code that handles a DataSet which has a DateTime column as part of an incoming web request. Whenever we get new developers on board, we watch them when they come across this piece of code. Some of them slump down in their desks and go into a trance, while some quickly walk away and wash their hands with plenty of SOAP.
SG
Aham Brahmasmi!
|
|
|
|
|
Here's a 'nice' pattern I saw in some code I've inherited...
catch (Exception ex)
{
if (ex is ExceptionSpecialType)
throw new SomeException()
{
CustomData = (ex as ExceptionSpecialType).SomeThing.ToXmlString()
};
else
{
throw new SomeException()
{
CustomData = new CustomError(ex).ToXmlString()
};
}
}
Oh, and yes, my predecessor loved using 'if (X is T) (X as T).M();'.
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
|
|
|
|
|
And I thought my custom unrecoverable Exception handling wrapper sucked:
Helper.logUnrecoverable(this.GetType().ToString(), "doSync - createHeader or createLine fail. Action rollbacked", e.Message, true);
Where true is whether it should log the StackTrace or not. But this is a whole different -ness level
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
|
|
|
|
|
Obviously, your predecessor did not have the slightest understanding of proper exception handling. Even reading one article on Code Project about exception would have helped him greatly
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
I've worked with a codebase where each and every method has a try catch block.
The catch logged the error and that's that. As a result, every method you called would return normally like everything went fine.
Something like an Exception or unexpected results when updating a database record could very well be the result of a ReferenceNull- or InvalidCastException somewhere in some method.
Good luck trying to find it
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}
|
|
|
|
|
"Look boss, never any error!"
In Visual Studio, you can set a kind of breakpoints on exceptions just when they're thrown, I guess it could help with that kind of monstrous codebase.
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
|
|
|
|
|
Julien Villers wrote: it could help with that kind of monstrous codebase We would sit and cry in the corner waiting for help... Help never came
It's an OO world.
public class Naerling : Lazy<Person>{
public void DoWork(){ throw new NotImplementedException(); }
}
|
|
|
|
|
WPF by any chance? I was forced to write code like that for it.
He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chineese Proverb]
Jonathan C Dickinson (C# Software Engineer)
|
|
|
|
|
Nope. I'm mostly working in Silverlight, but this is backend code for a webservice, so ASP.NET.
I don't see any reason to 'force' you to write bad exception handling code, ie catching Exception, then testing type.
'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail
|
|
|
|
|
I made the following code, and I stand by it (kind of):
var numTweets = parseInt("<%= NumTweets.ToString() %>", 10);
Can you figure out why I would do such a thing?
|
|
|
|
|
Because your tweets were numb?
|
|
|
|
|
While most tweeters are numskulls, that is not the reason.
|
|
|
|
|
Because you really don't wanna know and don't care about the number of twits?
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
|
|
|
|
|
While true, it's not the reason.
|
|
|
|
|
What's the type of NumTweets? Perhaps it is not an int type and the conversion of it's type to var is different from the conversion of int to var.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
It's an int. This is an ASP.Net page, so the code inside the string is VB.Net and the outside code is JavaScript.
|
|
|
|