Forum Moderators: coopster
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.
65.
DO
if Request.Form("Action") = "CREATE" and strCreate = "Y" then
IF strPersonId <> "" then
for iLoop = 0 to UBound(astrSubTest)
if Request.Form(astrSubTest(iLoop) & "CodeID") <> "" then
if DBConnNextKey.Errors.Count > 0 then
for iLoop2 = 0 to DBConnNextKey.Errors.Count - 1
next
exit do
end if
if Request.Form(astrSubTest(iLoop) & "V") = "" then
else
end if
if DBConnU.Errors.Count > 0 then
exit for
end if
end if
next
if DBConnU.Errors.Count = 0 then
else
for iLoop2 = 0 to DBConnU.Errors.Count - 1
next
end if
End IF
end if
if Request.Form("Action") = "UPDATE" and strUpdate = "Y" then
IF strPersonId <> "" then
for iLoop = 0 to UBound(astrSubTest)
if Request.Form(astrSubTest(iLoop) & "ID") = "" then 'row does not exist
if Request.Form(astrSubTest(iLoop) & "CodeID") <> "" then 'Create
if DBConnNextKey.Errors.Count > 0 then
for iLoop2 = 0 to DBConnNextKey.Errors.Count - 1
next
exit do
end if
if Request.Form(astrSubTest(iLoop) & "V") = "" then
else
end if
end if
elseif Request.Form(astrSubTest(iLoop) & "CodeID") = "" then 'Delete
else 'Update
if Request.Form(astrSubTest(iLoop) & "V") = "" then
else
end if
end if
if strSQL <> "" then
end if
if DBConnU.Errors.Count > 0 then
exit for
end if
next
if DBConnU.Errors.Count = 0 then
else
for iLoop = 0 to DBConnU.Errors.Count - 1
next
end if
End IF
end if
if Request.Form("Action") = "DELETE" and strDelete = "Y" then
IF strPersonId <> "" then
for iLoop = 0 to UBound(astrSubTest)
if Request.Form(astrSubTest(iLoop) & "ID") <> "" then 'row exists
end if
nextif DBConnU.Errors.Count = 0 then
else
for iLoop = 0 to DBConnU.Errors.Count - 1
next
end if
End IF
end if
LOOP UNTIL TRUE
In response to #81 (message 19, inspired by a tongue in cheek remark made by a certain someone in message 17):
When grep is outlawed, only outlaws will use grep
No seriously, sometimes I know within 20 lines where a variable is, but I still grep to get the exact line number or, if I really know what I want to do, just use grep and replace with the value I want. That way, all I do is type what I want into grep - don't have to open the file, find the line, change it, save the file, close. That and my code is such a pile of spaghetti that in truth I couldn't actually find anything without grep ;-)
Tom
Nothing like throwing in a hierarchy of javascripts that are all dependent on each other. Something along the lines of "this script must be defined after variables hd,hm and hy are defined".
Then, while running the page, only to find that something was left out somewhere and the script runs every year from 1 to 2004. Got to figure out why the page is 200k in size?
Of course all that fancy javascript could have been handled just as well by a ~5 line "Ymd" mktime function ...
55. You wrap it up and realize that there are 20 funtions in the include files which are never called, although at some point, they were all required.
54. The project scope continues to creep, but the timeline scope continues to deminish (don't care who you are, if you are keeping up with that, you are hacking dough)
53. You are using database structure changes in the middle of the project
52. In an attempt to same time, you are making system calls for OS functions.
51. Changing database is (e.g MS SQL to MySQL) requires the rewrite of SQL statments.
50. There is HTML in your functions. (this is a little debatable, but it is a watch sign for me).
45. You realize that the only differance between three functions is the number of variables being passed.
44. You realize that you are changing global variables with functions inside include files
You are using GLOBAL VARIABLES! (Not sure if that one has already been stated, but it crossed my mind it probably has.. so no number here.)
50. There is HTML in your functions. (this is a little debatable, but it is a watch sign for me).
I would change this to
50. Your functions output HTML directly (either through switching out of PHP or via echo).
I would say there are many situations where it makes sense to have a function *return* HTML. But then... I'm trying to approach all signs with an open mind... except of course Jatar's foolish and irresponsible comments about grep :-)
Tom