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
HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Wheany posted:

I once used Δx and Δy (or similar) variable names in Java in a toy project.

Writing a chess program I really wanted to use the unicode chess symbols as enum values, sadly* C# wouldn't allow it (although it will allow them in the comments).

*wisely

Adbot
ADBOT LOVES YOU

Dren
Jan 5, 2001

Pillbug

zergstain posted:

How do I linked list?
code:
    t = *headp;
    while (t != NULL && t->asof != asof)
        t = t->next;

     if (t == NULL) {
        t = xcalloc(1, sizeof (struct saves));
        t->count = 1;
        t->asof = asof;
        if (*headp == NULL) {
            assert(tail == NULL);
            *headp = tail = t;
        } else {
            assert(tail != NULL);
            tail->next = t;
            tail = t;
        }
    }
tail is initialized to NULL, and only gets assigned at the point you see, asof is a parameter to the function, as well as headp. xcalloc() is of course like the xmalloc() I mentioned (we also have xstrdup()). This code uses 4 space indents while the surrounding code uses tabs.

The function is supposed to build a linked list of times and paths.

Your code is chock full of horrors.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Thanks for letting him know.

zergstain
Dec 15, 2005

Dren posted:

Your code is chock full of horrors.

This code was written in 1998 with tabs, and in 2003 it got changed to spaces. I committed a version that isn't broken today.

Dren
Jan 5, 2001

Pillbug

zergstain posted:

This code was written in 1998 with tabs, and in 2003 it got changed to spaces. I committed a version that isn't broken today.

Which one did you pick? Does your place have a standard?

zergstain
Dec 15, 2005

Dren posted:

Which one did you pick? Does your place have a standard?

Standard is tabs, but it either wasn't always this way, or a lot of people don't care. I always just use what the rest of the file uses because mixing them is just awful. So I changed that code to tabs. As well as made it not crash when you have more than 1 item to insert in the list.

zergstain
Dec 15, 2005

I'm not sure which is worse, that code or the fact it's been broken for 15 years.

Sang-
Nov 2, 2007

HappyHippo posted:

Writing a chess program I really wanted to use the unicode chess symbols as enum values, sadly* C# wouldn't allow it (although it will allow them in the comments).

*wisely

this is an amazing idea.

Opinion Haver
Apr 9, 2007

I love really weird SE questions: My customer wants me to record a video of how I develop his software product.

SplitDestiny
Sep 25, 2004
Sometimes I like to search github...

https://github.com/search?q=fwrite+extension%3Aphp+%24_REQUEST&type=Code&ref=searchresults

Volte
Oct 4, 2004

woosh woosh
https://github.com/search?q=extension%3Aphp+md5+password+mysql_query+%24_GET&type=Code&ref=searchresults

Jewel
May 2, 2009


Pfffhahha

Sebbe
Feb 29, 2004

Jewel posted:

Pfffhahha



Heh, I had to do a double-take when I saw that username. I actually know that guy. He's dyslexic, so he has a good excuse for misspelling things.

ymgve
Jan 2, 2004


:dukedog:
Offensive Clock
"indput" is a perfectly valid Danish-ified English word, though.

Not so much "acces"

gibbed
Apr 10, 2006

HappyHippo posted:

Writing a chess program I really wanted to use the unicode chess symbols as enum values, sadly* C# wouldn't allow it (although it will allow them in the comments).

*wisely
Does this count as a valid hack?

You may not be able to directly interact with the unicode symbols, but ToString() doesn't give a poo poo about it. :)

var piece = Chess.Piece.BlackPawn;
var piece = Enum.Parse(typeof(Chess.Piece), "♟");

gibbed fucked around with this message at 13:32 on May 11, 2013

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Sebbe posted:

Heh, I had to do a double-take when I saw that username. I actually know that guy. He's dyslexic, so he has a good excuse for misspelling things.
I think if you're dyslexic you really should be using a compiled language with a strong type system.

bucketmouse
Aug 16, 2004

we con-trol the ho-ri-zon-tal
we con-trol the verrr-ti-cal

https://github.com/search?q=extension%3Acpp+%2F%2F+gently caress+poo poo&type=Code&ref=searchresults

E: hahaha

bucketmouse fucked around with this message at 17:49 on May 11, 2013

gonadic io
Feb 16, 2011

>>=

Plorkyeran posted:

I think if you're dyslexic you really should be using a compiled language with a strong type system.

Nah, then you get nothing but compile errors and it takes ages to get anything done.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

code:

gently caress->ppu->dump_vram();
gently caress->dump_ram();
exit(0);

Not the worst error handler I can think of.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I had to support an ancient PHP app back in the day (think like php 3.0) and I had no exposure to php before that. I basically had to learn it in one weekend and make this monstrously awful billing app that served millions of customers work. In my frustration I had several variables called things like gently caress, FUCKKK, and FUCKKKKKKKKYOOOOOOOOOUUUUUPHP but the thing eventually got working. A couple weeks ago one of the guys I used to work with got hold of me on LinkedIn and the first thing he told me was that they were all still there 'because if we tried to change one it broke everything'.

Damiya
Jul 3, 2012

Scaramouche posted:

I had to support an ancient PHP app back in the day (think like php 3.0) and I had no exposure to php before that. I basically had to learn it in one weekend and make this monstrously awful billing app that served millions of customers work. In my frustration I had several variables called things like gently caress, FUCKKK, and FUCKKKKKKKKYOOOOOOOOOUUUUUPHP but the thing eventually got working. A couple weeks ago one of the guys I used to work with got hold of me on LinkedIn and the first thing he told me was that they were all still there 'because if we tried to change one it broke everything'.

The horror is coming from inside the thread

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Scaramouche posted:

I had to support an ancient PHP app back in the day (think like php 3.0) and I had no exposure to php before that. I basically had to learn it in one weekend and make this monstrously awful billing app that served millions of customers work. In my frustration I had several variables called things like gently caress, FUCKKK, and FUCKKKKKKKKYOOOOOOOOOUUUUUPHP but the thing eventually got working. A couple weeks ago one of the guys I used to work with got hold of me on LinkedIn and the first thing he told me was that they were all still there 'because if we tried to change one it broke everything'.

This is a form of immortality. Your legacy will live on. In the year 2100 someone will see those variables and do a git blame on them and remember you. Because I'm sure this app was completely version controlled.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Scaramouche posted:

I had to support an ancient PHP app back in the day (think like php 3.0) and I had no exposure to php before that. I basically had to learn it in one weekend and make this monstrously awful billing app that served millions of customers work. In my frustration I had several variables called things like gently caress, FUCKKK, and FUCKKKKKKKKYOOOOOOOOOUUUUUPHP but the thing eventually got working. A couple weeks ago one of the guys I used to work with got hold of me on LinkedIn and the first thing he told me was that they were all still there 'because if we tried to change one it broke everything'.

The real coding horror is that you can't change a goddamned variable name in PHP without everything breaking.

Hughlander
May 11, 2005

Volmarias posted:

The real coding horror is that you can't change a goddamned variable name in PHP without everything breaking.

More like PHP jockeys trying to refactor without an IDE and missed half the files.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Hughlander posted:

More like PHP jockeys trying to refactor without an IDE and missed half the files.

Or globally replacing every instance with names that were already in use.

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.
php:
<?
function doReports() {
 
    /*
        Just when I thought it couldn't get any worse...
    */
?>
This does not bode well...

(Turns out that it's a "reports" dispatch function because some brilliant predecessor decided that the way to maintain multiple user-sites was to have a bunch of files which called dispatch functions, and then copy the files to a new directory every time you want to set up a new user site. This means that "adding a new feature" means "find an appropriate-ish dispatch file and shoe-horn it in there")

gently caress.

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.
php:
<?
if($dates)foreach($dates as $key => $value)
{                                          
    $year   = addslashes($value['y']);     
    $month  = addslashes($value['m']);     
    $day    = addslashes($value['d']);     
    $hm     = addslashes($value['i']);     
                                           
    $date = "$year-$month-$day $hm";       
                                           
    $this->data[$key] = $date;             
    //$this->data[$key] = $date;           
}                                          
?>
Oh, gently caress off.

Pilsner
Nov 23, 2002

bobthecheese posted:

php:
<?
function doReports() {
 
    /*
        Just when I thought it couldn't get any worse...
    */
?>
This does not bode well...

(Turns out that it's a "reports" dispatch function because some brilliant predecessor decided that the way to maintain multiple user-sites was to have a bunch of files which called dispatch functions, and then copy the files to a new directory every time you want to set up a new user site. This means that "adding a new feature" means "find an appropriate-ish dispatch file and shoe-horn it in there")

gently caress.
Has anyone ever seen a method in code named Do____ (for example DoEmails) that wasn't crap? I assume it's a holdover from VB or something.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Pilsner posted:

Has anyone ever seen a method in code named Do____ (for example DoEmails) that wasn't crap? I assume it's a holdover from VB or something.

DoItInTheButt(...) :pervert:

Hughlander
May 11, 2005

Volmarias posted:

DoItInTheButt(...) :pervert:

Depending on implementation, a lot of crap.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

bobthecheese posted:

PHP code:
if($dates)foreach($dates as $key => $value)
{                                          
    $year   = addslashes($value['y']);     
Oh, gently caress off.

Cool, I see your coder copy-pasted the same php foreach tutorial as our did. Meaning he used foreach($dates as $key => $value), then $value['y'] instead of foreach($dates as $date) and $date['y']

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.
There is so much wrong with this code. So much. Just finding where things are rendered (and how) is a spaghetti mess, because it (appears to be) dependant on all of these inputs which are never actually set, or used, but are supposedly required.

For example, this is how that particular report page gets rendered:

Step 1: a call to "endcustomer/admin/reports.php?rp=2
"rp=2" refers to "report page number 2" because this is the only way to add new pages to the "reports.php" script

php:
<?
// this file sets a the "ROOT_RELATIVE" constant to be... usually '../' or '../../'. Because that could never go wrong
include_once ('pathdepth.php'); // this file sets a the "ROOT_RELATIVE" constant to be... usually '../' or '../../'. Because that could never go wrong
include_once ('../rtoid.php'); // this is a file which defines which end customer the code is meant to run as. It sets an ID.
// include some application build-up junk
doReports();
?>
In shared/adminfunctions.php we find the "doReports" function (and a whole bunch of other poo poo)
php:
<?
function doReports() {

    /*
        Just when I thought it couldn't get any worse...
    */

    // a bunch of stuff until we get the report page - most of it isn't used in this function at all

    $reportpage = getInt('rp',REPORTPAGE_GROUP);

    if ($reportpage == REPORTPAGE_HOMEPAGE) {
        // a bunch more stuff, and a poo poo-load of else-ifs for different reports
    } elseif ($reportpage == REPORTPAGE_STUDENT || $reportpage == REPORTPAGE_GROUP) {
        // oh wow, two unrelated reports share the same function... and model
        require_once(ROOT_RELATIVE . 'model/admin/report_student_results.model.php');
        $request = HTTPRequest::getInstance();
        $view = new StudentResultsReport();

        // this part is a decoy because nothing ever sets this action. Anywhere.
        $action = $request->get('form_action');

        // OK, so we call "execute" on this model... that sounds straight forward
        echo $view->Execute($action);

        die();

        //doStudentReport();
    }
}
?>
Let's find this model...

php:
<?
class StudentResultsReport extends FooController
{
    function getCollatedResults( $groupId=null, $search=null, $assess_types = Array(), $showAll=false )
    {
        // a bunch of poo poo which runs bad queries.
    }
    
    var $templates = Array(
        "view" => "student_results"
    );

}
?>
Well there's no execute function, but that probably came from the FooController... but the "action" is empty, so how will it know to call the getCollatedResults function?

php:
<?
class FooController
{
    function Execute($action=null)
    {
        // if the action isn't set, it automatically becomes "view"
        $action = $action ? $action : 'view';
        
        // looks to see if there's a tempalte for that action
        $request = HTTPRequest::getInstance();
        if(isset($this->templates) && is_array($this->templates) && array_key_exists($action, $this->templates)){
            $template = $this->templates[$action];
            $handler = new PHPTemplate($template);
            return $handler->render($request, $this);
        }
        
        // no template? maybe we have a function... should we use that "hasAction" function below? nah...
        $call   = "do_$action";
        if(is_callable(Array($this, $call)))
            return $this->$call($request);
        else
            return $this->render($request);            
    }
    
    function hasAction($action)
    {
        $call   = "do_$action";
        return (is_callable(Array($this, $call)));
    }
}
?>
Mmmm redundancy... seeing as we don't have a "do_view" function (which would be the default), then we're probably using a template... and according to the original model, we're looking for the "student_results" template... which is a perfect place to put an unrelated report...

php:
<?
if( $request->rp == REPORTPAGE_GROUP ) {
    // a bunch of report stuff
} else if ($request->rp == REPORTPAGE_STUDENT ) 
{
    // hey look, more, but different stuff
}
else
  // a function call to build a different report...
?>
No where in there is a call to "getCollatedResults" made.

This was actually a pretty tame one. I found another where it was pulling templates from the database, so if you didn't have an "up to date" database, certain pages wouldn't work. Pages with hard-coded URLs. That depend on the database to tell them which source files to read.

gently caress fuckity gently caress gently caress gently caress.

To be clear, none of that code has ACTUAL comments, except for the one that I posted earlier. The comments were put in by me to skip a lot of the unpleasantness.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Volmarias posted:

DoItInTheButt(...) :pervert:

DoTheNeedful()

No Safe Word
Feb 26, 2005

Scaramouche posted:

DoTheNeedful()

Oh my god yes, now you need to work "I have a doubt" in there somewhere as I heard that one quite a bit as well

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

No Safe Word posted:

Oh my god yes, now you need to work "I have a doubt" in there somewhere as I heard that one quite a bit as well

That's from Spanish speakers, since the word we use when we are uncertain of something is "duda" which is literally translated as doubt. I believe that native English speakers interpret doubt as something negative so it seems weird to use it in place of the word question.

Summit
Mar 6, 2004

David wanted you to have this.
code:
int k = 0;
foreach (string str in _term.Split(' '))
{
	if (k == 0) Season = str;
	if (k == 1) yr = str;
	k++;
}
Sometimes I find code in our codebase that I just find adorable :3:

Summit fucked around with this message at 21:19 on May 14, 2013

raminasi
Jan 25, 2005

a last drink with no ice

Hard NOP Life posted:

That's from Spanish speakers, since the word we use when we are uncertain of something is "duda" which is literally translated as doubt. I believe that native English speakers interpret doubt as something negative so it seems weird to use it in place of the word question.

"I have a doubt" is a bad translation of "I have a question," which, if I'm not mistaken, would use "pregunta" instead of "duda." I've only seen "I have a doubt" from Indians. The reason it's weird isn't connotation, it's the fact that using "doubt" as a singular noun in English is extremely uncommon.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

GrumpyDoctor posted:

"I have a doubt" is a bad translation of "I have a question," which, if I'm not mistaken, would use "pregunta" instead of "duda."

You're technically correct about "pregunta", but at least in Mexico it's just as common to use "duda". Also thanks for introducing me to the term singular noun, it's frustrating to try and talk about a something where your vocabulary is limited on the subject.

Deus Rex
Mar 5, 2005

Wheany posted:

Cool, I see your coder copy-pasted the same php foreach tutorial as our did. Meaning he used foreach($dates as $key => $value), then $value['y'] instead of foreach($dates as $date) and $date['y']

it's possible the data looks like

PHP code:
$dates = array(
  "nine eleven" => array(
    "y" => "2001",
    "m" => "9",
    "d" => "11"
  ));
note that the code does use $key later in the loop

Deus Rex fucked around with this message at 23:21 on May 14, 2013

Adbot
ADBOT LOVES YOU

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:
"Sure, I'll just dig in there and find out why searches aren't working like they should in this goddamn software we pay way too much money for!"

PHP code:
if($searchType == "simple"){
  $results_query = $this->XXXapi->api_prepare_simple_query($searchCollection, $searchFieldsTermsMode, $searchReturnFields, $orderby, $maxrecs, $startrecord);
} else {
  //make advanced if need be
  $results_query = $this->XXXapi->api_prepare_simple_query($searchCollection, $searchFieldsTermsMode, $searchReturnFields, $orderby, $maxrecs, $startrecord);
}
... I see. This must be some usage of the word "advanced" that I haven't encountered before.

Edit: I just found this in the same code.

PHP code:
  private function parse_htmldoc($file){
    $bodytag = strpos($file, "<body>");
    //echo "body tag is: ".$bodytag;
    $file = substr($file, $bodytag+6);

    //remove second body tag if exists
    //use while since there can be many body tags
    $moreBodyTags = true;
    $preBodyHTML = "";
    do{
      if(preg_match("/<body>/", $file)){
        //echo "here...<br />";
        $htmltag = strpos($file, "<html>");
        $prebody = substr($file, 0, $htmltag);
        $prebody = str_replace("</body>", "", $prebody);
        $prebody = str_replace("</html>", "", $prebody);

        $bodytag = strpos($file, "<body>");
        //$prebody = substr($file, 0, $bodytag);
        //echo "PREBODY:<br />".$prebody;
        $preBodyHTML .= $prebody;
        $file = substr($file, $bodytag+6);
      } else {
        $moreBodyTags = false;
      }
    } while($moreBodyTags);
    //echo $preBodyHTML;
    //echo ".......<br /><br />----prebody done";
    //exit;
    $file = $preBodyHTML . $file;
    $file = str_replace("<b><td", "<td", $file);
    $file = str_replace("</td></b>", "</td>", $file);
    $file = str_replace("</body>", "", $file);
    $file = str_replace("</html>", "", $file);

    return $file;
  }
This software costs us hundreds of thousands annually...

Tad Naff fucked around with this message at 23:41 on May 14, 2013

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