Click here to Skip to main content
15,887,596 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
AnswerRe: Why? Pin
Sentenryu19-Sep-12 6:43
Sentenryu19-Sep-12 6:43 
AnswerWe have a winner! Pin
AspDotNetDev19-Sep-12 7:11
protectorAspDotNetDev19-Sep-12 7:11 
JokeThank god the else part is not the same! Pin
VallarasuS12-Sep-12 22:55
VallarasuS12-Sep-12 22:55 
GeneralRe: Thank god the else part is not the same! Pin
Brisingr Aerowing13-Sep-12 16:42
professionalBrisingr Aerowing13-Sep-12 16:42 
GeneralRe: Thank god the else part is not the same! Pin
Bernhard Hiller13-Sep-12 21:15
Bernhard Hiller13-Sep-12 21:15 
GeneralRe: Thank god the else part is not the same! Pin
BillW3319-Sep-12 7:30
professionalBillW3319-Sep-12 7:30 
GeneralRe: Thank god the else part is not the same! Pin
Pete O'Hanlon19-Sep-12 9:20
mvePete O'Hanlon19-Sep-12 9:20 
RantWhat the hell is wrong with people today? Pin
Andrei Straut12-Sep-12 21:59
Andrei Straut12-Sep-12 21:59 
[start rant]

I had to debug some logic code written by a colleague this morning. Now, the guy usually writes his code properly, but this one...

Basically, it drew some 50000 rows from a MySQL table, emptied an Oracle one, inserted those 50000 into the Oracle table, called a stored procedure, updated some stock and price info in the same Oracle table, and then logged the operation info.

Now, all would be well, IF THE GODDAMN THING WASN'T GROUPED IN SINGLE GODDAMN ELEPHANTING 250 LINES METHOD!!!!

And then, those inserts were done 20 by 20 rows, with NOT EVEN FRICKIN' MANUALLY ESCAPED STRINGS!!!
And then, of course those product codes had funky chars in there (\, ', /, " everything you may think of)
And then, of course it had no comments, besides what it was doing with those 20 by 20 inserts!

And just to get a feel of what I'm saying:

C#
string query = "INSERT INTO product_sync_queue_log (price, sku, stock, log_refference) VALUES";
bool first = true;
foreach(Dictionary<string, string> row in rows) {
    insert_data = new StringBuilder();
    
    if(first) {
    	first = false;
    } else {
    	insert_data.Append(", ");
    }
    
    try {
        insert_data
            .Append("(")
            .Append(row["price"].ToString()).Append(", ")
            .Append("\'").Append(row["sku"].ToString()).Append("\', ")
            .Append("\'").Append(row["stock"].ToString()).Append("\', ")
            .Append(log_refference)
            .Append(")");
        
        insert_rows = insert_data.ToString();
        
        // avoid max_allowed_packet size overflow
        if((counter % MAX_INSERT_ROWS) == 0 && counter != 0) {
            command = new MySqlCommand(query + insert_rows + ";", conn);
            command.ExecuteNonQuery();
            
            command = new MySqlCommand(log_query + insert_rows + ";", conn);
            command.ExecuteNonQuery();
            
            first = true;
        }
        
        counter++;
    } catch(Exception e) {
    	Helper.treatException(this.GetType().ToString(), "copyKimProductList - ", e.Message + "\r\n" + e.StackTrace);
    	Helper.treatException(this.GetType().ToString(), "copyKimProductList - DEBUG - SQL Text:", "\r\n" + query + insert_rows + ";");
    	counter++;
    }
}


The first lines in the try - catch are there to make the table insert syntax correct, i.e.
if it's the first row, do not append "," to query if it's not, do the "," append. Which of course fails!

I've just lost almost an hour, which I'll never get back!

[/end rant]
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.

GeneralRe: What the hell is wrong with people today? Pin
Brisingr Aerowing14-Sep-12 2:53
professionalBrisingr Aerowing14-Sep-12 2:53 
GeneralRe: What the hell is wrong with people today? Pin
Andrei Straut14-Sep-12 11:22
Andrei Straut14-Sep-12 11:22 
GeneralContact Us - here, have our email addresses PinPopular
enhzflep30-Aug-12 15:53
enhzflep30-Aug-12 15:53 
GeneralRe: Contact Us - here, have our email addresses Pin
Brisingr Aerowing30-Aug-12 17:19
professionalBrisingr Aerowing30-Aug-12 17:19 
JokeRe: Contact Us - here, have our email addresses PinPopular
Peter_in_278030-Aug-12 17:20
professionalPeter_in_278030-Aug-12 17:20 
GeneralRe: Contact Us - here, have our email addresses (message sent to Lonmin) Pin
enhzflep30-Aug-12 23:46
enhzflep30-Aug-12 23:46 
GeneralRe: Contact Us - here, have our email addresses (message sent to Lonmin) Pin
SoMad31-Aug-12 11:21
professionalSoMad31-Aug-12 11:21 
GeneralRe: Contact Us - here, have our email addresses (message sent to Lonmin) Pin
enhzflep3-Sep-12 15:20
enhzflep3-Sep-12 15:20 
GeneralRe: Contact Us - here, have our email addresses Pin
PIEBALDconsult30-Aug-12 18:54
mvePIEBALDconsult30-Aug-12 18:54 
GeneralRe: Contact Us - here, have our email addresses Pin
Bernhard Hiller30-Aug-12 21:24
Bernhard Hiller30-Aug-12 21:24 
GeneralRe: Contact Us - here, have our email addresses Pin
ekolis31-Aug-12 11:14
ekolis31-Aug-12 11:14 
GeneralRe: Contact Us - here, have our email addresses Pin
enhzflep3-Sep-12 15:11
enhzflep3-Sep-12 15:11 
GeneralHey kids, what day is it? PinPopular
esaulsberry29-Aug-12 3:38
esaulsberry29-Aug-12 3:38 
GeneralRe: Hey kids, what day is it? Pin
Nagy Vilmos29-Aug-12 3:47
professionalNagy Vilmos29-Aug-12 3:47 
GeneralRe: Hey kids, what day is it? PinPopular
OriginalGriff29-Aug-12 4:56
mveOriginalGriff29-Aug-12 4:56 
GeneralRe: Hey kids, what day is it? Pin
BobJanova29-Aug-12 4:58
BobJanova29-Aug-12 4:58 
GeneralRe: Hey kids, what day is it? PinPopular
esaulsberry29-Aug-12 5:05
esaulsberry29-Aug-12 5:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.