Forum Moderators: coopster

Message Too Old, No Replies

Top 100 Signs That I Am Writing Spaghetti Code in PHP

Every one join in

         

ergophobe

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

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



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.

webadept

11:44 am on Feb 20, 2004 (gmt 0)

10+ Year Member



31. You have no idea what a CRC Card is ...

Knowles

11:48 am on Feb 20, 2004 (gmt 0)

10+ Year Member



31. You dont understand classes

oh and btw leave my html inside my functions alone!

Netizen

2:25 pm on Feb 20, 2004 (gmt 0)

10+ Year Member



30 You know someone else is writing spaghetti code when.... you find

if (1==0) {
...
}

seomike2003

3:51 pm on Feb 20, 2004 (gmt 0)



29. When you have more cases then a court house

slade7

4:31 pm on Feb 20, 2004 (gmt 0)

10+ Year Member



28: reading this list you think.. "Hmmm what's so bad about that? Or that? Or that?

httpwebwitch

5:42 pm on Feb 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



27.

index.php:
<?php include("menu.php");?>
...
menu.php:
<?php include("navigation.php");?>
...
navigation.php:
<?php include("newmenu.php");?>
...
newmenu.php:
<?php include("newmenu_final.php");?>
...
newmenu_final.php:
<?php include("menu_newer_version.php");?>
... etc

jatar_k

6:49 pm on Feb 20, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



26. if your included file "stuff.inc" has become deprecated in favour of "newer-stuff.inc"

jamie

6:58 pm on Feb 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



slade7 LOL ;-)))

txskydiver

9:42 pm on Feb 20, 2004 (gmt 0)

10+ Year Member



25. Parse error: parse error in /home/index.php on line 140

20 minutes later

Parse error: parse error in /home/index.php on line 141

20 minutes later

Parse error: parse error in /home/index.php on line 142

slade7

10:04 pm on Feb 20, 2004 (gmt 0)

10+ Year Member



25. Parse error: parse error in /home/index.php on line 140...

or worse.. Parse error: parse error in /home/newer-stuff.inc

seomike2003

1:33 am on Feb 21, 2004 (gmt 0)



24. When the first line of your code is:
<?
ini_set(max_execution_time,"99999");

23. And the last line of your codes is:
ini_set(max_execution_time,"30");
?>

grandpa

11:37 am on Feb 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



22. When you open the same db 11 times in the same file.

(Hey, I'm still figuring it out)

<what is a CRC card?>

webadept

12:51 pm on Feb 21, 2004 (gmt 0)

10+ Year Member



Hey GrandPa.. here ya go
[laputan.org...]

Kami

12:59 pm on Feb 21, 2004 (gmt 0)

10+ Year Member



21:

When you have to do your includes in a page being called...

Yup... and thats what I'm doing now... *cries*

ergophobe

5:02 pm on Feb 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




21: When you have to do your includes in a page being called...

Can you explain that a bit? I'm not sure what you mean.

Tom

WhosAWhata

8:45 pm on Feb 21, 2004 (gmt 0)

10+ Year Member



20.
you include a file that includes the original file...
<!-- file1.php -->
<? include("file2.php"); //other stuff?>

<!-- file2.php -->
<? echo "stuff"; include("file1.php");?>

grandpa

8:47 pm on Feb 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks webadept

At least I'm pretty good with a paint brush :)

WhosAWhata

8:49 pm on Feb 21, 2004 (gmt 0)

10+ Year Member



19.
you have so many custom fucntions that you try to redifine the nl2br function

18.
you have so many custom functions that the WhatDoTheseFunctionsDo.txt file is 20MB

17.
your kids understand the code...after college

ergophobe

11:03 pm on Feb 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




20.
you include a file that includes the original file...
<!-- file1.php -->
<? include("file2.php"); //other stuff?>

<!-- file2.php -->
<? echo "stuff"; include("file1.php");?>

That's ridiculous code. I would never do that! No way. I prefer

<!-- file1.php -->
<? include_once("file2.php");?>

<!-- file2.php -->
<? include_once("file1.php");?>

Rock solid that way.

Tom

ergophobe

11:05 pm on Feb 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Which reminds me of the well-known rule 16

16 You have to grep for all occurences of include() or require() and replace them with include_once() and require_once() just to get your app to run.

Tom

logiclamp

11:53 pm on Feb 21, 2004 (gmt 0)



15 - you're still using extract, cause well, those security folks are all just anal anyways.

lexipixel

9:37 am on Feb 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



14. You need to write a Perl script to check your PHP code.

Kami

12:23 pm on Feb 22, 2004 (gmt 0)

10+ Year Member



Ergophobe, what I mean is this.

I use a page-calling script (php?page=somedullpage)

The thing is, ALL my templating and other includes have to be done in the page being called just so I can specify the title of the page.

That, to me, is probably making a mountain out of a molehill... but not figured out a better way of doing it yet.

willybfriendly

11:42 pm on Feb 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you have so many custom fucntions that you try to redifine the nl2br function

Using info in these forums I did just that. I now have a very nice nl2p function.

Why generate <br>'s when proper markup calls for <p>'s?

I'd give credit to whoever offered the original code snippet, but I can't remember now who it was. :(

function nl2p($html)
{
// Use \n for newline on all systems
$html = preg_replace("/(\r\n¦\n¦\r)/", "\n", $html);

// Only allow two newlines in a row.
$html = preg_replace("/\n\n+/", "\n\n", $html);

// Put <p>..</p> around paragraphs
$html = preg_replace('/\n?(.+?)(\n\n¦\z)/s', "<p>$1</p>", $html);

// convert newlines not preceded by </p> to a <br /> tag
$html = preg_replace('¦(?<!</p> )\s*\n¦', "<br />", $html);

return $html;
}

WBF

stargeek

4:01 am on Feb 23, 2004 (gmt 0)

10+ Year Member



13. When your orignal project was to recreate a windows desktop application in php/html/javascript to run on windows desktops.

WhosAWhata

4:52 am on Feb 23, 2004 (gmt 0)

10+ Year Member



from #13
12.
you start trying to recreat a windows app with php...and end up making another form to e-mail app

seldo

11:01 am on Feb 23, 2004 (gmt 0)



11. You realise you have three functions with the exactly the same name, but which do completely different things, scattered across several includes.

(aka the answer to the question "Why does this function return different results for the same input on different pages?")

WhosAWhata

11:56 pm on Feb 26, 2004 (gmt 0)

10+ Year Member



just a little boost...come on just the top 10 left...

jatar_k

12:00 am on Feb 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



10 When your control script forgets that it is handling the return from one of many scripts it calls and re initializes all the vars.

...and you don't figure it out for a month.

jatar_k

5:37 pm on Feb 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



9. You have read through this whole thread so far and said to yourself "I don't do any of those" and patted yourself on the back.
This 108 message thread spans 4 pages: 108