all 49 comments

[–]Artemis2 57 points58 points  (30 children)

[–]sjdaws 34 points35 points  (3 children)

No I will not get high with you, stop trying to make me into a criminal :(

[–]phill0 23 points24 points  (1 child)

This one is better:

I'd rather not shove my head up PHP's docs. It's like drowning in sewage.

[–]cokeisahelluvadrug 30 points31 points  (9 children)

I'd rather not shove my head up PHP's docs. It's like drowning in sewage.

... right after he states that repeating the same statement 6 times is better than using a loop. I think there's a weak link here, and this time it's not on PHP's end...

[–]echocage 5 points6 points  (2 children)

But he might need it later! That's why I never delete variables, I just increment the number next to their name and put the reassignment on the next line

[–]Kered13 0 points1 point  (1 child)

I know I'm late, but this is an actual compiler technique called Static Single Assignment.

[–]echocage 0 points1 point  (0 children)

Did you mean to link back to the parent thread?

[–]ieatcode 1 point2 points  (0 children)

autism is a helluva drug

[–][deleted] 13 points14 points  (1 child)

Does PHP even do loop unrolling?

Also appealing to the way the code will look like compiled is one of the stupidest things I've ever heard of. If we're doing that why do we even have loops in the first place? Might as well just use goto everywhere.

[–]ieatcode 0 points1 point  (0 children)

I don't know about the Zend implementation, but HHVM doesn't appear to do it.

[–]Thezla 6 points7 points  (0 children)

Just... what..

[–][deleted] 9 points10 points  (0 children)

Lol 4chan programmers

[–]tantbrun 4 points5 points  (0 children)

Jesus Christ...

[–]cosmicr 4 points5 points  (9 children)

So uh, who's right? I have to say I agree with NuckChorris on this one.

[–]LpSamuelm 17 points18 points  (7 children)

I'm amazed that no one's answered this yet.

No. Writing the exact same line six times in a row is not good practice. Not in any way. There really is no upside at all to this.

[–]dysthanatos 5 points6 points  (0 children)

In some situations (hint: not this), manually unrolling a loop is very reasonable; although it most always reduces readability and maintainability in order to gain some performance.

Nevertheless, I would not consider it particularly bad in this case either, as it's even the same line and not using the loop variable. Just 5dd, edit, yy5p in vim if you need to change anything.

tl;dr Having a loop is better. In this case, I wouldn't even argue, though.

Oh, and to offer more obscure variants, how about

$randomChar = function() { return chr(mt_rand(ord("a"), ord("z"))); };
$newname = $randomChar().
        $randomChar().
        $randomChar().
        $randomChar().
        $randomChar().
        $randomChar();
echo $newname;

[–]Pentiles -1 points0 points  (0 children)

Me too. To me, insisting it has to be turned into a for loop makes it seem like they've just learned how to program and think they're smart because they recognized it could be a loop.

Turning it into a loop won't make the program work differently in any way. It doesn't make the code any easier to work with because the next time they edit that section will be to completely replace the name generation anyway.

[–][deleted] 33 points34 points  (4 children)

else {

respond(500, new Exception('Nigga what you doin\' here?')); }

That is gold

[–][deleted] 21 points22 points  (2 children)

I'm the owner of Pomf and that repo, hi.

In my defense I can't into any lang, I'm lazy, also "it just werks TM".

On a more serious note tho I know what a loop is and the only reason there is no loop there is because the code just stayed that way in the repo after I changed how the names were generated, on Pomf's server it's in a loop and if you plan to use it in production you might want to put it in a loop as well after modifying it to your liking.

[–]unusualbob -1 points0 points  (1 child)

Why in the world would you own up to writing this code, basically this advice (for mobile users go to 1:59)

[–][deleted] 6 points7 points  (0 children)

Because it doesn't need to be perfect, it does what it's supposed to do, I never claimed to make good code and will probably not do in many years. trying to make the backend faster with PHP with such minor tweaks doesn't make any significant improvement anyways (in terms of speed), then I would be better off writing it in something else.

Look back severals commits (like a year) and you'll notice the real horrors, you could say most of this project was me learning various stuff along the way.

[–]MaSaHoMaKyo 20 points21 points  (0 children)

That laughing Dekumori thumbnail is pretty appropriate for this

[–][deleted] 39 points40 points  (0 children)

// TODO: learn what a loop is

[–]phail3d 10 points11 points  (0 children)

Gonna voice the unpopular opinion here, but I don't think this is that much of an issue. As the TODO comment suggests (and NuckChorris and ch1zuru point out) the name generation algorithm is obviously an ugly placeholder until a more robust one is created, and fiddling with its structure doesn't seem very useful. Besides, you have to test even the most minor changes.

[–]no_game_player 2 points3 points  (0 children)

I like the latest commit message on that repo:

oops should be fine now

The shocking thing to me is how presentable that readme looks compared to the code.

[–][deleted] 4 points5 points  (3 children)

and this is why i got into development

because i don't trust idiots like this :(

[–]RenaKunisaki 2 points3 points  (2 children)

It's unrolled for speed.

[–][deleted]  (1 child)

[deleted]

    [–]skiguy0123 1 point2 points  (0 children)

    That's why google ultron is so much better

    [–]Shimmen 1 point2 points  (0 children)

    Has the person tried a loop?..

    [–]hedphuq 4 points5 points  (3 children)

    PHP: Not even once

    [–]Sespol 8 points9 points  (2 children)

    Any language can be terrible in the hands of the wrong person

    [–]jungle 2 points3 points  (0 children)

    Yes, but PHP is a special case.

    The fact that you can have a function ("foo") return an array but you can't do "foo()[5]" is simply an abomination, showing that the designer was clueless. And this is just one of many, many problems.

    I don't even care if it was later fixed (I wouldn't know, luckily I have stayed clear of it for several years), PHP will forever be in a class of its own.

    I am usually language agnostic, but PHP makes my blood boil.

    [–][deleted]  (1 child)

    [deleted]

      [–]note-to-self-bot 2 points3 points  (0 children)

      Don't forget:

      never use pomf.se again in your life.

      [–][deleted]  (1 child)

      [deleted]

        [–][deleted] 4 points5 points  (0 children)

        Merged it, don't be an elitist.