Worst source code EVER
-
There was this code they wrote a SQL Server stored procedure just for completing a string with zeroes to the left until its maximum length, in pseudo code it was like this:
if value.Length < 2
value = "0000000" + value
else
if value.Length < 3
value = "000000" + value
else
if value.Length < 4
value = "00000" + value
else
if value.Length < 5
value = "0000" + value
else
if value.Length < 6
value = "000" + value
else
if value.Length < 7
value = "00" + value
else
if value.Length < 8
value = "0" + valueWhen I saw this, I was like :omg: and wondered what else I was going to find :~. I feared that I would :(( on the course of this project and really hoped no to :sigh: along the way. In the end I had a lot of :doh:
"To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson
I had to do something similar recently to fix all the data in a column in a SQL DB cos the leading zeros had been lost in the data export. I think I did if length < 8 value = "0" + value and kept running it over and over until it changed no records. In my defense I don't really know SQL. More recently I had to stick trailing zeros back on that had been lost by an export routine (123456.789 exported and becomes 123456789, 123456.700 exports as 123456.7 and needs to become 123456700). I have to do this in xpath, which I am also just starting with. I would hate to post what I have come up with to achieve that.
Every man can tell how many goats or sheep he possesses, but not how many friends.
-
I had to do something similar recently to fix all the data in a column in a SQL DB cos the leading zeros had been lost in the data export. I think I did if length < 8 value = "0" + value and kept running it over and over until it changed no records. In my defense I don't really know SQL. More recently I had to stick trailing zeros back on that had been lost by an export routine (123456.789 exported and becomes 123456789, 123456.700 exports as 123456.7 and needs to become 123456700). I have to do this in xpath, which I am also just starting with. I would hate to post what I have come up with to achieve that.
Every man can tell how many goats or sheep he possesses, but not how many friends.
ChrisElston wrote:
I think I did if length < 8 value = "0" + value and kept running it over and over until it changed no records.
Can I assume you used a loop? Because that's completely different. Imagine if the guy that coded the sample I provided had to do this for a 255 characters field. You get the idea right? I really hope you didn't do the same. And worse, this was a procedure on database for a common task of the application.
ChrisElston wrote:
I would hate to post what I have come up with to achieve that.
:~
"To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson
-
Okay, last day or so ago, I asked what your favorite programming job was. Now, what is the worst, nastiest, ugliest source code you ever saw and what made it so horribly bad? Not commented (heh heh yeah, as if) or one-letter (or zero-letter?) variable names? Written in a dead programming language that should be dead, but your client is still using it for some God-awful reason? The list goes on...so spew!
Sincerely Yours, Brian Hart
After reading some of the responses, I guess I am lucky. However, one of the worse was at my last job I had to constantly fix bugs in my college's code. He almost always used two letters for variable names. All data tables were "dt" for example. Probably the worst was that he always used "ln" for "Last Name" and also used it for "Loan Number". (Banking applications) What a mess, you never knew what you were looking at. When stepping through the code I would be in one module looking at the Last Name and the next thing I knew, I was in another module looking at the Loan Number thinking "what happen"?
-
Okay, last day or so ago, I asked what your favorite programming job was. Now, what is the worst, nastiest, ugliest source code you ever saw and what made it so horribly bad? Not commented (heh heh yeah, as if) or one-letter (or zero-letter?) variable names? Written in a dead programming language that should be dead, but your client is still using it for some God-awful reason? The list goes on...so spew!
Sincerely Yours, Brian Hart
The worst I have come across so far is a vb program where the one sub is 2600 lines long. Yes I said "the one sub" :confused: I had to update that from VB 6 to 2010, took a few days to just figure out the flow of the application as it jumped all over the place with GOTO's. I hope who ever replaces me at some point in time finds the new version much easier to follow. There were some comments but they were things like "s = the count of something" not what was actually trying to be accomplished or anything...
-
A month or two ago I got to see this Java codebase that I was supposed to work on; whoever wrote it apparently was a fan of this incredibly awesome (NOT!) paradigm I like to call "Hashtable Oriented Programming"... Basically, all business-tier classes implement a BusinessObject interface, which contains four methods: loadFromDb, saveToDb, a third one I can't remember, and the infamous getHashtable... The classes themselves do indeed implement these methods... and nothing else - no bean-style getters or setters! That's right, a Loan object has the exact same structure as a Realtor object; the only difference is the convention of "which keys do we stick in the hashtable?" It's almost as if they were trying to implement some sort of dynamically typed language on top of Java... just with none of the advantages, and all of the disadvantages! Thankfully I've been transferred to another project, so I don't have to mess with that nonsense! edit: Now I remember what the third method was... it was isInDb! This method was implemented rather... erratically, one might say: several of the classes implemented it by executing "select count(*) from theTable" and comparing to zero; if the count was not zero, the object was "in" the database! And no, I doubt that there were all THAT many "singleton tables" in the DB!
My project in a nutshell, they even did this with the session user object in a web application. A couple dozen columns accessible by name only, shared across the entire subsequent processing flow. The column names were aliased in the query so they didn't necessarily match the actual database names either. Then, to add insult to injury, any exceptions caught in any DML (insert, update, delete) simply put a zero in the rowcount value and calmly return. The caller has no other option but to wonder if no rows were affected or an error occurred. Since it's a server app, all the logs are hidden behind an alligator filled moat of: 1. A VPN account which not only kills your local network access (folder shares, email, printers, etc.), but also a roaming profile which makes it impossible to open an application from the start menu once the VPN connection is up. 2. Constantly expiring UNIX account passwords with limited file access privileges. (DEV environments included)
-
SAP requires costly, difficult-to-manage programmers be available in very large numbers so that one may be sacrificed daily to appease the beast! The same thing goes for Oracle ERP too!
-
And its more verbose but equally horrible Java cousin:
try {
mystery1();
mystery2();
mystery3();
mystery4();
theRestOfTheProgram();
} catch(Exception e) {};I've been bitten by that a few times, testing something that is not behaving as it should, but not producing any error messages. What's the point of having exceptions, and just as importantly, a managed language with automatic line-numbered stack traces etc, if you're going to suppress all of that goodness? :omg:
I've done this for ONE specific... case... now I wonder if there's a better way or if given the context it would be considered excusable. A file or a database call, I don't remember which that can fail via exception. Thing is, I believe the defaults were suitable, I was just checking the db/file for more correct values. That may not be exactly it (I really don't remember...) and if I left it empty I'd think comments explaining WHY would be neccessary. The rest of these comments are making me feel a lot better about my file and function length ^_^;;
-
I was hired to port a case management system for intellectual properties (patents, trademarks, etc) to Java/EE. It was written in Power Basic (Sybase 3.5 GL language) by someone who learned programming in C64 basic. I have not seen such clutter before in my life. I found huge blocks of code that literally could've been removed, countless dependencies on global variables, ugly SQL (they often stored their queries in the database - WTF?). Such a mess. I still have nightmares. On several occasions, my design decisions were overridden by their management. One case involved user role management. I proposed the standard role/object/model that is well understood. They agreed, but refused to understand basic set theory. An empty set of access rights would mean "all access to everything" according to them. I responded that is a bad idea, and makes security administration overly complex, and potentially insecure. They would not understand (even after countless of negative use cases). I implemented their stupid ideas. Later on they did not want to pay for my work on the role management, because "it was implemented badly". WTF? They said I did not implement it according to their specifications. Guess what? The "specifications" was my original design! I told them I don't do business with liars, and we went to court. I got half in a settlement. If I had wanted 100% of what they owed, the case would've taken at least one more year. I don't want to spend time in court, I want to create, so I grabbed the 50% and vowed to myself not to fall into that trap again. I was screwed royally on that gig. Code wise and business wise. I have also encountered code for an installer driver that was spaghetti in several dimensions. Structure wise, and thread wise! The code had bugs that the original authors could not track down in 6 months. I spent two weeks with a colleague trying to track it down. I just gave up and kept bugging the management until I was approved to ditch the code, and rewrite it. It turned out that another division in the company had written a really good installer driver, so the story had a good ending!
-- Kein Mitleid Für Die Mehrheit
Jörgen Sigvardsson wrote:
they often stored their queries in the database - WTF?
Haven't you ever heard of a "stored procedure?" :laugh:
-
Okay, last day or so ago, I asked what your favorite programming job was. Now, what is the worst, nastiest, ugliest source code you ever saw and what made it so horribly bad? Not commented (heh heh yeah, as if) or one-letter (or zero-letter?) variable names? Written in a dead programming language that should be dead, but your client is still using it for some God-awful reason? The list goes on...so spew!
Sincerely Yours, Brian Hart
The worst code I have seen lately was a .net application that had been updated from through the .net versions .net 1.1 to .net 4 using the vs migration update tools but other than sorting out a couple of build errors no changes were made. I was asked to review the code for the company and to add some additional functionality. I was told it would only take a few days. it was terrible created over time by about several consultants hired over the years it had the joy of using 4 of the .net languages (java.net, c#, vb (which is bad enough on its own), and c++) a couple of purchased library for .net 1.1 still being used in .net 4 version, all in a single project no comments never sticking to a single coding style, variable names were just funny words and no unit testing at all. (oh it was also not in version control and was mission critical to the company) Having explained all this o the boss using pretty pictures and fancy words I spent 4 days putting it in to version control and adding in the new functionality to the code that they wanted, and making it live. I then had 10 weeks of fun sorting the whole hornets mess out. The first few weeks converting all the code into just one language c# just to make life easier and adding some basic unit tests. Then started to actually get the code up to scratch and taking advantage of .net 4.0 changes and even the use of masterpages, after about 6 weeks efforts getting the code up to scratch the source code was less than half the size their was unit testing and a heck of alot of major bugs were fixed. Alas after all that effort and actually getting accurate reports about the state of the company from the app they learnt the company was doing crap (were as before due a error were negative were being treated as positive numbers in the finacial system), the company decided ot hire some consultants who advised to move to a purchased system, the company is now bust shame but managements fault.
Good luck
-
ON ERROR RESUME Nothing more, nothing less...
Software Kinetics Wear a hard hat it's under construction
Metro RSSNorm .net wrote:
ON ERROR RESUME
Nothing more, nothing less...This one beats yours:
On Error Resume Next
'Do Somthing
Err.Clear()
On Error Resume Next
'Do Somthing
Err.Clear()
On Error Resume Next
'Do Somthing
Err.Clear()
On Error Resume Next
'Do Somthing
Err.Clear()
...And it goes on for every single line in the code.
-
Jörgen Sigvardsson wrote:
they often stored their queries in the database - WTF?
Haven't you ever heard of a "stored procedure?" :laugh:
Lol! I guess they put the newbie in charge of the stored procedures... :-D
-- Kein Mitleid Für Die Mehrheit
-
Okay, last day or so ago, I asked what your favorite programming job was. Now, what is the worst, nastiest, ugliest source code you ever saw and what made it so horribly bad? Not commented (heh heh yeah, as if) or one-letter (or zero-letter?) variable names? Written in a dead programming language that should be dead, but your client is still using it for some God-awful reason? The list goes on...so spew!
Sincerely Yours, Brian Hart
One system that I worked on about 10 years ago, required a heck of a lot of database work. We were on SQL Server 6.5, and the database collation was set up so that code was case sensitive. The big problem on this project was that developers loved writing these monser stored procedures that were thousands of lines long. The stored proc in question was about 2000 lines long, and riddled with the same variable names, with different cases, e.g. @PatientRx @patientRx @patientrx @PATIENTRX @Patientrx @PatientRX This wasn't limited to one variable either, but multiple variables. I eventually re-wrote the stored proc after about a week of trying to figure it out.
-
Okay, last day or so ago, I asked what your favorite programming job was. Now, what is the worst, nastiest, ugliest source code you ever saw and what made it so horribly bad? Not commented (heh heh yeah, as if) or one-letter (or zero-letter?) variable names? Written in a dead programming language that should be dead, but your client is still using it for some God-awful reason? The list goes on...so spew!
Sincerely Yours, Brian Hart
A quick list of the things I've seen: ON ERROR RESUME starting every routine Using 70 textboxes to simulate a spreadsheet Everytime the database was opened it was never closed Everytime data was retrieved it was using 'Select * from', even when getting 1 field Variables declared and never used, and Variables used that were never Declared, both in the same routines. Creating temporary records in the database and never deleting them. A whole section dedicated to an internal email system, in a program where a majority of the clientele were mom & pop used car dealers with 1 computer. All of these were in the same code I was hired to maintain. I eventually gave up trying to wade through fixing it and re-wrote the entire program in my spare time.
-
Okay, last day or so ago, I asked what your favorite programming job was. Now, what is the worst, nastiest, ugliest source code you ever saw and what made it so horribly bad? Not commented (heh heh yeah, as if) or one-letter (or zero-letter?) variable names? Written in a dead programming language that should be dead, but your client is still using it for some God-awful reason? The list goes on...so spew!
Sincerely Yours, Brian Hart
Let's see, this was years ago. FORTRAN. Uncommented? Of course, real programmers don't use comments. (I'm not a real programmer.) This subroutine was about 5000 lines long, label numbers randomly organized, goto statements all over the place, going up/down and if he could do it, sideways. Some of the code, I'm sure is dead because I can't see any way to reach it, but I'm not about to remove it because I've been wrong before.