homepage Welcome to WebmasterWorld Guest from 54.198.130.203
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

This 108 message thread spans 4 pages: 108 ( [1] 2 3 4 > >     
Top 100 Signs That I Am Writing Spaghetti Code in PHP
Every one join in
ergophobe




msg:1296040
 8:18 pm on Feb 15, 2004 (gmt 0)

This got started a little off topic in another thread [webmasterworld.com]. I was curious to see what it might generate if it had it's own thread. I started with numbers 99 and 100. Jatar_K chimed in with number 98. Now let's see what we can come up with collectively.

And for those unfamiliar with the term, here's part of the definition from the Wikipedia:

Spaghetti code is a pejorative term for code with a complex and tangled control structure,

In other words it is inelegant, difficult to understand for anyone who takes over a project, difficult to maintain. It is likely to be inefficient, but may in fact be very efficient if only anyone could figure out how it worked.

Top 100 Signs That I Am Writing Spaghetti Code in PHP

100. I have no idea where this constant is defined.
99. I have echo stmts littered throughout my code.
98. There is an error but it isn't handled, and I can't find it to figure out what's wrong.

 

justageek




msg:1296041
 8:45 pm on Feb 15, 2004 (gmt 0)

97. Spelling 'referer' wrong everywhere so it matches the PHP $HTTP_REFERER syntax and then adding a comment everywhere it's used so everyone knows you did it on purpose.

96. Passing variables directly to 635 functions and using 'global' on 453 functions.

JAG

coopster




msg:1296042
 9:22 pm on Feb 15, 2004 (gmt 0)

95.
I have to modify the same function 10 times because I have not
moved it into an include script...yet.

jatar_k




msg:1296043
 9:36 pm on Feb 15, 2004 (gmt 0)

94. Finding out that the 2 libraries you need to include also happen to include each other

93. trying to edit html content on the index page and not being able to find the template until you go through 10 scripts (gotta love horde)

justageek




msg:1296044
 9:44 pm on Feb 15, 2004 (gmt 0)

92. <removed - Shoddy doesn't count>

JAG

[edited by: justageek at 11:01 pm (utc) on Feb. 15, 2004]

lorax




msg:1296045
 10:28 pm on Feb 15, 2004 (gmt 0)

91. You lose track of what include to use for what functions.
90. You edit an include and realize you've already written that function or something very similar...somewhere.

ergophobe




msg:1296046
 10:30 pm on Feb 15, 2004 (gmt 0)

89. Opening and closing tags for an element like <p>, <table>, etc are in different files.

This is going much better than I expected... I love the contributions, especially #94, which perfectly describes the code I took over from the previous co-op student when I got my co-op job as a student. In the entire code to test data for the AWACS flight simulator, two variables were each defined once and only once.

x = y

Then somewhat later,

y = x

By the way, IMO spaghetti code implies bad logic and organization. I would say the lack of comments (#92) is shoddy, but may not be spaghetti code.

[edited by: ergophobe at 10:40 pm (utc) on Feb. 15, 2004]

willybfriendly




msg:1296047
 10:37 pm on Feb 15, 2004 (gmt 0)

88. Can't find the include file anywhere in the folder I am examining.

WBF

ergophobe




msg:1296048
 10:38 pm on Feb 15, 2004 (gmt 0)

This is a corollary to 91.

87. Includes? What are includes?

Knowles




msg:1296049
 11:30 pm on Feb 15, 2004 (gmt 0)

86. Everything looks the same. IE.
Top of page:
include "include.php";
include "include1.php":
inlcude "include2.php":

Try to find that function!

ps. I dont know how to subtract.

coopster




msg:1296050
 11:40 pm on Feb 15, 2004 (gmt 0)

85. I find that rewriting is quicker and easier than modifying the original design.

RobinC




msg:1296051
 11:59 pm on Feb 15, 2004 (gmt 0)

84. You have a library of small functions that you wrote yourself, and will cut'n'paste them into almost every project you work on... Whether they're needed or not...

Robin

jatar_k




msg:1296052
 1:32 am on Feb 16, 2004 (gmt 0)

83. You have a corrupted variable and can't find where, or if, you initialized it and, for that matter, where you assigned a different value.

lorax




msg:1296053
 2:39 am on Feb 16, 2004 (gmt 0)

82. I'm at that precipice where I suddenly realize that the whole application would be a lot better if I made a certain change - a fundamental change - one that would allow me to streamline my code, perhaps combine functions, and save me time and hassle later on. But it requires me to dump a day's (or more) work and because of a lack of time - I press on and ignore it.

[edited]$reason="change of pov";[/edited]

willybfriendly




msg:1296054
 4:37 am on Feb 16, 2004 (gmt 0)

Hey Lorax, its a bit off topic, but I just threw out 2 week's work for that exact reason. It came to me in a dream, literally. (Wasn't there recently a thread about dreaming code?)

The new approach has reduced the volume of code by at least 40%.

I guess that is a sign that I was boiling up a big pot of spaghetti ;)

WBF

P.S. -This forum is great. A year ago I had only a couple of books about PHP, and ancient experience with BASIC and Z-80 assembly. Boy, I have come a long way with your folk's wisdom to help me! (Now if I can get my head more fully around DB stuff...)

mipapage




msg:1296055
 4:42 am on Feb 16, 2004 (gmt 0)

Hooo I'm doing #82 riight now! I should really stop and make this script a class! :-[

ergophobe




msg:1296056
 5:30 am on Feb 16, 2004 (gmt 0)


83. You have a corrupted variable and can't find where, or if, you initialized it and, for that matter, where you assigned a different value.

But hey, I know how to use grep, so that's okay.

Tom

ergophobe




msg:1296057
 4:40 pm on Feb 16, 2004 (gmt 0)

Since it seems stalled out at #82 for the moment, so I thought I would recap what we have so far (aside from a great start!). I might have to get Jatar K to rename the thread if we don't get 81 more!

The list so far

100. I have no idea where this constant is defined.

99. I have echo stmts littered throughout my code.

98. There is an error but it isn't handled, and I can't find it to figure out what's wrong.

97. Spelling 'referer' wrong everywhere so it matches the PHP $HTTP_REFERER syntax and then adding a comment everywhere it's used so everyone knows you did it on purpose.

96. Passing variables directly to 635 functions and using 'global' on 453 functions.

95. I have to modify the same function 10 times because I have not moved it into an include script...yet.

94. Finding out that the 2 libraries you need to include also happen to include each other

93. trying to edit html content on the index page and not being able to find the template until you go through 10 scripts (gotta love horde).

92. No comments.

91. You lose track of what include to use for what functions.

90. You edit an include and realize you've already written that function or something very similar...somewhere.

89. Opening and closing tags for an element like <p>, <table>, etc are in different files.

88. Can't find the include file anywhere in the folder I am examining.

87. Includes? What are includes? (This is a corollary to 91).

86. Everything looks the same, as in:
Top of page:
include "include.php";
include "include1.php":
include "include2.php":

85. I find that rewriting is quicker and easier than modifying the original design.

84. You have a library of small functions that you wrote yourself, and will cut'n'paste them into almost every project you work on... Whether they're needed or not...

82. I'm at that precipice where I suddenly realize that the whole application would be a lot better if I made a certain change - a fundamental change - one that would allow me to streamline my code, perhaps combine functions, and save me time and hassle later on. But it requires me to dump a day's (or more) work and because of a lack of time - I press on and ignore it.

Tom

jatar_k




msg:1296058
 4:48 pm on Feb 16, 2004 (gmt 0)

81. Every time you want to change a variable you have to use grep to find it ;)

seomike2003




msg:1296059
 8:02 pm on Feb 16, 2004 (gmt 0)

80. you have so many "for" loops you've declared a variable for each letter in the alphabet

seomike2003




msg:1296060
 8:08 pm on Feb 16, 2004 (gmt 0)

79. Dreamweaver starts to lag when you open the file

jatar_k




msg:1296061
 8:22 pm on Feb 16, 2004 (gmt 0)

78. You realize there is no possible way to unwind your cross included files and in your great wisdom you used include and require. You now have to replace all of them with include_once and require_once just to stop the contamination.

seomike2003




msg:1296062
 8:23 pm on Feb 16, 2004 (gmt 0)

77. there are enough "if" statements to make you scroll to the right.

coopster




msg:1296063
 8:26 pm on Feb 16, 2004 (gmt 0)

76. Your
GET query string is so long it can crash a browser.
Gibble




msg:1296064
 8:30 pm on Feb 16, 2004 (gmt 0)

78. You realize there is no possible way to unwind your cross included files and in your great wisdom you used include and require. You now have to replace all of them with include_once and require_once just to stop the contamination.

Done that one!

75. Your class object includes are stored on a single server and aliased on all your webservers...but you don't know which server those files are REALLY on anymore.

Asandir




msg:1296065
 8:49 pm on Feb 16, 2004 (gmt 0)

74. You curse at your co-worker's terrible logic just before you realise you wrote that code last week.

Gibble




msg:1296066
 9:01 pm on Feb 16, 2004 (gmt 0)

73. You see comments in the code that read something like:

Your Name: Don't ask me how or why this works, I know it looks overly complex and it appears there IS a simpler solution, but this works, it fixed a bug from the 'simpler code'...just leave it be...don't touch it, I've hired a voodoo witch doctor to place a curse on anybody who alters this code...trust me, just leave it alone!

mipapage




msg:1296067
 10:01 pm on Feb 16, 2004 (gmt 0)

@73.

Here's what I'm looking at right now:

// Something useful is being done here. 
$page_num = $cur_page;

jackson




msg:1296068
 2:59 am on Feb 17, 2004 (gmt 0)

72

Following on from 81 - you know you're digging through a bowl of the stuff when, as a regular tool, you're using the windoz's search feature to find functions, variables and other bits of code.

71

Following of from 80 and 77 - having to "peel" your way through while/for loops and a chunks of IF and ELSE statements because the original author (probably in all his haste) couldn't be bothered to use brackets. The code works but not always for the right reasons.

BTW - nice move on opening this thread

seomike2003




msg:1296069
 6:52 am on Feb 17, 2004 (gmt 0)

70. out of the 50 arrays used 49 are 3 dimensional

This 108 message thread spans 4 pages: 108 ( [1] 2 3 4 > >
Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved