<?
package MetarTools
;

use 
5.005;
use 
strict;
use 
vars qw($VERSION);

$VERSION '0.1';

# define weather types
my @wx_types qw(MI PI BC DR BL SH TS FZ DZ RA SN SG IC PE GR GS UP BR FG FU VA DU SA HZ PY PO SQ FC SS DS);
my $wx_pat join "|",@wx_types;

# define cloud condition types
my @sky_types qw(CLR SKC FEW SCT BKN OVC VV);
my $sky_pat join "|", @sky_types;

sub convertLST {
    eval { require 
Date::Calc };
    if ($@) { die 
"Date::Calc module required for time conversions\n" }

    
my $self shift;
    
my ($yr$mo$tz) = @_;
    
$tz = -6 unless $tz;
    
my @roundUTC;
    
my @roundLST;
    
my ($round,$dy,$hr,$mn,$hr_ampm,$ampm);
    
my @utc;
    
my @lst;

    if (!
defined($self->{DAY})) { $self->processDatetime() }
    if (
defined($self->{DAY})) {
        
$dy $self->{DAY};
        
$hr $self->{HOUR};
        
$mn $self->{MINUTE};

        @
utc = ($yr,$mo,$dy,$hr,$mn,0);

        @
lst Date::Calc::Add_Delta_DHMS(@utc,0,$tz,0,0);

        if (
$lst[3] == 0) { $hr_ampm 12$ampm 'am' }
        
elsif ($lst[3] == 12) { $ampm 'pm' }
        
elsif ($lst[3] > 12) { $hr_ampm $lst[3] - 12$ampm 'pm' }
        else { 
$hr_ampm $lst[3] ; $ampm 'am' }
        
$ampm "$hr_ampm:$mn$ampm";

        
$self->{DATE_LST} = sprintf("%4d%02d%02d %02d:%02d",@lst[0..4]);
        
$self->{YEAR_LST} = $lst[0];
        
$self->{MONTH_LST} = $lst[1];
        
$self->{DAY_LST} = $lst[2];
        
$self->{HOUR_LST} = $lst[3];
        
$self->{MINUTE_LST} = $lst[4];
        
$self->{TIME_LST} = sprintf "%d:%02d"$lst[3],$lst[4];
        
$self->{TIME_LST_ENGLISH} = $ampm;

        if (
$mn >= 45) { 
            @
roundUTC Date::Calc::Add_Delta_DHMS(@utc[0..3],0,0,0,1,0,0);
            @
roundLST Date::Calc::Add_Delta_DHMS(@lst[0..3],0,0,0,1,0,0);
            
$round++;
        }
        
elsif ($mn 15) {
            @
roundUTC = (@utc[0..3],0,0);
            @
roundLST = (@lst[0..3],0,0);
            
$round++;
        }
        if (
$round) {
            if (
$roundUTC[2] == 0) { $hr_ampm 12$ampm 'am' }
            
elsif ($roundUTC[2] == 12) { $ampm 'pm' }
            
elsif ($roundUTC[2] > 12) { $hr_ampm $roundUTC[2] - 12$ampm 'pm' }
            else { 
$hr_ampm $roundUTC[2] ; $ampm 'am' }
            
$ampm "$hr_ampm:00$ampm";

            
$self->{DATE_UTC_ROUND} = sprintf("%4d%02d%02d %02d:%02d",@roundUTC[0..4]);
            
$self->{YEAR_UTC_ROUND} = $roundUTC[0];
            
$self->{MONTH_UTC_ROUND} = $roundUTC[1];
            
$self->{DAY_UTC_ROUND} = $roundUTC[1];
            
$self->{HOUR_UTC_ROUND} = $roundUTC[2];
            
$self->{TIME_UTC_ROUND} = "$roundUTC[2]:00";
            
$self->{TIME_UTC_ROUND_ENGLISH} = $ampm;

            if (
$roundLST[2] == 0) { $hr_ampm 12$ampm 'am' }
            
elsif ($roundLST[2] == 12) { $ampm 'pm' }
            
elsif ($roundLST[2] > 12) { $hr_ampm $roundLST[2] - 12$ampm 'pm' }
            else { 
$hr_ampm $roundLST[2] ; $ampm 'am' }
            
$ampm "$hr_ampm:00$ampm";
            
            
$self->{DATE_LST_ROUND} = sprintf("%4d%02d%02d %02d:%02d",@roundLST[0..4]);
            
$self->{YEAR_LST_ROUND} = $roundLST[0];
            
$self->{MONTH_LST_ROUND} = $roundLST[1];
            
$self->{DAY_LST_ROUND} = $roundLST[1];
            
$self->{HOUR_LST_ROUND} = $roundLST[2];
            
$self->{TIME_LST_ROUND} = "$roundLST[2]:00";
            
$self->{TIME_LST_ROUND_ENGLISH} = $ampm;
        }
    }
}
?>
<?
class some_y_php4_class {

    function 
some_random_method() {
        
$this dont_do_this_ever_horrible_practice;
    }

}
?>
stupid porgramming - TranceAddict Forums - Technology & Gadget Zone
return to tranceaddict TranceAddict Forums Archive > Other > Technology & Gadget Zone

 
stupid porgramming
View this Thread in Original format
malek
I have to maintain software and some of the code I see is heart braking... its bad really bad.

If you have examples of your own, please post:D


example 1:


start = 1
if (start > 1) then
... code
else
... code
end if


example 2:

if (a > 0 )
...if (b > 0)
.......code
.......x = 2
...else
.......code
.......x = 2
...end if
else
...if (c > 0)
.......code
.......x = 2
...else
.......code
.......x = 2
end if
_Nut_
PHP:




All part of a METAR reading subroutine. This is about 1% of it, and I just found an issue in the LST conversion... boo urns. broken
winnowingfan51
PHP:




:wtf:


Yea... in our CMS that we use, the guy that wrote it assigned $this to something else. SERIOUSLY WTF?!
LeopoldStotch
seriously, i have seen this before at work.

code:
a=true; i=0; while(a == true) { i++; if (i>0) a = true; }
witchsabbath258
quote:
Originally posted by LeopoldStotch
seriously, i have seen this before at work.

code:
a=true; i=0; while(a == true) { i++; if (i>0) a = true; }



Thats almost as bad as this.


code:
some_psuedo_function { if(x == 0) { return x; } else { //continue } }



Though technically its bad practice to have a return anywhere but the last statement (at least thats what I been told :p).

Also I guess you could be checking something for x and then doing something special if it doesnt meet the return value or something, I dont know.

Over complexity.
LeopoldStotch
quote:
Originally posted by witchsabbath258
Thats almost as bad as this.


code:
some_psuedo_function { if(x == 0) { return x; } else { //continue } }



Though technically its bad practice to have a return anywhere but the last statement (at least thats what I been told :p).

Also I guess you could be checking something for x and then doing something special if it doesnt meet the return value or something, I dont know.

Over complexity.


you are right, however i have been in many companies with many people touching the CVS, and i have learned the "less" changes, the better. i have seen that before, and i have also seen this.

code:
some_pseudo_function { if (x ==0) return x; //continue }


where everyone knows once the prog executes the return, it pops out of the function. bad programming practices, but sometimes the "less is more" philosophy works.
malek
quote:
Originally posted by LeopoldStotch
seriously, i have seen this before at work.

code:
a=true; i=0; while(a == true) { i++; if (i>0) a = true; }


wow:nervous:
Dr. Cfire
How about bad variable names.
In one function the idiot assigned these variables

Torque
torque
Ratio
ratio1
Maintorque
mainTorque
LeopoldStotch
quote:
Originally posted by Dr. Cfire
How about bad variable names.
In one function the idiot assigned these variables

Torque
torque
Ratio
ratio1
Maintorque
mainTorque


someone told me this quote ... "if you find yourself F3ing a lot, then the person who wrote the program sucks at naming variables" (he was referencing the F3 function to "goto variable decleration" in eclipse).
CLICK TO RETURN TO TOP OF PAGE
 
Privacy Statement