Wonderful code

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

This is generally what I do..

1. Create skeleton code to nail down the logic.
2. Add meat for validation, security and error handling.
3. Refactor
4. Optimize
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I write a test case, write an empty skeleton of the class/method, then make the test pass by writing code. Now where have I seen people do that before? :twisted:

Seriously though, test driven development just results in the cleanest and most flexible interfaces you can imagine.

I'd really like to give pair programming a chance too but the team at my workplace is too small to convince my boss it's a good idea. Maybe when I get to SitePoint... they're an agile bunch :D
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I bought an arcade game script, *wont say from where*, and the php/html pages it came with were horrendous. I ended up just coding my own pages.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Well I learned that this works today..

Code: Select all

if (false)
{
    echo 'yo what\'s up';
}{
    echo 'this actually works?';
}
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

8O
Is that like... An invisible else??
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Post by Chalks »

superdezign wrote:8O
Is that like... An invisible else??
IT'S MAGIC!
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I say we use the influence of DevNet to deprecate the word else! :lol:
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Oh astions, you are such a liar!! :evil:

I looked at that code just now and realized what's happening. This is perfectly valid code:

Code: Select all

echo $foo;

{
    echo $bar;
}
See what's happening?

Just like in C++, you can create blocks of code with no meaning simply for organizational purposes. That doesn't create an else, it just doesn't meet the if-statement condition. It'd print the second part regardless of the condition being true or false.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Well there was supposed to be an else there..

See, this is the kind of stuff I am talking about.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

astions wrote:Well there was supposed to be an else there..

See, this is the kind of stuff I am talking about.
Yes, I certainly see the nightmare of code you are dealing with. Ewww.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

If you see if{ statement }{} in your code immediately kill the previous coder..or do something more politically correct to him :-D
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

It was something like..

Code: Select all

if ($thisvariable > $thatvariable && $somethingelse < $anothersomethingelse) { $ErrAry[$i]['index'] = "Really long error message"; $Errcnt++;}
{
    // tons of code here..
}
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Freaky. You'll need to find the coder and give him a dirty look. He'll know what he did. :P

If he doesn't, then he genuinely does suck and tried his best.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That sucks.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

I hate:

1) Functions longer than 80-100 lines
2) Classes with more than half a dozen (or dozen at most) functions
3) Stupid comments like (Initialize variable)
4) Non-existant conventions (MyClass mized with My_Class)
5) Complicated code
6) Inconsistent file naming conventions (Smarty.php, mysmarty.class.php, etc)
7) HTML mixed with PHP - excluding template specific logic
8) JavaScript mashed with PHP or AJAX hell
9) Cross frame scripting
10) Monolithic applications, poor separation of concerns, etc
11) Poor file structures

Although I usually get at least one thing (an 'oh good idea' moment) on every peice of code I work on, so I guess it's not a total loss.
Post Reply