|
Thing is, this code has been in production for as least 12 months.
|
|
|
|
|
So Final is obviously valid!
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
At a former place of employment we were told "Names mean nothing." If the function name is "Print" it may not get around to doing any. And for this crapware it was true. Typically functions were not single purpose. They might do 10 different things. These functions would be called by other functions only interested in the output of two of the operations and with the hope that the other eight did not cause any problems.
A colleague and I traced a subroutine down 25 levels making calls to these routines, we totally lost what the intended result was supposed to be and never reached bottom.
Psychosis at 10
Film at 11
|
|
|
|
|
Unless it was filling in an interface (and you have no control over the interface definition; third party, etc.), it's just code bloat. YAGNI: you ain't gonna need it. The best designs have the minimum of moving parts.
|
|
|
|
|
As non-virtual, I agree. I'm just suggesting what reasonable thing the original code might have been trying to do.
|
|
|
|
|
|
It's funny because I know what he was thinking, I still make similar mistakes from time to time.
But when I find myself typing something like this:
if (singleApp.ApplicationId > bestMatch.ApplicationId)
{
bestMatch = singleApp;
}
else
{
bestMatch = singleApp;
}
It's usually a sign that it's time to slap yourself and get go outside for five minutes.
Giraffes are not real.
|
|
|
|
|
Yeah I think we've all written code like that on a bad day. But most of us probably notice immediately and take a little break.
The worst thing about the original example is the way it returns a value and assigns to instance variables, I think (as well as the 'best match' logic being broken, but that's just a mistake, it's not really insidious). It could just return bestMatch and if it's null then there wasn't one, and then it wouldn't have side effects.
|
|
|
|
|
RCoate wrote: protected bool FinalValidation()
{
return true;
}
The more anger towards the past you carry in your heart, the less capable you are of loving in the present.
My Blog![ ^]
|
|
|
|
|
Why don't you just do...
private bool HasApplicationAlready(int appTypeID, int registrationNumber, ref Application app)
{
app = Application().GetApplicationListForContact(DataLocation.OnlineDataBase, Int32.Parse(Profile.RegistrationNumber)).OrderByDescending(s=>s.ApplicationId).FirstOrDefault(s=>s.Application_type_id==appTypeID);
return app==null?false:true;
}
... or something similar?
|
|
|
|
|
Probably because it is a bitch to debug
|
|
|
|
|
Not really.. You get null, or the result you wanted, nothing to debug.
|
|
|
|
|
But if it is null rather than the result you expected and you want to dig in a bit to find where it is going wrong it is a nightmare so you end up expanding it out a bit to trace then perhaps collapsing again once it is working (or more likely leaving well alone). While I like the concept of the single line solution until you can step through the parts I can see why you would validly avoid it.
|
|
|
|
|
Well, when I write code, I write it so it doesn't have to be debugged(almost . Only thing that can go wrong here, would be that the database connection is down, or some sore of foreign key exception. It would result in an exception(with a nice description), but that's a whole different story.
My point is, that I would always rather write(and debug) 2 lines of code, than 22, no mather how complicated they may be...but that's just me...
|
|
|
|
|
also im not sure the lambda notation existed(in c#) when this code was made. i may be wrong.
|
|
|
|
|
The "not so" good old days...
|
|
|
|
|
Now all of your applications are belong to us!
modified 20-Oct-19 21:02pm.
|
|
|
|
|
You need to replace the second bit of code with this:
protected bool FinalValidation()
{
var TimeStamp = new Date();
if(TimeStamp.getDate()%2==1){
return false;
} else {
return true;
}
|
|
|
|
|
So that second gem is not totally useless if it's trying to fill out an Interface of some type. In PHP I've done crazy stuff like this b/c PHP only supports functions in Interfaces so you end with "constants" as "functions".
As to your first case, this has a full boat of failures. That whole block of if... elseif... else -> do the same thing is actually pretty comical. The fact that it's in a for loop and "finds something" but doesn't break is really just odd.
But the kicker to me is that he has sets the app variable and then has a return value of true. Which basically says "hey check the app variable you passed me, I hammered it and returned the app I think I found"
Thank goodness it's private and hopefully caused minimal destruction
|
|
|
|
|
This code reads like someone who codes placeholders and doesn't add comments about why he put in a placeholder. It also reads like code written by certain co-workers who can't code, comes running to you for help, mashes your suggestions into unrecognizable pulp and then presents their "work". Leaving you wondering what they were thinking.
I'll leave placeholders if I get requirements that are a confusing mishmash of illogical thinking. But I'll add comments about why my code is illogical.
|
|
|
|
|
|
Bumped into an interesting “Engineered” approach the other day. Went for a meeting to discuss 2 applications that share many common features. So I was expecting 2 solutions, each sharing a number of projects.
How wrong I was. It turned out to be 2 applications in the one project! I didn't react surprised because I've seen the approach before. One project liberally sprinkled with pre-processor directives.
#if APP_ABC
#else
#endif
Fortunately the developer reassured me he was an Engineer a few times so that made me feel a lot of better.
"You get that on the big jobs."
|
|
|
|
|
What no #if DEBUG vs #if RELEASE bugs in that code? Damn, he's good
You should have asked him if he ever swapped dll's between the applications. That would be great fun
|
|
|
|
|
Interesting approach that dll idea. I think we'll work on that
"You get that on the big jobs."
|
|
|
|
|
My company actually uses such an approach for a Form. The two Forms just happen to look the same.
Every Method looks a bit like this:
If m_screenMode = ScreenMode.ScreenOne Then
Else
End If
Fixing one mode almost always messes up the other one.
Adding Controls to the Form messes up the other one unless you do not forget to hide it etc...
It even got to a point where I had to change the name of the Form at runtime because of some other Classes that need a Formname as parameter...
Really horrible!
It's an OO world.
|
|
|
|