|
a Stored procedure is given a name and called from code, while ad query writes it's own query (select, update, insert, delete). Is there anything else we need to know about?
|
|
|
|
|
I know I posted an example of this a while ago, but here's another classic example, and I thought some of the other bits in this snippet may amuse you ...
For j = 1 To k
char = UCase(Mid$(myField, j, 1))
If InStr(delims, char) <> 0 Then
If i <> j Then
buffer = Mid$(myField, i, j - i)
GoSub addIndex ' Nooooooooooooooooooooooooooooooooooooooo
End If
i = j + 1
End If
Next j
If i <> j Then
buffer = Mid$(myField, i, j - i)
GoSub addIndex
End If
a bit later in the same routine...
addIndex:
If IsNull(buffer) Then Return
buffer = Left$(Trim$(buffer), 20)
If Len(buffer) = 0 Then Return
wordnum = libWordNo(Trim(utilRemoveCrap(buffer)))
If wordnum = 0 Then Return
If InStr(wordsNow, ";" & CStr(wordnum) & ";") = 0 Then
wordsNow = wordsNow & CStr(wordnum) & ";"
End If
If InStr(wordsThen, ";" & CStr(wordnum) & ";") <> 0 Then Return
retSet.AddNew
retSet![AccountNumber] = recSet![AccountNumber]
retSet![recordNumber] = recNum
retSet![wordNo] = wordnum
retSet.Update
Return
I should also mention that there's a variable in the same routine called wordNo, and one called wordNum.
Classy stuff.
That dull thudding you can hear in the distance is my head banging against the desk.
|
|
|
|
|
wordNo is probably a boolean. If the buffer contents are an actual word, then wordNo contains false. But if the buffer contetns are not a word, then wordNo contains true.
wordNum is what happens to you after reading all this code. My brain is now num(b).
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]
|
|
|
|
|
I've devised a new technique for dealing with this kind of code.
When el-coder-loco is at lunch, you sneak over and change some tiny part of the code. A plus to a minus, a True to a False, something small.
Then they spend the next six months trying to debug the tangled mess that they've created.
Keeping them out of your way.
-Rd
Hit any user to continue.
|
|
|
|
|
Wow! A fantastic tecnique!
|
|
|
|
|
|
A great suggestion, but as he retired a while ago...
At least I have the good sense to clear up after me
|
|
|
|
|
Rob Grainger wrote: but as he retired a while ago...
Let that not be an obstacle. A banana in a tailpipe can give a guy many days of debugging fun.
Childish? perhaps, but you'll feel better.
-Rd
Hit any user to continue.
|
|
|
|
|
This anti-pattern is scattered all over the place.
bool bStandardMandatory = false;
bool CheckStandardMandatory()
{
if (cbReportDefinitions.SelectedItem != null)
{
var rep = cbReportDefinitions.SelectedItem;
bStandardMandatory = _presenter.Controller.CheckMandatory(rep, "Standard");
return bStandardMandatory;
}
return false;
}
The only other place that touches bStandardMandatory :
bStandardMandatory = CheckStandardMandatory();
Please tell me who teaches this stuff to people?
Can I cry now?
|
|
|
|
|
What about the implementation in _presenter.Controller? Is it:
bool bMandatory = false;
bool CheckMandatory()
{
if (someCondition)
{
...;
bMandatory = _someMember.CheckMandatory(..., "Standard");
return bMandatory;
}
return false;
}
with only one other place that touches bMandatory :
bMandatory = CheckMandatory();
|
|
|
|
|
|
I don't know who their teacher was, but I have worked with several folk who must have and the same teacher!
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
private bool ContainsFilename(string reportfilename, string rdlcfilename)
{
return ((reportfilename.Contains(rdlcfilename)) ? true : false);
}
Today is gonna be a long day...
|
|
|
|
|
O_o! Just returning the value without casting it to boolean first! Definitely a horror!
|
|
|
|
|
Jeroen De Dauw wrote: Just returning the value without casting it to boolean first! Definitely a horror!
That's the minor part
The person should just be calling string.Contains() .
Now I have to fix this crap and 100's of similar crap pieces of code just to understand it.
|
|
|
|
|
leppie wrote: Now I have to fix this crap and 100's of similar crap pieces of code just to understand it.
Yeah, I hate working with superior programmers who write stuff like this that they can understand, but I can't.
I still remember with awe the greatest programmer I ever worked with.
Functions were hundreds of lines long, at his best he could write functions that were thousands of lines long.
I would just gaze at it like a dog that's just seen a card trick, but he would roll up his sleeves and fix problems all day long.
Not a try or a catch to be seen. Why would he need them? Only losers hit exceptions.
Yeah, he was a fricken genius.
-Rd
Hit any user to continue.
|
|
|
|
|
Yeah, I have worked with several programmers like that. They usually impress management because they are so "productive". They create very large amounts of code. Code that is not robust, very difficult to maintain and contains hard to find bugs, but those things are not important after all.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
Apologies, apparently I forgot to include my sarcasm sign.
|
|
|
|
|
I can't see the problem, logically it works:
if the reportfilename Contains rdlcfilename is true, return true, otherwise return false
Truly awful. If I'm honest, I've written a few functions like this, but only in the middle of a protracted refactoring session in the middle of the night. Next morning such functions do tend to "disappear" before other people see them .
|
|
|
|
|
|
But only to management.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
You clearly forgot to litter the methods with Debug.Assert statements. Eg:
result = true;
Debug.Assert(result == true);
You have to remember being very wary of the compiler, it has a mind of its own.
|
|
|
|
|
Or maybe Pascal.
class A
{
private:
public:
bool operator==(const A &rhs) const { return (this == &rhs); }
bool operator=(const A &rhs) const
{
}
bool operator!=(const A &rhs) const { return (!operator=(rhs)); }
};
|
|
|
|
|
Awesome! Just what I need to make my code work.
.....................
Life is too shor
|
|
|
|
|
Seriously, this should be outlawed. Why use redefine the == operator to compare the addresses, not the values, of the operands? Why redefine the assignment operator to perform a comparison? C++ might be thought to be a horrible language by some (sometimes including me), but why make it even worse by redefining operators to have inconsistent semantics?
I truly desire that the author of that code die a horrible death.
Eduardo León
|
|
|
|