PHP Templates problems


#1

Here is a exemple of the template for bender-episode-1

<?php
/**
 * Auto-generated code below aims at helping you parse
 * the standard input according to the problem statement.
 **/

fscanf(STDIN, "%d %d",
    $L,
    $C
);
for ($i = 0; $i < $L; $i++)
{
    $row = stream_get_line(STDIN, 101 + 1, "\n");
}

// Write an action using echo(). DON'T FORGET THE TRAILING \n
// To debug (equivalent to var_dump): error_log(var_export($var, true));

echo("answer\n");
?>
  1. echo is not a function, its a keyword, so it shouldn’t have parateses.
    so just: echo "answer\n";, or echo 'answer', PHP_EOL;
    (also remove them from the comment)

  2. ?> indicates the start of an raw output, and as there is no raw output behind it, it’s not needed, and only increase the chans of error, if someone put some whitespace behinds it.

  3. stream_get_line(STDIN, 101 + 1, "\n"); Why 101 + 1??

  4. fscanf(STDIN, "%d %d" have unnessesary use of dubble quotes, single quotes should be used here, according to some coding styles.


#2

Nearly every templates has the same issues. The javascript template is a big finger to ES6 for example.

The fact is that CodinGame use a stub language to generate every languages templates. So they can’t be precise in all languages, it would require many code (and probably more bugs).

The 101 + 1 is because 101 can be a variable. So it can be length + 1. CodinGame just don’t handle the case where the length it hardcoded.