|
When I joined my current company about three years ago, I was given the task of maintaining the company's business critical order processing system. This is written as an Access front end to a SQL Server back end, and was written by a contractor who had left at the end of his contract with a large amount of the company's money in his bank account!
Some investigation after my first week or two lead me to discover the following horrors:
There was not a single error trapping routine in the whole front end - if something fell over, the standard error message was "an error occurred in the click event of btn....."
Each routine that inserted a record was written as a Sub, rather than a function that returned a success/failure value.
Every user on the database was assigned DBO permissions!
There was absolutely no referential integrity defined in the database.
There was no transaction processing in the system - if someting fell over part way through (as it often did), updates/inserts/deletes had to be rolled back manually using Enterprise manager.
An example of his coding style is shown here - it shows how he retrieved a single record using its primary key:
Set rstMain = New ADODB.Recordset
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "spSELocationForSageImport"
Set prm = cmd.CreateParameter("@LocationCode", adVarChar, adParamInput, 20, "Sage")
cmd.Parameters.Append prm
cmd.CommandType = adCmdStoredProc
rstMain.Open cmd, , adOpenDynamic, adLockOptimistic, adCmdStoredProc
With rstMain
Do While Not .EOF
strLocation = ![Location]
.MoveNext
Loop
End With
Set rstMain = Nothing
Maybe I'm missing something, but do you need to loop though a dataset that can only contain one record?
His date handling was also a bit esoteric:
txtDateCreated = Month(Now()) & "/" & Day(Now()) & "/" & Year(Now())
I recently had occasion to rewrite some of his code that applied changes from an external system to the database. His code took two or more hours to run and slowed the system so much it was unusable (meaning I usually had to do unpaid overtime to apply the data out of hours). One of the lovely bits of code he wrote looped through a data set of 7000+ records, taking a value from each record and using this as a parameter in a stored procedure that retrieved a related value from a lookup table. Changing the source query of the main dataset to join it to the lookup table and return the value directly removed 7000+ executions of the stored procedure.
Tweaking the query, adding an index and cleaning up his code reduced the run time to approximately 3 minutes!
====================================
Transvestites - Roberts in Disguise!
====================================
|
|
|
|
|
I have the feeling that the guy in question once read a chapter on ADO and has abused the same example ever since ....
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Hehe, I basically suggested the same
|
|
|
|
|
Chris Quinn wrote: Maybe I'm missing something, but do you need to loop though a dataset that can only contain one record?
Because it returns a list with 0 or more values. Or maybe he only knew that single pattern
|
|
|
|
|
As the others have said, it does look like he found some example and kept using it over and over. Pretty much any VBA coding in Access is a strong candidate for being a coding horror.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
I don't agree - it's not the tool you use - it's the tool that uses it!
====================================
Transvestites - Roberts in Disguise!
====================================
|
|
|
|
|
True. Access can be alright when used correctly.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
By default, Access should be removed from the PC of anybody who is tempted to open it up and knock together a crappy app with zero understanding of basic database procedures. Hello. It's called normalization people, and it's not an optional extra. If you don't understand normalisation, then you should be in a more touchy-feely career and not one that demands reaching higher than a 2 on the clue-o-meter.
|
|
|
|
|
Yeah. Anyone wanting to use access should in addition to being required to pass the 'not excel' test for data design, also understand why changes are saved immediately instead of when you click the save icon. [my younger sister}, who creates single flat table dbs and never manages to grasp why I explain it isn't bundled in the cheap version of office, I mean you.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
dan neely wrote: it isn't bundled in the cheap version of office
Thanks to God for that
We have Access 2007 installed in the labs at my college where I teach and I took one look at it, and never looked at it again
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
At the risk of sounding like a fool, could I ask you to please explain the bit about changes being saved immediately instead of when the save icon is clicked.
|
|
|
|
|
Databases have implicit save behaviour, e.g. triggered by an action such as moving to a new row. An application like Excel does not know when you want to save the data, so it only saves when you trigger an explicit save.
|
|
|
|
|
Okey doke -- but this is only the case when there is data binding between the database and the client right? I'm sure there must be plenty of apps out there, other than Excel, that required an explicit save.
I'm not sure if I get the point that was originally being made. Was this being suggested as a good thing, a bad thing, or just an example of where the "developer" mis-understood what was going on?
|
|
|
|
|
This was a case of a luser insisting on using the wrong tool (access instead of excel), and then continually whining about how it didn't do what she wanted.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Pete O'Hanlon wrote: Access should be removed from the PC of anybody who is tempted to open it up and knock together a crappy app with zero understanding of basic database procedures. Hello. It's called normalization people, and it's not an optional extra. If you don't understand normalisation, then you should be in a more touchy-feely career and not one that demands reaching higher than a 2 on the clue-o-meter.
Amen to that
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Comeon I have written several VBA programs both nothing as horrible as that.
|
|
|
|
|
|
Sad: I have to maintain code like this.
|
|
|
|
|
Transactions are a blessing. Writing code to undo all changes after an error is no fun at all. And how do you proceed when even more errors pop up while undoing things?
Unfortunately you don't always have transactions. I'm working on a larger project that uses a MySql database for both low cost and speed. Using another table format would make transactions available, but also slow everything down in an unacceptable manner. So I guess, the only choice is dealing with some tight spots in the buisiness logic.
A while ago he asked me what he should have printed on my business cards. I said 'Wizard'.
I read books which nobody else understand. Then I do something which nobody understands. After that the computer does something which nobody understands. When asked, I say things about the results which nobody understand. But everybody expects miracles from me on a regular basis. Looks to me like the classical definition of a wizard.
|
|
|
|
|
the point was to do 2 column reversable order sorting, i wrote this thing as an intern.. have fun guys and gals.
int t1 = 0;
int t2 = 0;
string temp = "";
string orig = "";
if (lblSortOrder.Text==e.SortExpression)
{
Trace.Write("asdf","in order switcher");
lblSortOrder.Text +=" DESC";
}
else if (lblSortOrder.Text.IndexOf(e.SortExpression)== -1)
{
Trace.Write("asdf","in column adder");
temp=e.SortExpression;
temp+=", "+lblSortOrder.Text;
lblSortOrder.Text=temp;
}
else if (lblSortOrder.Text.IndexOf(',')!=-1)
{
if (lblSortOrder.Text.IndexOf(e.SortExpression)!=-1)
{
orig=lblSortOrder.Text;
t1=orig.IndexOf(e.SortExpression);
t2=orig.IndexOf(",",t1)-t1;
if(t2>=0)
{
temp=orig.Substring(t1,t2);
}
else
{
temp=orig.Substring(t1);
}
if(temp.IndexOf("DESC")!=-1)
{
orig=orig.Remove(t1,temp.Length);
temp=temp.Remove(temp.IndexOf("DESC"),4);
temp=temp.Trim();
}
else
{
orig=orig.Remove(t1,temp.Length);
temp+=" DESC";
temp=temp.Trim();
}
orig=orig.Trim();
lblSortOrder.Text=temp+","+orig;
}
else
{
lblSortOrder.Text=e.SortExpression;
}
}
else
{
lblSortOrder.Text=e.SortExpression;
}
lblSortOrder.Text=lblSortOrder.Text.Replace(",," , ",");
lblSortOrder.Text=lblSortOrder.Text.Replace(", ," , ",");
t1=lblSortOrder.Text.IndexOf(",",lblSortOrder.Text.IndexOf(",")+1);
if(t1>10)
{
lblSortOrder.Text=lblSortOrder.Text.Remove(t1,(lblSortOrder.Text.Length-t1));
}
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Several years ago I was asked to evaluate a C program. The question was: can we fix it, or do we need to rewrite it?
What the program did and for whom doesn't matter, other than it should have been a straightforward business application: user-interface screens and database reads and updates.
The client was concerned that the program - used daily by several people for real work - was "flaky" and would often lock up or BSOD after 15-20 minutes.
So I started looking at the code...and found several interesting things:
- the program was using invisible pop-up windows as temporary data buffers to implement wizard-like operations in the user-interface, and never deallocating them.
- every variable was global
- there were no data structures anywhere for anything
- there were no functions other than those required by the GUI
- several functions were over 75 pages long - that's about 4500 lines of code in a single function
- the level of code redundancy was incredible; it was common to see the same 5-10 lines of code repeated several dozen times within the same function
Naturally, my recommendation was that the system be rewritten, preferably in an object-oriented language [which we did, but that was a Success Story, not a Horror Story].
My curiosity could not be held back, I had to know who had written this program...
This program was written by a COBOL programmer. It was her first C program, and her first GUI program.
I asked what happened to her. They said she got a job with a larger firm in the same industry just down the street - teaching C programming!
|
|
|
|
|
You know, those who can't code, manage. Those who can't manage... you know where they end up at..
|
|
|
|
|
|
Steven A. Lowe wrote: the program was using invisible pop-up windows as temporary data buffers to implement wizard-like operations in the user-interface, and never deallocating them.
Ahead of its time: garbage collection without the collection!
Steven A. Lowe wrote: every variable was global
But think of all the stack space you have!
Steven A. Lowe wrote: there were no data structures anywhere for anything
Or you could think of it as a data structure everywhere for everything.
Steven A. Lowe wrote: there were no functions other than those required by the GUI
Again, think of the saved stack space!
Steven A. Lowe wrote: several functions were over 75 pages long - that's about 4500 lines of code in a single function
But I bet Intellisense was nice and responsive.
Steven A. Lowe wrote: the level of code redundancy was incredible; it was common to see the same 5-10 lines of code repeated several dozen times within the same function
Man, haven't you heard of code reuse??
Faith is a fine invention
For gentlemen who see;
But microscopes are prudent
In an emergency!
-Emily Dickinson
|
|
|
|
|
David Kentley wrote: Ahead of its time: garbage collection without the collection!
5!
|
|
|
|