You are here: Re: Can this code be improoved? If so how? « PHP Language « IT news, forums, messages
Re: Can this code be improoved? If so how?

Posted by Daedalus.OS on 05/27/05 12:31

I'm feeling really kind tonight so here is an exemple to illustrate what
kimmo might mean.
Using an array instead of those never ending if condition ... and merging 2
recursive
test into 1. Sometimes a good book is a good friend. Good luck.

<?
/*
Creating an array to hold your holidays with keys set
to the dates an values set to their "WILL_SHIP" code (A trough F)
*/

$HOLIDAYS = array(
'Nov 23'=>'F', 'May 27'=>'E', 'Jul 1'=>'E',
'Sep 2'=>'E', 'Oct 7'=>'E', 'Nov 8'=>'E',
'Nov 24'=>'E', 'Dec 23'=>'E', 'May 28'=>'D',
'Jul 2'=>'D', 'Sep 3'=>'D', 'Oct 8'=>'D',
'Nov 9'=>'D', 'Nov 25'=>'D', 'Dec 24'=>'D',
'May 29'=>'C', 'Jul 3'=>'C', 'Sep 4'=>'C',
'Oct 9'=>'C', 'Dec 25'=>'C', 'Jan 1'=>'C',
'May 30'=>'B', 'Jul 4'=>'B', 'Sep 5'=>'B',
'Oct 10'=>'B', 'Dec 26'=>'B', 'Jan 2'=>'B'
);

/*
Then later in your script the test would look like this
Note that this code is an exemple only ...
I didn't try to rewrite nothing but the 2 loops with little
regards to the rest of the code (Don't use it as is).
*/

if (isset($HOLIDAYS[$DELAYDAYFL])){
$IS_SHP_HOLIDAY = true;
$ORDER_WILL_SHIP = HOLIDAY_SHIP_TEXT .' '.
${'ORDER_WILL_SHIP'.$HOLIDAYS[$DELAYDAYFL]};
}else{
$IS_SHP_HOLIDAY = false;
}

/*
Basically the test use what is contain by $DELAYDAYFL
as the a key for the $HOLIDAYS array. If it is set
(let say $DELAYDAYFL = 'Nov 23'), since $HOLIDAYS['Nov 23'] is set,
this test will pass. Otherwise (let say $DELAYDAYFL = 'Nov 20'),
since $HOLIDAYS['Nov 20'] is not define, the test will fail.

${'ORDER_WILL_SHIP'.$HOLIDAYS[$DELAYDAYFL]}
This mean: Concat the string 'ORDER_WILL_SHIP' and
the value in $HOLIDAYS[$DELAYDAYFL] (wich will be A-F)
and use the result as a variable name...
*/

?>

Dae


"Kimmo Laine" <eternal.erectionN05P@Mgmail.com> wrote in message
news:%Xzle.34$WG5.33@reader1.news.jippii.net...
> "Michael" <mids1999@ptd.net> wrote in message
> news:S1ydnd6gyMjJXwvfUSdV9g@ptd.net...
>> Can this code be improoved? If so how?
>> I am new to php. This is one of my first scripts.
>> Thank you
>
>
> Don't get offended, but... It's the single most ugly and discusting code
> I've ever seen and I'm sure there are ways improve it. For example an if
> statement with over 20 conditions is quite anal and clearly something one
> would do with an array.
>
> It lacks comments. I have no idea what it is supposed to do. Adding
> comments and explanation would greatly improve it. Re-thinking the
> structure would help
>
> $STDSHIPWD = 'true'; ??? What the fuck is this? don't make it a string,
> just simply
> $STDSHIPWD = true;// or false
>
> Then later when you compare
> $STDSHIPWD == 'true' && $IS_SHP_HOLIDAY == 'false'
> all you need is
> $STDSHIPWD && !$IS_SHP_HOLIDAY etc...
>
> Those were just few things I could think right now. As once said in Beavis
> and Butt-head: "This thing sucks more than anything that has ever sucked
> before."
>
> (Yes, I understund that it is one of your first codes, and you should
> think about getting a book where they teach you the basic ideas of
> programming - such as using functions and arrays. The way your doing is
> like they used to do it in the 70's and 80's with assembly code. Things
> have advanced since those days.)
>
> --
> Welcome to Usenet! Please leave tolerance, understanding
> and intelligence at the door. They aren't welcome here.
> eternal piste erection miuku gmail piste com
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация