Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Randomosity
Sep 21, 2003
My stalker WAS watching me...
Holy poo poo.

I've seen some awful code on my job... but THIS has to be the worst thing I've ever seen.

The function is used to create a series of dropdown boxes to select month, day, year, hour, and minute.

php:
<?
function displayHTMLMenu( $type, $name, $class, $value_digits, $value_selected, $value_top_name, $value_top_value, $on_change_function_name, $return_or_echo_content = "echo" )
{
    //global $CM_app_system_path;

    //    get menu data START
    if ($type == "month_names")
    {
        if( $_SESSION["sessionStat"]["lowresolution"] )
        {
            $nxtFile = LIST_DATA_FILES_PATH . "list_date_month_names_abbrv.txt";
        }
        else
        {
            $nxtFile = LIST_DATA_FILES_PATH . "list_date_month_names.txt";
        }
    }
    else if ($type == "day_numbers")
    {
        $nxtFile = LIST_DATA_FILES_PATH . "list_date_day_numbers.txt";
    }
    else if ($type == "year_numbers")
    {
        $nxtFile = LIST_DATA_FILES_PATH . "list_date_year_numbers.txt";
    }
    else if ($type == "year_numbers_current_and_previous_in_january")
    {
        // no file for year_numbers_current_and_previous_in_january, generate dynamically
        $all_data_array[] = array (date("Y"), date("Y"), date("Y"));
        
        if (date("M") == "Jan")
        {
            $all_data_array[] = array (date("Y")-1, date("Y")-1, date("Y")-1);
        }
    }
    else if ($type == "hour_numbers")
    {
        $nxtFile = LIST_DATA_FILES_PATH . "list_date_hour_numbers.txt";
    }
    else if ($type == "minute_numbers")
    {
        $nxtFile = LIST_DATA_FILES_PATH . "list_date_minute_numbers.txt";
    }
    else    // default
    {
        $nxtFile = LIST_DATA_FILES_PATH . "list_date_minute_numbers.txt";
    }

    if( isset( $nxtFile ) && file_exists( $nxtFile ) )
    {
        $fd = fopen ($nxtFile, "r") or die ("Could not open file");
        flock ($fd, 2);
        while (!feof($fd))
        {
            $buffer = fgets ($fd, 4096);
            $next_line_array = split("\|", $buffer);
            $all_data_array[] = $next_line_array;
            //echo $all_data_array[0];
        }
        flock ($fd, 3);
        fclose($fd);
    }
    else
    {
        // file not found
        //echo "<h1>file not found</h1>";
    }
    //    get menu data END

    $content_to_return = "<select name=\"$name\" class=\"$class\" onchange=\"$on_change_function_name(this);\">";
    
    if (!empty ($value_top_name) || !empty ($value_top_value))
    {
        $content_to_return .= "<option value=\"$value_top_value\">$value_top_name";
    }

    foreach ($all_data_array as $next_data_array)
    {
        //echo $next_data_array[0];
        if ($next_data_array[0] != "")
        {
            //    get next value START
            if ($value_digits == 1)    // no leading zeros
            {
                $next_value = $next_data_array[1];
            }
            else if ($value_digits == 2)    // leading zeros
            {
                $next_value = $next_data_array[2];
            }
            else
            {
                $next_value = $next_data_array[2];    // leading zeros, default
            }
            //    get next value END

            if ($next_value == $value_selected)
            {
                $content_to_return .= "<option value=\"$next_value\" selected>$next_data_array[0]";
            }
            else
            {
                $content_to_return .= "<option value=\"$next_value\">$next_data_array[0]";
            }
        }
    }

    $content_to_return .= "</select>";
    
    if( $return_or_echo_content == "return" )
    {
        return $content_to_return;
    }
    else
    {
        echo $content_to_return;
    }
?>
:froggonk:

Adbot
ADBOT LOVES YOU

Randomosity
Sep 21, 2003
My stalker WAS watching me...

shopvac4christ posted:

An enumeration I found, the values of which are used in a database table.

code:

    public enum FooType 
    {
        Foo = 0,
        Bar = 1,
        Baz = 3,
        Bip = 5,
        Bob = 10,
        Jam = 20
    }

They tried to come up with numbers that they could add together for a combination of options. :haw:


:suicide:

Everyone remember this when they hear CS students complaining about CPU logic and close-to-the-metal programming classes! :haw:

Randomosity
Sep 21, 2003
My stalker WAS watching me...
My boss found this today in our app.

code:
if( is_ipLogin ){
         auth.setSession_id( getLoginSessionId( returnHash.get( "user_id" ),returnHash.get( "contract_id" ),returnHash.get( "status_id" ), true ) );
} else {
         auth.setSession_id( getLoginSessionId( returnHash.get( "user_id" ), returnHash.get( "contract_id" ),returnHash.get( "status_id" ), false ) );
}	
Edit: Typo trying to format.

Randomosity fucked around with this message at 16:11 on Jun 13, 2008

Randomosity
Sep 21, 2003
My stalker WAS watching me...
Error handlers are just another form of control structure!
code:
 //TODO to stop mike having an appaplexy, cause this to crash so we can find the break!
try
{
     Integer.parseInt( cc_text_id_split[i] );
}
catch( NumberFormatException nfe )
{
    //continued logic
}
I want to kill the people whose code I now maintain. And wtf is an 'appaplexy'

Randomosity
Sep 21, 2003
My stalker WAS watching me...
I have discovered an unholy trifecta brewing in a project I will likely be working on soon.

Javascript
YUI
HUNGARIAN NOTATION

Pray for me.

Randomosity
Sep 21, 2003
My stalker WAS watching me...
Can anyone explain why PHP is like this?

php:
<?
if($undefined_var){ //Evaluates to false.
    ...
}

define('DEFINED', true);
if(DEFINED){ //Evaluates to true
    ...
}

if(NOT_DEFINED){ //Evaluates to true

}
?>
I've had this pop up in annoying circumstances twice this week. It's not major, but why in the world is PHP designed like that? Answer: PHP is a terrible language... that we all use anyway :)

Randomosity
Sep 21, 2003
My stalker WAS watching me...

ToxicFrog posted:

Who the gently caress uses floats to store monetary amounts :psyduck:

At the risk of sounding stupid, what's that preferred way?

VVV hah, I understand how floats are stored and their implicit fuzziness. I meant which variable type or some other method.

Randomosity fucked around with this message at 19:57 on Feb 24, 2011

Randomosity
Sep 21, 2003
My stalker WAS watching me...
My co-worker is a really smart programmer and a great guy, but he is convinced empty lines make code ugly and hard to read.

:eng99:

Adbot
ADBOT LOVES YOU

Randomosity
Sep 21, 2003
My stalker WAS watching me...
Found a bug in some inventory code today that was way, way old. It's bad programming, but it's bad because it expected PHP not to be quirky.

code:
$count = (string)$response->AvailableInventory;

if(!empty($count)){
        //Do stuff
}
Whoever wrote that (and, I don't think it was me, but it probably was) forgot that "0" string counts as empty. We couldn't update inventory to 0. Whoops! It probably shouldn't be cast into a string though.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply