Goto hell. Do not parse code. Do not collect $200 paycheck.

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 5679 Views - Last Post: 23 October 2012 - 06:49 PM Rate Topic: -----

#1 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 795
  • View blog
  • Posts: 1,681
  • Joined: 30-January 09

Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 12 February 2012 - 05:48 PM

At my workplace, I was tasked with updating the letter templates. They are written in a custom markup we use, which is similar to VB, so I thought it wouldn't be too difficult. This is the skeleton of template I was given to "update" (all IP references removed). Suffice to say, I trashed it and rewrote it from scratch. While this code might not look too bad, this is just the skeleton of it. The entire code for this one template was 546 lines.
<%
if ( -- )
{goto LABEL_ZERO_FIXED_PAY_AND_VARIABLE_PAY_AMOUNTS;}
else
if ( -- )
{goto LABEL_TERMINATING_PROFITSHARE_ONLY;}
else
if ( -- )
{goto LABEL_PROFITSHARE_ONLY;}

if ( -- )
{goto LABEL_FIXED_PAY_INCREASE;}

LABEL_VARIABLE_PAY_TEXT:
if ( -- )
{
if ( -- )
{goto LABEL_VPP_PLAN;}
else if ( -- )
{goto LABEL_STI_PLAN;}
else if ( -- )
{goto LABEL_DSTI_PLAN;}
else if ( -- )
{goto LABEL_ESTI_PLAN;}
}

LABEL_LETTER_SIGNATORY:
goto LABEL_END_LETTER_TEMPLATE;

LABEL_ZERO_FIXED_PAY_AND_VARIABLE_PAY_AMOUNTS:
goto LABEL_LETTER_SIGNATORY;

LABEL_FIXED_PAY_INCREASE:
goto LABEL_VARIABLE_PAY_TEXT;

LABEL_STI_PLAN:
goto LABEL_LETTER_SIGNATORY;

LABEL_ESTI_PLAN:
goto LABEL_LETTER_SIGNATORY;

LABEL_VPP_PLAN:
goto LABEL_LETTER_SIGNATORY;

LABEL_DSTI_PLAN:
goto LABEL_LETTER_SIGNATORY;

LABEL_PROFITSHARE_ONLY:
goto LABEL_LETTER_SIGNATORY;

LABEL_TERMINATING_PROFITSHARE_ONLY:
goto LABEL_LETTER_SIGNATORY;

LABEL_END_LETTER_TEMPLATE:
%>


This was, mind you, one of the easy ones to rework. There were others that had circular references, missing labels, duplicate labels, etc.

Is This A Good Question/Topic? 4
  • +

Replies To: Goto hell. Do not parse code. Do not collect $200 paycheck.

#2 Zachari  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 22
  • Joined: 28-February 11

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 14 February 2012 - 01:38 PM

I will agree with Dijkstra and say that Goto should have been thrown out of a tall window along with anyone who uses Bubblesorts on the reg.
Was This Post Helpful? 0
  • +
  • -

#3 stackoverflow  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 165
  • View blog
  • Posts: 545
  • Joined: 06-July 11

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 15 February 2012 - 08:12 PM

I wouldn't say goto statements are useless and I also wouldn't say bubble sort is bad. There are certainly times when bubble sort is the right way to go-- given a small enough data set it can out perform even the best algorithms.

However, in this case the goto statements seem excessive and nasty. Down with it!
Was This Post Helpful? 0
  • +
  • -

#4 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 795
  • View blog
  • Posts: 1,681
  • Joined: 30-January 09

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 15 February 2012 - 08:22 PM

This was the template that didn't do my head in. There were others (that I have conpletely eradicated from the system) that were of this calibre:
if(-1-)
{
  goto A
} else {
  goto B
}

A:
if(-2-)
{
  goto C
  D:
  if(-4-) goto G
  I:
  goto J
} else if(-3-) {
  goto E
  F:
  if(-4-) goto G
  H:
  goto J
}

B:
goto E

C:
goto D

E:
goto F

G:
if(-2-)
{
  goto I
} else {
  goto H
}

J:
(termination of script)


I'm not kidding, it got this bad. Not to mention that there was no code re-use either. Blocks of code were copied from say C to E with 90% of the code being exactly the same.
Was This Post Helpful? 0
  • +
  • -

#5 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 15 February 2012 - 08:55 PM

Holy crap. I would probably have ended up running out of the office, hands waving frantically above my head, screaming like a little girl.

I hope you're getting hazard pay for this. Or at least supplied with some sort of protective gear?!

Posted Image
Was This Post Helpful? 4
  • +
  • -

#6 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 795
  • View blog
  • Posts: 1,681
  • Joined: 30-January 09

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 15 February 2012 - 09:10 PM

Nah, I just used the three golden words of troubleshooting... "Delete where true"
Was This Post Helpful? 0
  • +
  • -

#7 Zachari  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 22
  • Joined: 28-February 11

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 16 February 2012 - 01:10 AM

The Goto isn't a bad device, but most of the people who use them aren't always using it sensibly. The code above is a prime example of that.
Was This Post Helpful? 0
  • +
  • -

#8 aliancemd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 07-December 10

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 16 February 2012 - 07:39 AM

Good that my teacher made me never use goto again. From my first year he saw a goto in my program, even if it was the best program in class, at the beginning he was most disatisfied with my program... He told me that if he will ever see again a "goto" word in my program he will mark me with the lowest mark there is, doesn't matter how good the program will be. Than I've read more on goto and found that it leaves garbage in programs and some other shi**y things and whenever I see people saying that goto is not bad I just get mad. I really got mad seeing "goto", it's an instant reaction, even if I don't care about the code I just saw :)
Was This Post Helpful? 0
  • +
  • -

#9 Zachari  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 22
  • Joined: 28-February 11

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 16 February 2012 - 11:15 AM

See, I have the same experience. They never took our ability to use it away, but it was frowned upon. Once I had to deal with code of people who did use goto a lot, I understood why. That said, I've been doing a lot more Assembly, and a "goto" is really all you've got there.
Was This Post Helpful? 0
  • +
  • -

#10 aliancemd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 07-December 10

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 16 February 2012 - 12:31 PM

View PostZachari, on 16 February 2012 - 11:15 AM, said:

See, I have the same experience. They never took our ability to use it away, but it was frowned upon. Once I had to deal with code of people who did use goto a lot, I understood why. That said, I've been doing a lot more Assembly, and a "goto" is really all you've got there.


I did half year of assembly and anyway I never use goto in C/C++, that's not an excuse :)
Was This Post Helpful? 0
  • +
  • -

#11 Zachari  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 22
  • Joined: 28-February 11

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 16 February 2012 - 01:01 PM

I meant in Assembly. I never use goto in C or C++.
Was This Post Helpful? 0
  • +
  • -

#12 The Architect 2.0  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 351
  • Joined: 22-May 08

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 16 February 2012 - 08:11 PM

you know what sucked? when our instructors told us that 'break' and 'continue' were just keywords/macros for 'goto' :( I was pretty sad when that happened.
Was This Post Helpful? 0
  • +
  • -

#13 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 16 February 2012 - 08:50 PM

And he expected you to avoid them as well? That's going a bit overboard.

I mean sure, it's probably best to try and set your logic up so you don't need them (that's almost always possible), but it's not as big of a deal. All "break" and "continue" do is end a loop/block and skip the current iteration of a loop, which isn't exactly hard to follow. They don't share goto's ability to create the kind of horrendous code e_i_pi showed us.
Was This Post Helpful? 0
  • +
  • -

#14 aliancemd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 07-December 10

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 17 February 2012 - 01:17 AM

Break and Continue are not bad. Just don't use goto
Was This Post Helpful? 0
  • +
  • -

#15 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2263
  • View blog
  • Posts: 9,467
  • Joined: 29-May 08

Re: Goto hell. Do not parse code. Do not collect $200 paycheck.

Posted 17 February 2012 - 01:31 AM

Then don't look at the implementation of Async and Await in .net, is utilises GoTo.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2