Welcome to WebmasterWorld Guest from 3.227.249.234

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Top 100 Signs That I Am Writing Spaghetti Code in PHP

Every one join in

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

Senior Member

WebmasterWorld Senior Member ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8639
votes: 283


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.

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

Junior Member

10+ Year Member

joined:Feb 19, 2004
posts:61
votes: 0


31. You have no idea what a CRC Card is ...
11:48 am on Feb 20, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 17, 2002
posts:601
votes: 0


31. You dont understand classes

oh and btw leave my html inside my functions alone!

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

Full Member

10+ Year Member

joined:May 29, 2003
posts:273
votes: 0


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

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

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

Junior Member

joined:Sept 9, 2003
posts:107
votes: 0


29. When you have more cases then a court house
4:31 pm on Feb 20, 2004 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 20, 2003
posts:132
votes: 0


28: reading this list you think.. "Hmmm what's so bad about that? Or that? Or that?
5:42 pm on Feb 20, 2004 (gmt 0)

Senior Member from CA 

WebmasterWorld Senior Member httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
posts:4061
votes: 0


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
6:49 pm on Feb 20, 2004 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15756
votes: 0


26. if your included file "stuff.inc" has become deprecated in favour of "newer-stuff.inc"
6:58 pm on Feb 20, 2004 (gmt 0)

Senior Member from ES 

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

joined:July 24, 2002
posts:1129
votes: 2


slade7 LOL ;-)))
9:42 pm on Feb 20, 2004 (gmt 0)

New User

10+ Year Member

joined:Feb 20, 2004
posts:8
votes: 0


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

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

Junior Member

10+ Year Member

joined:Nov 20, 2003
posts:132
votes: 0


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

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

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

Junior Member

joined:Sept 9, 2003
posts:107
votes: 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");
?>

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 7, 2003
posts:1408
votes: 0


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?>

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

Junior Member

10+ Year Member

joined:Feb 19, 2004
posts:61
votes: 0


Hey GrandPa.. here ya go
[laputan.org...]
12:59 pm on Feb 21, 2004 (gmt 0)

New User

10+ Year Member

joined:Feb 17, 2004
posts:13
votes: 0


21:

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

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

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

Senior Member

WebmasterWorld Senior Member ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8639
votes: 283



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

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

Preferred Member

10+ Year Member

joined:Nov 12, 2003
posts:454
votes: 0


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

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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 7, 2003
posts:1408
votes: 0


Thanks webadept

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

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

Preferred Member

10+ Year Member

joined:Nov 12, 2003
posts:454
votes: 0


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

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

Senior Member

WebmasterWorld Senior Member ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8639
votes: 283



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

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

Senior Member

WebmasterWorld Senior Member ergophobe is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Apr 25, 2002
posts:8639
votes: 283


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

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

Junior Member

joined:Feb 18, 2004
posts:117
votes: 0


15 - you're still using extract, cause well, those security folks are all just anal anyways.
9:37 am on Feb 22, 2004 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 16, 2004
posts:1343
votes: 5


14. You need to write a Perl script to check your PHP code.
12:23 pm on Feb 22, 2004 (gmt 0)

New User

10+ Year Member

joined:Feb 17, 2004
posts:13
votes: 0


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.

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 1, 2002
posts:1834
votes: 0


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

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

Junior Member

10+ Year Member

joined:Nov 20, 2003
posts:197
votes: 0


13. When your orignal project was to recreate a windows desktop application in php/html/javascript to run on windows desktops.
4:52 am on Feb 23, 2004 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 12, 2003
posts:454
votes: 0


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)

Inactive Member
Account Expired

 
 


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?")

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

Preferred Member

10+ Year Member

joined:Nov 12, 2003
posts:454
votes: 0


just a little boost...come on just the top 10 left...
12:00 am on Feb 27, 2004 (gmt 0)

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15756
votes: 0


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.

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

Administrator

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
posts:15756
votes: 0


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