Over 1200 lines of pure WTFness



  • Since I'll be leaving my current company soon it's about time to publish some more WTFs I had to deal with during the 4 years I have been here. This was my first programming job after graduating from Uni, so I wouldn't be too surprised if I ever see some of my code showing up here. Especially the first programs I wrote here are very WTFy and looking back at them I would do MANY things different today.

    But hey, at the very least I can say I have never produced code such as THIS:

    public partial class Form1 : Form
    {
        DataSet ds; //DataSet for SQLSrv\Customer\dbo....
        DataSetTableAdapters.DSTableAdapter _ds; //Customer-TableAdapter
    
        public Form1()
        {
            //For calling from table - SQLSrv\Customer\dbo....
            ds = new DataSet();
            _ds = new Customer.DataSetTableAdapters.DSTableAdapter();
    
            InitializeComponent();
        }      
        private void Form1_Load(object sender, EventArgs e)
        {
            String line, TESTO; //String to read from row 
            decimal total = 0, RDN = 0, Amount = 0;
            int alreadythere = 0, number = 0, right = 0, header = 0, write = 0;
            this._ds.Fill(this.ds.CustTable);            
    
            // Check file path
            DirectoryInfo di = new DirectoryInfo("\\\\path\\to\\file");
            foreach (FileInfo fi in di.GetFiles("*.FileEnding", SearchOption.TopDirectoryOnly))
            {
                textBox1.AppendText("Data record 1" + "\r\n");
                textBox2.AppendText("Data record 2" + "\r\n");
                alreadythere = 0; right = 0;
                try
                {
                    try
                    {   //Checks if file has been processed or not
                        for (int i = 0; i <= this.ds.CustTable.Count; i++)
                        {                            
                            if (this.ds.CustTable[i].Datei == fi.ToString())
                            {
                                alreadythere = 1; //Is file already there
                            }
                            else
                            {
                            }
                        }
                    }
                    catch 
                    {
                    }
    
                    if (alreadythere == 1) //File is already there and isn't processed any further
                    {
                        textBox1.Clear();
                        textBox2.Clear();
                    }
                    else
                    {       
                        //Read this area: [area1Begin] to [area1End]
                        StreamReader preReader1 = new StreamReader(fi.DirectoryName + "\\" + fi.ToString(), Encoding.GetEncoding(1252));
                        try
                        {
                            while ((line = preReader1.ReadLine()) != null)
                            {
                                textBox1.AppendText(line.Substring(line.IndexOf("[area1Begin]"), line.IndexOf("[area1End]")) + "\r\n");
                                right = 1;
                            }
                        }
                        catch 
                        {
                            textBox1.Clear();                            
                        }
    
                        //Read this area: [area1End] bis [area1End] (LastIndexOF)
                        StreamReader preReader2 = new StreamReader(fi.DirectoryName + "\\" + fi.ToString(), Encoding.GetEncoding(1252));
                        try
                        {
                            while ((line = preReader2.ReadLine()) != null)
                            {                                
                                if (line.Substring(0, 7) == "[area1Begin]")
                                {
                                    textBox2.AppendText(line.Substring(line.IndexOf("[area1End]"), line.LastIndexOf("[area1End]") - line.IndexOf("[area1End]")) + "\r\n");
                                    right = 1;
                                }
                            }
                        }
                        catch
                        {
                            textBox2.Clear();
                        }
    
                        //Read this area: [area2Begin] to [area2Begin] (LastIndexOF)
                        StreamReader preReader3= new StreamReader(fi.DirectoryName + "\\" + fi.ToString(), Encoding.GetEncoding(1252));
                        try
                        {
                            while ((line = preReader3.ReadLine()) != null)
                            {                               
                               
                            }
                        }
                        catch
                        {
                        }
    
                        //Should file be processed?
                        if (right == 1)
                        {
    
                        //Save read areas in this path "\\\\path\\to\\file\\file_prepare1.csv"
                        try
                        {
                            if (File.Exists("\\\\path\\to\\file\\file_prepare1.csv"))
                            {
                                System.IO.File.Delete("\\\\path\\to\\file\\file_prepare1.csv");
                            }
                            else
                            {
                            }
    
                            StreamWriter file1 = new StreamWriter("\\\\path\\to\\file\\file_prepare1.csv", true, Encoding.Default, 1024);
                            {
                                file1.WriteLine(textBox1.Text);
                                file1.Close();
                            }
                        }
                        catch
                        {
                            Application.Exit();
                        }
    
                        //Save read areas in this path "\\\\path\\to\\file\\file_prepare2.csv"
                        try
                        {
                            if (File.Exists("\\\\path\\to\\file\\file_prepare2.csv"))
                            {
                                System.IO.File.Delete("\\\\path\\to\\file\\file_prepare2.csv");
                            }
                            else
                            {
                            }
    
                            StreamWriter file1 = new StreamWriter("\\\\path\\to\\file\\file_prepare2.csv", true, Encoding.Default, 1024);
                            {
                                file1.WriteLine(textBox2.Text);
                                file1.Close();
                            }
                        }
                        catch
                        {
                            Application.Exit();
                        }                        
    
                        textBox1.Clear();
                        textBox2.Clear();
    
                        try
                        {
                            for (int i2 = 0; i2 <= this.ds.CustTable.Count; i2++)
                            {
                                number = i2;
                            }
                        }
                        catch
                        {
                        }
    
                        textBox1.AppendText("Data record 1" + "\r\n");        
                            DataSet.CustTableRow addrow = this.ds.CustTable.NewCustTableRow();
                            number = number + 1;
                            addrow.Nr = number;
                            addrow.Pfad = fi.DirectoryName;
                            addrow.Datei = Convert.ToString(fi.ToString());
                            addrow.File_found_date = DateTime.Now;      
    
                            //Read buffered areas
                            try
                            {
                                using (CsvReader csv1 = new CsvReader(new StreamReader("\\\\path\\to\\file\\file_prepare1.csv", Encoding.Default), true, ';'))
                                {
                                    while (csv1.ReadNextRecord())
                                    {
                                        try
                                        {
                                            textBox1.AppendText(csv1[0].Substring(0, csv1[0].IndexOf("ENT-") + 63) + "\r\n");
                                        }
                                        catch
                                        {
                                            textBox1.AppendText(csv1[0].Substring(0, csv1[0].IndexOf("ENT-") + 43) + "\r\n");
                                        }
                                    }
                                }
                            }
                            catch 
                            {                                
                            }
    [snip... repeat this 27 times, each time with a different starting index for Substring]
    
                            //Save read areas in this path "\\\\path\\to\\file\\file_wrapup.csv"
                            try
                            {
                                if (File.Exists("\\\\path\\to\\file\\file_wrapup.csv"))
                                {
                                    System.IO.File.Delete("\\\\path\\to\\file\\file_wrapup.csv");
                                }
                                else
                                {
                                }
    
                                StreamWriter file1 = new StreamWriter("\\\\path\\to\\file\\file_wrapup.csv", true, Encoding.Default, 1024);
                                {
                                    file1.WriteLine(textBox1.Text + textBox2.Text);
                                    file1.Close();
                                }
                            }
                            catch
                            {
                                Application.Exit();
                            }
    
                            //Read needed data
                            textBox1.Clear();
                            textBox2.Clear();                            
                            textBox2.Visible = false;
                            textBox3.Visible = false;
    
                            try
                            {   
                                using (CsvReader csv1 = new CsvReader(new StreamReader("\\\\path\\to\\file\\file_wrapup.csv", Encoding.Default), true, ';'))
                                {
                                    while (csv1.ReadNextRecord())
                                    {
                                        try
                                        {
                                            if (csv1[0].Substring(csv1[0].IndexOf("000905"), 6) == "000905")
                                            {
                                                textBox1.AppendText(csv1[0].Substring(csv1[0].IndexOf("000905") + 19, 8) + ";" + csv1[0].Substring(csv1[0].IndexOf("000905") + 27, 10) + ";" + "670" + csv1[0].Substring(csv1[0].IndexOf("ELV") + 6, 6) + ";" + csv1[0].Substring(csv1[0].LastIndexOf("ME") - 12, 5) + "." + DateTime.Now.ToString("yyyy") + ";");
                                                Program.naechste = csv1[0].Substring(csv1[0].IndexOf("000905") + 19, 8) + ";" + csv1[0].Substring(csv1[0].IndexOf("000905") + 27, 10);
    
                                                try
                                                {
                                                    if (csv1[0].Substring(csv1[0].IndexOf("SELF") + 14, 5) == "BECAUSE")
                                                    {
                                                        textBox1.AppendText("because of objection" + ";");
                                                    }
                                                    else
                                                    {
                                                        textBox1.AppendText("shortage of cover" + ";");
                                                    }
                                                }
                                                catch
                                                {
                                                    textBox1.AppendText("shortage of cover" + ";");
                                                }
    
                                                try
                                                {
                                                    Amount = Convert.ToDecimal(csv1[0].Substring(csv1[0].IndexOf("ENT-") - 7, 7));                                                    
                                                    textBox1.AppendText(Amount + ";");
                                                }
                                                catch (Exception EXC)
                                                {
                                                    MessageBox.Show(EXC.Message + "\r\nField: Amount");
                                                }
    
                                                try
                                                {
                                                    RDN = Convert.ToDecimal(csv1[0].Substring(csv1[0].IndexOf("FOREIGN") + 5, 5)) + Convert.ToDecimal(csv1[0].Substring(csv1[0].IndexOf("FOREIGN") + 5, 5));
                                                    textBox1.AppendText(RDN + ";");
                                                }
                                                catch (Exception EXC)
                                                {
                                                    MessageBox.Show(EXC.Message + "\r\nField: RDN");
                                                }
    
                                                try
                                                {
                                                    total = Convert.ToDecimal(csv1[0].Substring(csv1[0].IndexOf("ENT-") - 7, 7)) + Convert.ToDecimal(csv1[0].Substring(csv1[0].IndexOf("FOREIGN") + 5, 5)) + Convert.ToDecimal(csv1[0].Substring(csv1[0].IndexOf("FOREIGN") + 5, 5));
                                                    textBox1.AppendText(total + ";");
                                                }
                                                catch (Exception EXC)
                                                {
                                                    MessageBox.Show(EXC.Message + "\r\nField: total");
                                                }
    
                                                try
                                                {
                                                    textBox1.AppendText("670" + csv1[0].Substring(csv1[0].IndexOf("ELV") + 6, 6) + ";");
                                                }
                                                catch (Exception EXC)
                                                {
                                                    MessageBox.Show(EXC.Message + "\r\nField: TID");
                                                }
    
                                                try
                                                {
                                                    textBox1.AppendText("670" + csv1[0].Substring(csv1[0].IndexOf("ELV") + 6, 6) + "\r\n");
                                                }
                                                catch (Exception EXC)
                                                {
                                                    MessageBox.Show(EXC.Message + "\r\nField: TID");
                                                }
                                            }
                                            else
                                            {
                                            }
                                        }
                                        catch
                                        {
                                            //other rows
                                            textBox1.AppendText(Program.naechste + ";" + "670" + csv1[0].Substring(csv1[0].IndexOf("ELV") + 6, 6) + ";" + csv1[0].Substring(csv1[0].LastIndexOf("ME") - 12, 5) + "." + DateTime.Now.ToString("yyyy") + ";");
    
                                            try
                                            {
                                                if (csv1[0].Substring(csv1[0].IndexOf("OWN") + 14, 5) == "REASON")
                                                {
                                                    textBox1.AppendText("because of objection" + ";");
                                                }
                                                else
                                                {
                                                    textBox1.AppendText("shortage of cover" + ";");
                                                }
                                            }
                                            catch
                                            {
                                                textBox1.AppendText("shortage of cover" + ";");
                                            }
    
                                            try
                                            {
                                                Amount = Convert.ToDecimal(csv1[0].Substring(csv1[0].IndexOf("ENT-") - 7, 7));
    
                                                textBox1.AppendText(Amount + ";");
                                            }
                                            catch (Exception EXC)
                                            {
                                                MessageBox.Show(EXC.Message + "\r\nField: Amount");
                                            }
    
                                            try
                                            {
                                                RDN = Convert.ToDecimal(csv1[0].Substring(csv1[0].IndexOf("FOREIGN") + 5, 5)) + Convert.ToDecimal(csv1[0].Substring(csv1[0].IndexOf("FOREIGN") + 5, 5));
                                                textBox1.AppendText(RDN + ";");
                                            }
                                            catch (Exception EXC)
                                            {
                                                MessageBox.Show(EXC.Message + "\r\nField: RDN");
                                            }
    
                                            try
                                            {
                                                total = Convert.ToDecimal(csv1[0].Substring(csv1[0].IndexOf("ENT-") - 7, 7)) + Convert.ToDecimal(csv1[0].Substring(csv1[0].IndexOf("FOREIGN") + 5, 5)) + Convert.ToDecimal(csv1[0].Substring(csv1[0].IndexOf("FOREIGN") + 5, 5));
                                                textBox1.AppendText(total + ";");
                                            }
                                            catch (Exception EXC)
                                            {
                                                MessageBox.Show(EXC.Message + "\r\nField: total");
                                            }
    
                                            try
                                            {
                                                textBox1.AppendText("670" + csv1[0].Substring(csv1[0].IndexOf("ELV") + 6, 6) + ";");
                                            }
                                            catch (Exception EXC)
                                            {
                                                MessageBox.Show(EXC.Message + "\r\nField: TID");
                                            }
    
                                            try
                                            {
                                                textBox1.AppendText("670" + csv1[0].Substring(csv1[0].IndexOf("ELV") + 6, 6) + "\r\n");
                                            }
                                            catch (Exception EXC)
                                            {
                                                MessageBox.Show(EXC.Message + "\r\nField: TID");
                                            }
                                        }
                                    }
                                }
                            }
                            catch
                            {                                
                            }
    
                            //Save final data
                            try
                            {
                                textBox5.Clear();
                                if (header == 0)
                                {
                                    textBox5.AppendText("BIN" + ";" + "Account" + ";" + "TID" + ";" + "Date" + ";" + "Reason of RDN" + ";" + "Amount" + ";" + "RDN" + ";" + "total" + ";" + "TID" + ";" + "TID" + "\r\n");
    
                                    StreamWriter file1 = new StreamWriter("\\\\path\\to\\file\\File_yesno.csv", true, Encoding.Default, 1024);
                                    {
                                        file1.WriteLine(textBox5.Text + textBox1.Text);
                                        file1.Close();
                                    }
                                    header++;
                                    write = 1;
                                    textBox3.AppendText("_" + fi.ToString());
                                    textBox6.AppendText(fi.ToString() + "<br>");
                                }
                                else
                                {
                                    StreamWriter file1 = new StreamWriter("\\\\path\\to\\file\\File_yesno.csv", true, Encoding.Default, 1024);
                                    {
                                        file1.WriteLine(textBox1.Text);
                                        file1.Close();
                                    }
                                    write = 1;
                                    textBox3.AppendText("_" + fi.ToString());
                                    textBox6.AppendText(fi.ToString() + "<br>");
                                }
    
                                textBox1.Clear();
                                textBox4.Clear();
                                textBox5.Clear();
                                //Save final data - END
                            }
                            catch
                            {
                                Application.Exit();
                            }
    
                            //Processing of data has been successful - save data to database
                            this.ds.CustTable.AddMCTabelleRow(addrow); //Ad row
                            this._ds.Update(this.ds.CustTable); //write to database                          
                        }
                        else
                        {
                        }
                    }
                }
                catch (Exception EXC)
                {
                    MessageBox.Show(EXC.Message);
                }
            }                         
            
            //Customer oder not customer?   
            if (write == 1)
            {
                textBox1.Clear();
                textBox4.Clear();
                textBox5.Clear();
                int customerornot = 0, present = 0, present2 = 0;
                textBox5.AppendText("Account (C11)" + ";" + "BIN(C10)" + ";" + "Cardnumber" + "\r\n");
                textBox4.AppendText("Account (C11)" + ";" + "BIN(C10)" + ";" + "TID" + ";" + "Date" + ";" + "Reason of RDN" + ";" + "Amount" + ";" + "RDN" + ";" + "total" + ";" + "TID" + ";" + "TID" + "\r\n");
                using (CsvReader csv1 = new CsvReader(new StreamReader("\\\\path\\to\\file\\File_yesno.csv", Encoding.Default), true, ';'))
                {
                    while (csv1.ReadNextRecord())
                    {
                        customerornot = 0;
    
                        using (CsvReader csv2 = new CsvReader(new StreamReader("\\\\path\\to\\file\\Terminalbestand Cruse 24.06 2011.csv", Encoding.Default), true, ';'))
                        {
                            while (csv2.ReadNextRecord())
                            {
                                if ((csv1[1].ToString().Length > 2) && (csv2[0].ToString().Length > 2))
                                {
                                    string a = csv1[2];
                                    string b = csv2[0];
    
                                    if (csv1[2] == csv2[0])
                                    {
                                        customerornot = 1;
                                        present = 1;
                                        textBox4.AppendText(csv1[1] + ";" + csv1[0] + ";" + csv1[2] + ";" + csv1[3] + ";" + csv1[4] + ";" + csv1[5] + ";" + csv1[6] + ";" + csv1[7] + ";" + csv1[8] + ";" + csv1[9] + "\r\n");
                                    }                                    
                                }
                            }
    
                            if (customerornot == 1)
                            {
                            }
                            else
                            {
                                textBox5.AppendText(csv1[1] + ";" + csv1[0] + ";" + "99" + "\r\n");
                                customerornot = 1;
                                present2 = 1;
                            }
                        }
                    }
    
                    if (present == 1)
                    {
                        StreamWriter file2 = new StreamWriter("\\\\path\\to\\file\\Created by Customer\\Customer_(" + textBox3.Text + ")_.csv", true, Encoding.Default, 1024);
                        {
                            file2.WriteLine(textBox4.Text);
                            file2.Close();
                        }
                    }
                    if (present2 == 1)
                    {
                        StreamWriter file3 = new StreamWriter("\\\\path\\to\\file\\Created by Customer\\NotCustomer_(" + textBox3.Text + ")_.csv", true, Encoding.Default, 1024);
                        {
                            file3.WriteLine(textBox5.Text);
                            file3.Close();
                        }
                    }
    
                    //Send Message
                    try
                    {
                        [snip ... Code to send an email, clearly copied from some tutorial]
                    }
                    catch (Exception ee)
                    {
                        Console.WriteLine("{0} Exception caught.", ee);
                    }
                    //End Message
                }
            }            
            //Customer or not customer? - END
    
            [snip... delete all the files we have created here. Of course with hard coded paths]
    
            Application.Exit();
        }
    }
    

    I had to snip some of the code du to character limit. The original program is 1220 lines long. Including unused namespaces such as "using System.IO".

    A breakdown of the program:

    1. Flags declared as int, because bool just isn't trustworthy.

    2. We check if a file has already been processed not by a simple SQL statement where we pass the file name as a parameter, no. We iterate through each row in the table, checking it against the file name. And if we have indeed found the file name in the table, we don't stop there. In fact, we run into an IndexOutOfRangeException every time we check a file name (because of "<= Table.Count" as opposed to "< Table.Count"). And since we check all the files in a folder with as many as 10,000 files in it, we run into A LOT OF EXCEPTIONS HERE!!! But don't worry, it's been taken care of by an empty catch block. We have a lot of empty catch blocks here, so get used to it...

    3. When processing the file, we don't iterate through all the lines only once, but 3 times. The third time we don't do anything at all, but we still go through the whole file again. Also note how how in case of an exception the flag "right" is still set to 1, but the textBoxes are cleared at least.

    4. Using textBoxes like variables. Storing the stuff we read from the file in them, reading from the textBoxes again to save it in a different file. How many textBoxes are there? 6. All convieniently named "textBox1" through "textBox6".

    5. My favorite, because the same developer has done the same thing in a different program: Determine how many lines are in a table by using a for-loop with the number of lines in the table used as break condition. This is pure genius and a good way to make sure the CPU doesn't get bored.

    6. Using 28 CsvReaders to read the stuff we wrote to a file back into the textBoxes, instead of maybe writing a small method for this kind of stuff. Omitted from the code due to problems with the character limit.

    7. Juggling data between the 6 textBoxes and writing everything to a file again.

    8. Last but not least, everything happens in "Form_Load". Makes you wonder why this isn't just a console application. But on the other hand, a console application doesn't have a GUI, so you cannot use textBoxes as some kind of buffer.

    9. As a bonus, we have many if-else statements like this:

      if(condition)
      {
      doStuff();
      }
      else
      {
      }

    And sometimes even

    if(condition)
    {
    }
    else
    {
        doStuff();
    }
    

    Oh and the messed up indentation at "if (right == 1)" is from the original program, I didn't bother to correct it. Deal with it. :P



  • @Hans_Mueller said in Over 1200 lines of pure WTFness:

    Flags declared as int, because bool just isn't trustworthy.

    Of course you can't trust a Boolean, you could end up with FILE_NOT_FOUND. That's not good when dealing with CSV files :trollface:



  • @Hans_Mueller said in Over 1200 lines of pure WTFness:

    The original program is 1220 lines long.

    Aahhhh. It's a baby! (We have some source files with 10x that much code.)



  • @dcon

    @dcon said in Over 1200 lines of pure WTFness:

    @Hans_Mueller said in Over 1200 lines of pure WTFness:

    The original program is 1220 lines long.

    Aahhhh. It's a baby! (We have some source files with 10x that much code.)

    But since the sole purpose of this beatuy is to process a single file, it's a bit much to need 1220 lines of code. :P
    I once rewrote a program of the same developer. His program was something along like 2000 lines, I needed only about 500. I think I still have the original program (have to check SVN), because it's even more WTF as what I presented here. I only say this much: A hidden label on the GUI, only used to get it's font to pass it to a printer...



  • My favorite: Try with an empty catch around a while loop with no internals.


  • Discourse touched me in a no-no place

    @Magus said in Over 1200 lines of pure WTFness:

    My favorite: Try with an empty catch around a while loop with no internals.

    😆

    Plus all of these:

                            else
                            {
                            }
    

  • Fake News

    @loopback0
    FTFY

                            else
                            {
                                // Reserved for future use
                            }
    

  • 🚽 Regular

    @Hans_Mueller

    StreamWriter file2 = new StreamWriter(...);
    {
        file2.WriteLine(textBox4.Text);
        file2.Close();
    }
    

    That's not how you should be... using... braces.


  • Winner of the 2016 Presidential Election

    @Zecc said in Over 1200 lines of pure WTFness:

    That's not how you should be... using... braces.

    And it's a garbage-collected language, so introducing scopes inside a function is completely pointless anyway.*

    *Only exception: Generated code


  • Java Dev

    @Zecc I've got some instances of

    pthreads_mutex_acquire(&some_mutex);
    {
        /* a bunch of code */
    }
    pthreads_mutex_release(&some_mutex);
    

    I prefer to hide my mutexes in wrapper functions whose primary task is mutex/condition juggling. But if I do mix, it's a nice way to have it be clear which areas are under lock.


  • 🚽 Regular

    @PleegWat That's a good point.


  • Java Dev

    catch
    {
        Application.Exit();
    }
    

    I think that should be every catch block instead of just the one.

    Although I must say I love the ingenuity of using a for loop to count the number of objects in a collection using the size of the collection as the break condition!


  • Winner of the 2016 Presidential Election

    @PleegWat said in Over 1200 lines of pure WTFness:

    it's a nice way to have it be clear which areas are under lock.

    Even better would be to have a RAII wrapper which is initialized at the start of the block. Unless you have to use pure C, in which case I pity you.



  • @asdf said in Over 1200 lines of pure WTFness:

    @Zecc said in Over 1200 lines of pure WTFness:

    That's not how you should be... using... braces.

    And it's a garbage-collected language, so introducing scopes inside a function is completely pointless anyway.*

    *Only exception: Generated code

    It's totally pointless. file2 isn't in that scope.


  • Winner of the 2016 Presidential Election

    @dcon
    To be fair, the only thing that's missing to make this sensible code is a try( and replacing the semicolon with ). I'm actually willing to bet that the original author C&P'd that from the internet, then removed the try, but left the scope.



  • @loopback0 said in Over 1200 lines of pure WTFness:

    @Magus said in Over 1200 lines of pure WTFness:

    My favorite: Try with an empty catch around a while loop with no internals.

    😆

    Plus all of these:

                            else
                            {
                            }
    

    Maybe their coding style guideline require both side present on if statement, plus no negative conditioning?

    Personally I'd just regard that as waste of space, but much WTF.



  • @asdf

    In C# it's one word and some punctuation away from being state of the art:

    using (StreamWriter file2 = new StreamWriter(...))
    {
        file2.WriteLine(textBox4.Text);
        //file2.Close();
    }
    

  • Winner of the 2016 Presidential Election

    @hungrier
    Oops, forgot that it was called using in C#. That's what I meant.



  • @asdf said in Over 1200 lines of pure WTFness:

    @Zecc said in Over 1200 lines of pure WTFness:

    That's not how you should be... using... braces.

    And it's a garbage-collected language, so introducing scopes inside a function is completely pointless anyway.*

    *Only exception: Generated code

    I'm pretty sure there are garbage collected languages where a variable is still considered reachable until the end of the block it's declared in.



  • @asdf said in Over 1200 lines of pure WTFness:

    @dcon
    I'm actually willing to bet that the original author C&P'd that from the internet, then removed the try, but left the scope.

    You'd win that bet. The original author is the prime example of a cargo cult programmer.


  • Winner of the 2016 Presidential Election

    @ben_lubar said in Over 1200 lines of pure WTFness:

    I'm pretty sure there are garbage collected languages where a variable is still considered reachable until the end of the block it's declared in.

    Unless the code spends minutes inside the same function, this is completely irrelevant.


  • Java Dev

    @asdf Yes, this is pure C. I'm not going to rewrite it from scratch and I've been told nothing good comes from mixing C++ into an existing C codebase.


  • Winner of the 2016 Presidential Election

    @PleegWat said in Over 1200 lines of pure WTFness:

    I've been told nothing good comes from mixing C++ into an existing C codebase.

    ???

    I mean, I'm not trying to convince you that rewriting legacy code is a good idea, but I cannot think of any reason why you can't gradually migrate a C program to C++.


  • Discourse touched me in a no-no place

    @asdf said in Over 1200 lines of pure WTFness:

    I cannot think of any reason why you can't gradually migrate a C program to C++

    The C++ build chain is typically a lot trickier than the C build chain. Also, the level of trickiness in C++ is usually higher, and that gives maintenance programmers more of a headache when things go wrong. (Ideally, they'd go wrong less, but even so…)


  • Winner of the 2016 Presidential Election

    @dkf
    That sounds more like the typical culture/people problem you'll have when switching languages in general than a specific problem with C++, though.

    But yes, it takes a while to get used to the C++ compiler's error messages. It might be a good idea to use clang if you are a beginner, because GCC often manages to produce particularly irrelevant error messages. However, if you don't use templates too much (which someone migrating from C probably won't), most error messages you'll deal with should be easy to understand.

    And if you're starting to learn C++, you should really compile with -Wall -Wextra -Werror -pedantic to avoid typical rookie mistakes. (Personally, I'd also add -Woverloaded-virtual -Wnon-virtual-dtor and -Wconversion -Wsign-conversion, which force you to be explicit whenever you actually want potentially dangerous behavior.)


    Filed under: -Wall is a lie!

  • Discourse touched me in a no-no place

    @asdf said in Over 1200 lines of pure WTFness:

    But yes, it takes a while to get used to the C++ compiler's error messages.

    No, I was thinking more about issues to do with ABI/API stability (C++ code tends to be a lot less clear about the separation issues there). Also, the applications I'm developing tend to end up in pretty restricted environments; one of them is going on a system with only 32kB of instruction memory (and the same of fast data memory), so C++'s tendency to require a larger standard library is a significant problem there. Theoretically, it could be fixed by strictly avoiding the std lib and implementing our own using templates, but that's quite a bit of effort.

    Another problem that's hit me in the past few years when working with C++ code is when the compiler, standard headers and linker all ended up disagreeing on the version of the language in play. The errors from that (even with clang) were very mysterious indeed.


  • Impossible Mission - B

    C++ may not be the worst language ever created, but it is without a doubt the worst ever to be taken seriously.



  • @masonwheeler said in Over 1200 lines of pure WTFness:

    C++ may not be the worst language ever created, but it is without a doubt the worst ever to be taken seriously.

    As long as Python is not taken seriously :trollface:


  • Impossible Mission - B

    @TimeBandit When's the last time someone made a minor typo in Python and got a 10-page error spew from the compiler? Or wrote a buffer overrun bug in Python code? Or ended up with a metaprogramming language within the compiler that's distinct from the actual Python language and Turing-complete (and thus subject to the Halting Problem and the possibility of infinite loops, on code that is supposed to run to completion) by accident?

    Python's got plenty of problems, but they're nowhere near the magnitude of C++'s.



  • @masonwheeler You're the strongest Python defender I ever met 😃


  • Winner of the 2016 Presidential Election

    @TimeBandit said in Over 1200 lines of pure WTFness:

    You're the strongest Python defender I ever met

    I've never met someone IRL who hated Python as religiously as some forum members here. Most of the people I know who dislike Python are simply annoyed by the fact that indentation is significant.



  • @asdf said in Over 1200 lines of pure WTFness:

    simply annoyed by the fact that indentation is significant.

    Count me in 😃


  • Winner of the 2016 Presidential Election

    @TimeBandit said in Over 1200 lines of pure WTFness:

    Count me in

    I still don't get it. Since Python 3, you can use any indentation style you want (IIRC), as long as it's consistent within the same block. And inconsistent indentation is TR:wtf: anyway; why would anyone want to be able to do that?



  • @asdf said in Over 1200 lines of pure WTFness:

    I still don't get it. Since Python 3, you can use any indentation style you want (IIRC), as long as it's consistent within the same block.

    Can you use brackets to define blocks now ?

    And inconsistent indentation is TR:wtf: anyway; why would anyone want to be able to do that?

    I don't, I just let my IDE fix the indentation for me.


  • Impossible Mission - B

    @asdf said in Over 1200 lines of pure WTFness:

    I still don't get it. Since Python 3, you can use any indentation style you want (IIRC), as long as it's consistent within the same block. And inconsistent indentation is TR:wtf: anyway; why would anyone want to be able to do that?

    Agreed. I'm just fine with that aspect; it's the technical issues that bug me.


  • Winner of the 2016 Presidential Election

    @TimeBandit said in Over 1200 lines of pure WTFness:

    I don't, I just let my IDE fix the indentation for me.

    Unless your IDE is horribly broken, it won't need to fix anything, but will auto-indent your code for you using the correct characters when you use the Tab key.



  • @asdf While I write code, I indent it properly.

    After I'm done modifying code, I press Alt + Shift + F and it magically fix all indentation.


  • 🚽 Regular

    @TimeBandit said in Over 1200 lines of pure WTFness:

    After I'm done modifying code, I press Alt + Shift + F and it magically fix all indentation.

    Made possible by the characters that show where your blocks end.

    To me that's the problem with indentation-based syntax. If you're adding new control flow statements to existing code, you can't just go "a { here, another { there, } here and here, alright fix formatting plz". The editor can't magically guess where blocks end, so you need to add/remove the indentation yourself.

    The other problem is counting how many indentation levels end at a line (and of what type) without having to scan upwards.


  • Winner of the 2016 Presidential Election Banned

    @Hans_Mueller said in Over 1200 lines of pure WTFness:

                                    try
                                    {
                                        textBox1.AppendText(csv1[0].Substring(0, csv1[0].IndexOf("ENT-") + 63) + "\r\n");
                                    }
                                    catch
                                    {
                                        textBox1.AppendText(csv1[0].Substring(0, csv1[0].IndexOf("ENT-") + 43) + "\r\n");
                                    }
    
    if(!succeeded(try())){
        try();
    }
    


  • @Fox But once it's "IndexOf("ENT-") + 63" and in the catch block it's "+43".



  • @dkf
    Sounds like a microcontroller. c++ compiler/library for some instructions sets are not as mature as C.


  • Winner of the 2016 Presidential Election Banned

    @Hans_Mueller Ah, good point, I didn't notice that. That's still pretty :wtf: though. Why 63 and 43? Is it based on a very specific set of text formats which will never change? Probably, in which case, those formats will probably change at some point and then this code breaks.



  • @Fox The program was designed to handle electronic banking data. It was a very specific format designed by the German Banking Industry Committee, so the numbers do make sense.

    However, it still would've been better to use const values instead of magic numbers. Or at least explain in a comment why it is either +63 or +43 as to not leave anyone guessing.


  • Winner of the 2016 Presidential Election Banned

    @Hans_Mueller said in Over 1200 lines of pure WTFness:

    German Banking Industry Committee,

    So there's a committee in charge of deciding this standardized format? And you think that means the format won't change? As far as I've observed, committees change formats any time the membership of that committee changes drastically enough to allow for a change.



  • @Fox We're talking about Banking institutes here. You know, the only place where you still can observe COBOL in the wild. :)


  • Discourse touched me in a no-no place

    @Helix said in Over 1200 lines of pure WTFness:

    Sounds like a microcontroller.

    It's actually a non-standard supercomputer, where the individual CPUs look a lot like microcontrollers (and there are an absolute shit-ton of them in a custom messaging fabric). Converting normal code to work on it is intensely brain-bending, but the result is awesomely fast. ;)

    c++ compiler/library for some instructions sets are not as mature as C.

    The support for ARM in GCC is pretty good. The standard library… not so much.



  • @dkf said in Over 1200 lines of pure WTFness:

    for ARM in GCC is pretty good. The standard

    i was going to say, ARM would be about the best option


  • BINNED

    @asdf said in Over 1200 lines of pure WTFness:

    Most of the people I know who dislike Python are simply annoyed by the fact that indentation is significant.

    There's also my former signature:

    "Dynamic typing": The belief that you can't explain to a computer why your code works, but you can keep track of it all in your head.



  • @Hans_Mueller COBOL is fairly popular in the US government, iirc, having kind of been the source of it.

    Meanwhile I also work in financial stuff, and we have a 30yo proprietary language that's still alive and kicking, and someone wants to even update the compiler a bunch.

    While my team is dockering the messy blob and shoving it off into a passing cloud, in the hopes that this will be more reasonable than rewriting the thing.

    Now, while this post could have enough information for someone who knows enough about the project to find me, it certainly isn't sensitive information.



  • @masonwheeler said in Over 1200 lines of pure WTFness:

    When's the last time someone made a minor typo in Python and got a 10-page error spew from the compiler?

    No, you just get a runtime error sometime in the future 🚎


Log in to reply