|
Not at this level
It's an OO world.
|
|
|
|
|
At every level
(yes|no|maybe)*
|
|
|
|
|
I meant I shouldn't be learning how to return true or false depending on a variable's true or falseness which depends on an expressions true or falseness on which it should not depend at all, which would be false if you just started out, but true after almost a year of programming
Just true with me
It's an OO world.
|
|
|
|
|
Naerling wrote: I meant I shouldn't be learning how to return true or false depending on a variable's true or falseness which depends on an expressions true or falseness on which it should not depend at all, which would be false if you just started out, but true after almost a year of programming
Ok... I definitely like that
(yes|no|maybe)*
modified on Friday, July 1, 2011 5:13 AM
|
|
|
|
|
Good one.
At least you caught yourself.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
Naerling wrote: falseness
Falacy? Falaciousness? Falacio?
|
|
|
|
|
false
[fawls] Show IPA
adjective, fals·er, fals·est, adverb
–adjective
1. not true or correct; erroneous: a false statement.
2. uttering or declaring what is untrue: a false witness.
3. not faithful or loyal; treacherous: a false friend.
4. tending to deceive or mislead; deceptive: a false impression.
5. not genuine; counterfeit.
6. based on mistaken, erroneous, or inconsistent impressions, ideas, or facts: false pride.
7. used as a substitute or supplement, especially temporarily: false supports for a bridge.
8. Biology . having a superficial resemblance to something that properly bears the name: the false acacia.
9. not properly, accurately, or honestly made, done, or adjusted: a false balance.
10. inaccurate in pitch, as a musical note.
–adverb
11. dishonestly; faithlessly; treacherously: Did he speak false against me?
—Idiom
12. play someone false, to betray someone; be treacherous or faithless.
Origin:
before 1000; Middle English, Old English fals < Latin falsus feigned, false, orig. past participle of fallere to deceive; reinforced by or reborrowed from Anglo-French, Old French fals, feminine false < Latin
—Related forms
false·ly, adverb
false·ness, noun
half-false, adjective
qua·si-false, adjective
qua·si-false·ly, adverb
—Synonyms
1. mistaken, incorrect, wrong, untrue. 2. untruthful, lying, mendacious. 3. insincere, hypocritical, disingenuous, disloyal, unfaithful, inconstant, perfidious, traitorous. 4. misleading, fallacious. 5. artificial, spurious, bogus, forged. False, sham, counterfeit agree in referring to something that is not genuine. False is used mainly of imitations of concrete objects; it sometimes implies an intent to deceive: false teeth; false hair. Sham is rarely used of concrete objects and usually has the suggestion of intent to deceive: sham title; sham tears. Counterfeit always has the implication of cheating; it is used particularly of spurious imitation of coins, paper money, etc.
Falseness!
It's an OO world.
|
|
|
|
|
|
Greetings - Jacek
|
|
|
|
|
Looks like a good basis for a recursive function
If my jokes make me laugh, then I have already succeeded with 100% of my target audience
|
|
|
|
|
The next time someone tells you that true always returns true I want you to ask that person a question. Ask that person: Have you tested it? Frankly, when I see your code I see an excellent place to put a unit test.
|
|
|
|
|
In preparation for some redevelopment work, I was having a look through some legacy code provided by a contractor. I have a feeling that it does not do exactly what the comments suggest it does.
private bool HasApplicationAlready(int appTypeID, int registrationNumber, ref Application app)
{
bool foundOne = false;
List<Application> matches = new Application().GetApplicationListForContact(DataLocation.OnlineDataBase, Int32.Parse(Profile.RegistrationNumber));
Application bestMatch = null;
foreach (Application singleApp in matches)
{
if (singleApp.Application_type_id.GetValueOrDefault(0) == appTypeID)
{
if (bestMatch == null)
{
bestMatch = singleApp;
}
else
{
if (singleApp.ApplicationId > bestMatch.ApplicationId)
{
bestMatch = singleApp;
}
else
{
bestMatch = singleApp;
}
}
}
}
if (bestMatch != null)
{
app = bestMatch;
foundOne = true;
}
else
{
foundOne = false;
}
return foundOne;
}
Another gem I found was:
protected bool FinalValidation()
{
return true;
}
|
|
|
|
|
The second gem was really funny.
Good judgment comes from experience, and experience comes from bad judgment. Barry LePatner
...it's our division that makes us sane(r), and their unity that makes them crazy. Ian Shlasko
|
|
|
|
|
Yes, although if it were virtual, it could make sense. Even as it stands if it's a placeholder for something to be added later, it makes sense. (If public, I'd say it was probably an interface implementation; I often have trivial methods or property getters for that purpose.)
|
|
|
|
|
BobJanova wrote: Even as it stands if it's a placeholder for something to be added later, it makes sense.
I agree. But I find it funny to have a method called FinalValidation and does no validation at all. Maybe I just have a weird sense of humor.
Good judgment comes from experience, and experience comes from bad judgment. Barry LePatner
...it's our division that makes us sane(r), and their unity that makes them crazy. Ian Shlasko
|
|
|
|
|
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?
|
|
|
|
|