How much redundant code one can produce in a lifetime (and why)?



  • OK, I'm officialy pissed now. Can't even count how much wtf's are there.
    Below is the code of a event handler in a legacy windows desktop application which I inherited. Keep in mind, that this... WONDER comes from an ex-colleague (let's call him Ivan), who used to be the senior programmer in our small software company. Ivan left several months ago, because he doesn't feel like writing code anymore. He insisted that he was achieved the excelency and that the company must pay him to teach others how to write the perfect code and to guide them. Of course, no one was trying to stop Ivan when he announced his departure.
    This event handler belongs to a instalment calculator for small personal credits. The whole calculator (by the words of the original "developer") consists of over 20 000 lines of code, and is extremely complicated (who cares about maintenance, anyway :( ). There are many more pearls of WTF, like mixing business calculations with GUI controlling code, calculations with absurd precission, funny error messages etc., but I will keep them for later (when I bump into them again).
     
    Wondering why over 20 000 lines of code? That's why:
    datawindowchild ldwch_temp
    long ll_found, i
    long ThisIsNullLong
    decimal ThisIsNullDecimal, ldc_pv_prc
    string ThisIsNullString, ls_pv_type, ls_pv_text, ls_filter
    decimal {2} ldc_ps_gpr
    

    SetNull(ThisIsNullLong)
    SetNull(ThisIsNullDecimal)
    SetNull(ThisIsNullString)

    if ISNULL(al_pay_scheme_id) then
    dw_main.SetItem(1, "ps_period", ThisIsNullLong)
    dw_main.SetItem(1, "ps_gpr", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_gratis", ThisIsNullLong)
    dw_main.SetItem(1, "ps_interest", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_pv_type", ThisIsNullString)
    dw_main.SetItem(1, "ps_pv_prc", ThisIsNullDecimal)
    dw_main.SetItem(1, "pv_text", ThisIsNullString)
    dw_main.SetItem(1, "pv_custom", "N")
    dw_main.SetItem(1, "pv_client", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_gift_beg", ThisIsNullLong)
    dw_main.SetItem(1, "ps_gift_end", ThisIsNullLong)
    dw_main.SetItem(1, "ps_ins_perc", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_recurrence", ThisIsNullLong)
    dw_main.Modify("pv_custom.Visible=0")
    dw_main.Modify("pv_client.Visible=0")
    dw_fees.Reset()
    iuo_pp.iuo_ins.il_pay_scheme_id = al_pay_scheme_id
    return TRUE
    end if

    if dw_main.GetChild("pay_scheme_id", ldwch_temp) = -1 then
    dw_main.SetItem(1, "ps_period", ThisIsNullLong)
    dw_main.SetItem(1, "ps_gpr", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_gratis", ThisIsNullLong)
    dw_main.SetItem(1, "ps_interest", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_pv_type", ThisIsNullString)
    dw_main.SetItem(1, "ps_pv_prc", ThisIsNullDecimal)
    dw_main.SetItem(1, "pv_text", ThisIsNullString)
    dw_main.SetItem(1, "pv_custom", "N")
    dw_main.SetItem(1, "pv_client", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_gift_beg", ThisIsNullLong)
    dw_main.SetItem(1, "ps_gift_end", ThisIsNullLong)
    dw_main.SetItem(1, "ps_ins_perc", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_recurrence", ThisIsNullLong)
    dw_main.Modify("pv_custom.Visible=0")
    dw_main.Modify("pv_client.Visible=0")
    dw_fees.Reset()
    MessageBox(go.m.msg(go.m.ERR), go.m.msg(go.m.DDDW_GETCHILD, go.m.msg(3726)), StopSign!)
    return FALSE
    end if

    ll_found = ldwch_temp.Find("pay_scheme_id=" + trim(string(al_pay_scheme_id)), 1, ldwch_temp.RowCount())
    if ll_found <= 0 then
    dw_main.SetItem(1, "ps_period", ThisIsNullLong)
    dw_main.SetItem(1, "ps_gpr", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_gratis", ThisIsNullLong)
    dw_main.SetItem(1, "ps_interest", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_pv_type", ThisIsNullString)
    dw_main.SetItem(1, "ps_pv_prc", ThisIsNullDecimal)
    dw_main.SetItem(1, "pv_text", ThisIsNullString)
    dw_main.SetItem(1, "pv_custom", "N")
    dw_main.SetItem(1, "pv_client", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_gift_beg", ThisIsNullLong)
    dw_main.SetItem(1, "ps_gift_end", ThisIsNullLong)
    dw_main.SetItem(1, "ps_ins_perc", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_recurrence", ThisIsNullLong)
    dw_main.Modify("pv_custom.Visible=0")
    dw_main.Modify("pv_client.Visible=0")
    dw_fees.Reset()
    return FALSE
    end if

    dw_main.SetItem(1, "ps_period", ldwch_temp.GetItemNumber(ll_found, "ps_period"))
    dw_main.SetItem(1, "ps_gpr", ldwch_temp.GetItemDecimal(ll_found, "ps_gpr"))
    dw_main.SetItem(1, "ps_gratis", ldwch_temp.GetItemNumber(ll_found, "ps_gratis"))
    dw_main.SetItem(1, "ps_interest", ldwch_temp.GetItemDecimal(ll_found, "ps_interest"))
    ls_pv_type = ldwch_temp.GetItemString(ll_found, "ps_pv_type")
    dw_main.SetItem(1, "ps_pv_type", ls_pv_type)
    ldc_pv_prc = ldwch_temp.GetItemDecimal(ll_found, "ps_pv_prc")
    dw_main.SetItem(1, "ps_pv_prc", ldc_pv_prc)
    dw_main.SetItem(1, "ps_gift_beg", ldwch_temp.GetItemDecimal(ll_found, "ps_gift_beg"))
    dw_main.SetItem(1, "ps_gift_end", ldwch_temp.GetItemDecimal(ll_found, "ps_gift_end"))
    dw_main.SetItem(1, "ps_ins_perc", ldwch_temp.GetItemDecimal(ll_found, "ps_ins_perc"))
    dw_main.SetItem(1, "ps_recurrence", ldwch_temp.GetItemNumber(ll_found, "ps_recurrence"))

    ids_ps_fees.SetFilter("pay_scheme_id=" + trim(string(al_pay_scheme_id)))
    ids_ps_fees.Filter()
    ls_filter = ""
    for i = 1 to ids_ps_fees.RowCount()
    if i > 1 then ls_filter = ls_filter + ","
    ls_filter = ls_filter + string(ids_ps_fees.GetItemNumber(i, "fee_id"))
    next
    if ls_filter <> "" then
    ls_filter = "fee_id in (" + ls_filter + ")"
    else
    ls_filter = "0 = 1"
    end if

    dw_fees.uf_clear_sort()
    if dw_fees.uf_Retrieve_ds(gnom.uf_get_ds("fees"), ls_filter) = -1 then
    dw_main.SetItem(1, "ps_period", ThisIsNullLong)
    dw_main.SetItem(1, "ps_gpr", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_gratis", ThisIsNullLong)
    dw_main.SetItem(1, "ps_interest", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_pv_type", ThisIsNullString)
    dw_main.SetItem(1, "ps_pv_prc", ThisIsNullDecimal)
    dw_main.SetItem(1, "pv_text", ThisIsNullString)
    dw_main.SetItem(1, "pv_custom", "N")
    dw_main.SetItem(1, "pv_client", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_gift_beg", ThisIsNullLong)
    dw_main.SetItem(1, "ps_gift_end", ThisIsNullLong)
    dw_main.SetItem(1, "ps_ins_perc", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_recurrence", ThisIsNullLong)
    dw_main.Modify("pv_custom.Visible=0")
    dw_main.Modify("pv_client.Visible=0")
    dw_fees.Reset()
    return FALSE
    end if

    for i = 1 to dw_fees.RowCount()
    ll_found = ids_ps_fees.Find("fee_id=" + string(dw_fees.GetItemNumber(i, "fee_id")), 1, ids_ps_fees.RowCount())
    if ll_found > 0 then
    dw_fees.SetItem(i, "ps_fee_ord_no", ids_ps_fees.GetItemNumber(ll_found, "ps_fee_ord_no"))
    else
    dw_fees.SetItem(i, "ps_fee_ord_no", ThisIsNullLong)
    end if
    next
    dw_fees.Sort()
    dw_fees.uf_SelectFirst()

    ua_datastore lds_temp
    lds_temp = gnom.uf_get_ds("pv_type")
    if not IsValid(lds_temp) then
    dw_main.SetItem(1, "ps_period", ThisIsNullLong)
    dw_main.SetItem(1, "ps_gpr", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_gratis", ThisIsNullLong)
    dw_main.SetItem(1, "ps_interest", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_pv_type", ThisIsNullString)
    dw_main.SetItem(1, "ps_pv_prc", ThisIsNullDecimal)
    dw_main.SetItem(1, "pv_text", ThisIsNullString)
    dw_main.SetItem(1, "pv_custom", "N")
    dw_main.SetItem(1, "pv_client", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_gift_beg", ThisIsNullLong)
    dw_main.SetItem(1, "ps_gift_end", ThisIsNullLong)
    dw_main.SetItem(1, "ps_ins_perc", ThisIsNullDecimal)
    dw_main.SetItem(1, "ps_recurrence", ThisIsNullLong)
    dw_main.Modify("pv_custom.Visible=0")
    dw_main.Modify("pv_client.Visible=0")
    dw_fees.Reset()
    MessageBox(go.m.msg(go.m.ERR), go.m.msg(3727), StopSign!)
    return FALSE
    end if

    // Fill PV_TEXT
    ll_found = lds_temp.Find("nh_id='" + ls_pv_type + "'", 1, lds_temp.RowCount())
    if ll_found <= 0 then
    dw_main.SetItem(1, "pv_text", ThisIsNullString)
    else
    ls_pv_text = lds_temp.GetItemString(ll_found, "nh_name")
    if ls_pv_type = "P" then
    ls_pv_text = f_str_replace(ls_pv_text, "#%1", string(ldc_pv_prc))
    end if
    dw_main.SetItem(1, "pv_text", ls_pv_text)
    end if

    if ls_pv_type = "N" then
    dw_main.SetItem(1, "pv_custom", "N")
    dw_main.SetItem(1, "pv_client", ThisIsNullDecimal)
    dw_main.Modify("pv_custom.Visible=0")
    dw_main.Modify("pv_client.Visible=0")
    else
    if dw_fees.Find("fc_type='O' and fee_apply='P'", 1, dw_fees.RowCount()) > 0 then
    dw_main.SetItem(1, "pv_custom", "N")
    dw_main.SetItem(1, "pv_client", ThisIsNullDecimal)
    dw_main.Modify("pv_custom.Visible=0")
    dw_main.Modify("pv_client.Visible=0")
    else
    ldc_ps_gpr = dw_main.GetItemDecimal(1, "ps_gpr")
    if ISNULL(ldc_ps_gpr) then ldc_ps_gpr = 0.00
    if ldc_ps_gpr < 0.00 then ldc_ps_gpr = 0.00
    if ldc_ps_gpr > 0.00 then
    dw_main.SetItem(1, "pv_custom", "N")
    dw_main.SetItem(1, "pv_client", ThisIsNullDecimal)
    dw_main.Modify("pv_custom.Visible=0")
    dw_main.Modify("pv_client.Visible=0")
    else
    if ab_check_fin_type then // show/hide PV_CUSTOM and PV_CLIENT according to FIN_TYPE_ID
    wf_change_fin_type(dw_main.GetItemString(1, "fin_type_id"))
    end if
    end if
    end if
    end if

    iuo_pp.iuo_ins.il_pay_scheme_id = al_pay_scheme_id
    return TRUE


  • Trolleybus Mechanic

    @partizanin said:

    OK, I'm officialy pissed now.
     

    I would be too if I was working Saturday,

    @partizanin said:

    Can't even count how much wtf's are there.

    Neither can I, but I could give it a try. Which is the TRWTF... a first time poster managing to format their first post correctly, including indented code. What manner of wizard are you?

    Also, it's St. Patrick's Day weekend. At the very least you can drown your sorrows in a couple big, tall pints of green-tinted whiskey.



  • @Lorne Kates said:

    a first time poster managing to format their first post correctly, including indented code
    He registered here almost 9 years ago.  He's obviously been practicing for this big event.

    Or he's drunk.

     



  • @Lorne Kates said:

    What manner of wizard are you?

    Well, thank you for your kind words. I hate reading unidented code (or code published in non-proportional fonts), so I tried my best :)

     @Lorne Kates said:

    At the very least you can drown your sorrows in a couple big, tall pints of green-tinted whiskey

    I most certanly will. Unfortunately, it's not easy to find green whiskey or green ale around here, but we have something called Menta, which will honor st. Patrick as good as whiskey.

    @El_Heffe said:

    Or he's drunk

    Not yet. But soon :)

     



  • @Lorne Kates said:

    @partizanin said:

    OK, I'm officialy pissed now.
     

    I would be too if I was working Saturday.



    Heh. I got a call at fucking 6:30 this morning because of issues in our migration to production.

     



  • @Lorne Kates said:

    Neither can I, but I could give it a try. Which is the TRWTF... a first time poster managing to format their first post correctly, including indented code. What manner of wizard are you?

    He forgot to increase the font size on CS's ridiculously-tiny PRE style. He's only a sorcerer.



  • I really don't like VB in saturdays (or never) so can you explain in a TL;DR way what is all of this supposed to be doing? One thing I can see is that this Ivan guy was pretty affraid of using functions/methods and separation of concerns.



  •  TRWTF is Ivan's code uses variables with normal english names without typos and his comments are also normal english without mistakes. 

    If this were on the first page, it would be full of random words in cyrillic Alex got off google translate.



  • @Mo6eB said:

    Ivan's code uses variables with normal english names without typos and his comments are also normal english

    Ivan's English language skills are quite OK. It's his programming and social skills that need polishing. I wish that it was other way around.

    @ubersoldat said:

    I really don't like VB in saturdays (or never)

    It's actually PowerScript (used in PowerBuilder), which is way more obscure :)

    @ubersoldat said:

    what is all of this supposed to be doing?

    It is supposed to change values of some screen fields according to selected value in another drop-down field.

    @ubersoldat said:

    affraid of using functions/methods and separation of concerns

    I suspect that he is not affraid, he just is huge fan of "lines of code" metric (if it can be metric at all) - he used to praise himself for thousand of lines of code written in a week/month/whatever. And please, don't let me even start on separation of concerns... If soon have more time, I'll post some excerpts which demonstrates Ivan's approach to that.

    Cheers.



  • @Snooder said:

    our migration to production
     

    I don't know if I would migrate to production - I've heard it's a dangerous country.



  • @too_many_usernames said:

    @Snooder said:

    our migration to production
     

    I don't know if I would migrate to production - I've heard it's a dangerous country.

    Nice place, but the bugs there are terrible.

     


Log in to reply