Author |
Topic |
DavidChel
Constraint Violating Yak Guru
474 Posts |
Posted - 2008-10-22 : 15:38:53
|
Ever take a new job and look at the code your predecessor wrote and ask, "Who wrote this crap?" I've had this experience a couple of times, but now I'm finding it in my own work. I've been learning SQL programming fairly rapidly thanks to you folks. I look at code I wrote even a few months ago, and I feel compelled to re-write it as it looks like crap to me now. I'm sucking less and less everyday, and I thank you folks for it. |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-10-22 : 15:41:41
|
yep... been there, done that..._______________________________________________Causing trouble since 1980Blog: http://weblogs.sqlteam.com/mladenpSpeed up SSMS development: www.ssmstoolspack.com <- version 1.1 out! |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-10-22 : 15:45:19
|
I had this happen a few years back. It was terrible code in a stored procedure. The author put a comment header block with his name, so I was able to identity the culprit. He was a past consultant for our company. The funny thing though is that I took a .NET programming class from him a couple of years after I saw the stored procedure. I made sure to ask him about it. In his defense, the system was on SQL Server 6.5 when he wrote it. We had since upgraded it to SQL Server 2000, but that code was brought over as is. If only it were possible to upgrade it to 2005 or 2008...I also have a similar story for someone that I've seen as an author on a SQL book. Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-10-22 : 16:13:01
|
David -- You may enjoy/appreciate http://www.TheDailyWTF.com if you haven't already heard of that site. There are quite a few datbase/SQL "WTF" entries there if you browse around, I am not sure if you program in other languages as well. Lots of the non-code stories (such as the job interview ones) are pretty funny as well.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-23 : 00:25:05
|
I used to have lots of such experiences when i worked for maintainence project. Most of work was related to some legacy systems which were handed over to us. it has some really crappy codes. one of instances that immidiately comes to my mind was case when there was a need to cross tab a table and get about 15 values as columns and author had used 14 self joins to same table to get each one of those columns. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-10-23 : 00:40:29
|
Every single day Not a day pass by before I have to rewrite a procedure because of performance problems.The last few months, I have rewritten some procedures (which all uses cursors) so they now is much faster and uses less resources.To one procedure I added a function and that procedure is now 3500 times faster. Before 2.25 hours, now 2 seconds.One procedure took (yes, with cursors) about 2.5-3.0 hours to complete. Rewrote that so it now runs in under 2.25 minutes.60 times faster.And so on, and on, and on... I am in cursor hell right now.I don't say cursors are all bad, but it's rare that cursors outperforms set-based logic. I posted some example just the other day with an example of WHERE CURRENT OF.I have used a cursor-based solution twice the last five year in favor of set-based solution. Twice out of some thousands. E 12°55'05.63"N 56°04'39.26" |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-23 : 02:58:38
|
I almost change all unnecessary dynamic sql and ineffecient date handlingsMadhivananFailing to plan is Planning to fail |
 |
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2008-10-23 : 06:15:35
|
quote: Originally posted by Peso Every single day Not a day pass by before I have to rewrite a procedure because of performance problems.The last few months, I have rewritten some procedures (which all uses cursors) so they now is much faster and uses less resources.To one procedure I added a function and that procedure is now 3500 times faster. Before 2.25 hours, now 2 seconds.One procedure took (yes, with cursors) about 2.5-3.0 hours to complete. Rewrote that so it now runs in under 2.25 minutes.60 times faster.And so on, and on, and on... I am in cursor hell right now.I don't say cursors are all bad, but it's rare that cursors outperforms set-based logic. I posted some example just the other day with an example of WHERE CURRENT OF.I have used a cursor-based solution twice the last five year in favor of set-based solution. Twice out of some thousands. E 12°55'05.63"N 56°04'39.26"
First thing to do is find out who wrote them originally, then find them and shoot them! If it was yourself, there is no exceptions.. There is hardly ever any excuse for a cursor. |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-10-23 : 07:04:39
|
quote: Originally posted by Peso Every single day Not a day pass by before I have to rewrite a procedure because of performance problems.
I know the feeling. My company started with 2 java programmers and no sql guys. They coded a lot of the stored procs in the following way:1) No ANSI joins2) everything based on tight little loops.3) No indexes(bizarrely their schema choices at least seem fairly good apart from this)Everything was fine while we were a little company with little clients and small datasets. Now, not so much :)I rewrote some payroll code last week that was taking 13 hours to run. It now takes 2 minutes and will probably still work on 2008!-------------Charlie |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-10-23 : 07:11:23
|
quote: Originally posted by DavidChel Ever take a new job and look at the code your predecessor wrote and ask, "Who wrote this crap?"
And, I have thought this then realised it was code that *I* wrote about 2 years ago. Things like that make you realise how much you've learned over time. I probably will look back to the stuff I'm writing now and think the same-------------Charlie |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-10-23 : 12:22:26
|
Some years ago I worked for a software company that purchased another software company. Almost all the stored procedures for that system were written using cursors and often multiple layers of nested cursors. It was almost impossible for me to work on this code without producing huge performance improvements. There was a weekly purchasing job that went from 14 hours to 2 minutes, a physical inventory job that went from 16 hours to 1 minute, and a month-end purchasing job that went from 35 hours to 20 seconds.When I ran the month-end purchasing job in production for the first time it took me some time to convince the end-users that the job had actually run, and not failed. They had been so used to the month-end process being this terrible ordeal that left the system down for over a day that it was hard for them to believe the nightmare was over.I often thought about trying to track down the consultants that wrote the original code to get a list of their former clients. I figured that I could earn an easy living coming in behind them to clean up the messes that they left behind.CODO ERGO SUM |
 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2008-10-23 : 13:20:40
|
quote: Originally posted by Transact Charlie I probably will look back to the stuff I'm writing now and think the same-------------Charlie
We're building tomorrow's performance problems WebfredNo, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
graz
Chief SQLTeam Crack Dealer
4149 Posts |
Posted - 2008-10-23 : 17:54:32
|
I'm very proud of the signature I use for my posts on this forum:=================================================Creating tomorrow's legacy systems today. One crisis at a time. |
 |
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-10-23 : 18:32:20
|
quote: Originally posted by Transact Charlie
quote: Originally posted by DavidChel Ever take a new job and look at the code your predecessor wrote and ask, "Who wrote this crap?"
And, I have thought this then realised it was code that *I* wrote about 2 years ago. Things like that make you realise how much you've learned over time. I probably will look back to the stuff I'm writing now and think the same-------------Charlie
I learned to avoid my old mistakes; I'm making all new mistakes. CODO ERGO SUM |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-10-24 : 07:39:17
|
Just had a wtf moment.Consider the following logic: (assume that there are masses of spaghetti sql written by various engineers with different view on how to (or not) format SQL in between also) The cursors were obviously more complex than this.........DECLARE @Id INTDECLARE @staffNumber VARCHAR(255)/* MASSES OF SPAGHETTI HERE */DECLARE zempInnerCur CURSOR FORSELECT e.[staffNumber]FROM employee eWHERE e.[Id] = @Id/* MASSES OF SPAGHETTI HERE */DECLARE empOuterCur CURSOR FORSELECT [Id]FROM employeeOPEN empOuterCur FETCH NEXT FROM empOuterCur INTO @Id WHILE ( @@FETCH_STATUS = 0 ) BEGIN /* MASSES OF SPAGHETTI HERE */ OPEN zempInnerCur FETCH NEXT FROM zempInnerCur INTO @staffNumber WHILE ( @@FETCH_STATUS = 0 ) BEGIN /* MASSES OF SPAGHETTI HERE */ FETCH NEXT FROM zempInnerCur INTO @staffNumber END CLOSE zempInnerCur FETCH NEXT FROM empOuterCur INTO @Id ENDCLOSE empOuterCurDEALLOCATE empOuterCurDEALLOCATE zempInnerCur Urgh! declaring a cursor that references a variable that hasn't had a value assigned to it yet? great plan.-------------Charlie |
 |
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2008-10-24 : 10:11:18
|
I recently had the opposite experience actually...I came across a piece of code I wrote several years back and I thought "da**, this is good shi*!!" - Lumbago |
 |
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2008-10-24 : 10:21:54
|
...and this sentence just made my day: "I'm sucking less and less everyday, and I thank you folks for it." That's EXACTLY how I feel too...that bad part is that the more I learn the more I realise I don't know - Lumbago |
 |
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2008-10-24 : 10:35:58
|
>> that bad part is that the more I learn the more I realise I don't knowthat's not the bad part, that's the best part! elsasoft.org |
 |
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2008-10-24 : 11:27:39
|
quote: Originally posted by Lumbago I recently had the opposite experience actually...I came across a piece of code I wrote several years back and I thought "da**, this is good shi*!!" - Lumbago
I looked at some of the serious $hit I designed back in school N years ago.... I just realized that I did learn a lot from my boring professor.It made me want to drop him off a Xmas card this year... hehe |
 |
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-10-24 : 12:21:58
|
quote: Originally posted by Michael Valentine Jones Some years ago I worked for a software company that purchased another software company. Almost all the stored procedures for that system were written using cursors and often multiple layers of nested cursors. It was almost impossible for me to work on this code without producing huge performance improvements. There was a weekly purchasing job that went from 14 hours to 2 minutes, a physical inventory job that went from 16 hours to 1 minute, and a month-end purchasing job that went from 35 hours to 20 seconds.When I ran the month-end purchasing job in production for the first time it took me some time to convince the end-users that the job had actually run, and not failed. They had been so used to the month-end process being this terrible ordeal that left the system down for over a day that it was hard for them to believe the nightmare was over.I often thought about trying to track down the consultants that wrote the original code to get a list of their former clients. I figured that I could earn an easy living coming in behind them to clean up the messes that they left behind.CODO ERGO SUM
Holy cow!!!! |
 |
|
|