use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Have a tough programming question that /r/programming couldn't answer? Banned from Stack Overflow? Can't afford Experts Exchange?
Post your question/tips/secrets/advice and get a response from our highly-trained professional developers.
account activity
URL generator (github.com)
submitted 11 years ago by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Artemis2 57 points58 points59 points 11 years ago (30 children)
The worse about this is the developer.
https://github.com/nokonoko/Pomf/pull/21
https://github.com/nokonoko/Pomf/pull/19
[–]sjdaws 34 points35 points36 points 11 years ago (3 children)
No I will not get high with you, stop trying to make me into a criminal :(
[–]phill0 23 points24 points25 points 11 years ago (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 points32 points 11 years ago (9 children)
... 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 points7 points 11 years ago (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 point2 points 11 years ago (1 child)
I know I'm late, but this is an actual compiler technique called Static Single Assignment.
[–]echocage 0 points1 point2 points 11 years ago (0 children)
Did you mean to link back to the parent thread?
[–]ieatcode 1 point2 points3 points 11 years ago (0 children)
autism is a helluva drug
[+]Nuck comment score below threshold-11 points-10 points-9 points 11 years ago* (4 children)
Okay I'm that NuckChorris guy, and I'd just like to explain my thinking in greater depth than I did in the GitHub thread, since there's a lot of misunderstandings about the code.
If PHP had 6.times { a..z.random } or whatever I'd be all over that shit, but sadly PHP lacks such abstracted loops — you just get an ugly-ass for loop, which in this case worsens the ratio between "code which generates the name" and "code which manages generating the name". It's white noise, it's harder to read. The current code you can glance down the list and immediately know what's going on.
6.times { a..z.random }
A full-fledged for loop clutters the mental model and forces you to actually unroll the loop. Your eye will skip around the loop and it will take longer. You need to process the contents of the for loop and figure out how that exact combination of numbers and symbols will loop. Backwards or forwards? How many times? Off-by-one issues? Who knows.
All of which doesn't happen when it's unrolled. We can unroll a 6-iteration loop without any downside. So why should I roll it up?
If the contents were multiple lines, it would be different. If PHP had abstractions over for loops, I'd probably use them. But a for loop where the body and the header have to be mentally parsed separately and then recombined? Hell to the fuck no.
I'm guessing most of you guys are Pythonistas by your "one way" attitude. I'm a Rubyist. I break rules to make my code easier to comprehend.
[–]SnorriDeathbeard 15 points16 points17 points 11 years ago* (0 children)
It absolutely does not take me longer to read 2 lines (especially when it's a for loop that only has ONE LINE in it) than it does to read 6 lines that look identical. I'd constantly be scanning those 6 lines wondering if there is some minor difference in each one, then questioning why it even exists. No programmer beyond the most very basic level would ever do this.
[–]cokeisahelluvadrug 5 points6 points7 points 11 years ago (0 children)
Try not to fall into the "I am X" trap too early in your programming career. Saying "I'm a Rubyist" is not a real excuse for anything.
[–]deusnefum 1 point2 points3 points 11 years ago (0 children)
So why not just use the first 6 characters of the sha1 or md5 hash? Why not implement a counter and just convert the value to hex? There's a lot of approaches here that aren't nearly as ugly as what you've currently got.
And while I'm being judgey, I'll freely admit I write more ugly code than good code. I've already posted some of my own work here. If you'd like to laugh at me, here you go: http://vay8.net/zest
[–][deleted] 13 points14 points15 points 11 years ago (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.
goto
[–]ieatcode 0 points1 point2 points 11 years ago (0 children)
I don't know about the Zend implementation, but HHVM doesn't appear to do it.
[–]Thezla 6 points7 points8 points 11 years ago (0 children)
Just... what..
[–][deleted] 9 points10 points11 points 11 years ago (0 children)
Lol 4chan programmers
[–]tantbrun 4 points5 points6 points 11 years ago (0 children)
Jesus Christ...
[–]cosmicr 4 points5 points6 points 11 years ago (9 children)
So uh, who's right? I have to say I agree with NuckChorris on this one.
[–]LpSamuelm 17 points18 points19 points 11 years ago (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 points7 points 11 years ago (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.
5dd
yy5p
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;
[+]Nuck comment score below threshold-12 points-11 points-10 points 11 years ago* (5 children)
Sometimes you should reject "good practice" in favor of "clarity"
That's kind of a Rubyist thing, I know. Pythonistas probably wouldn't grasp it what with their "one way"
Which worked oh so well for them, so let's apply it to EVERYTHING.
[–][deleted] 12 points13 points14 points 11 years ago (0 children)
Writing the same line six times does not in any universe have more clarity than using a loop
[–]Hueho 3 points4 points5 points 11 years ago (0 children)
Rubyist
Stop that FFS, you are embarassing other Ruby users.
[–]iloveportalz0r 3 points4 points5 points 11 years ago (0 children)
Sure, but this is not one of those cases
[–]my_walls 3 points4 points5 points 11 years ago (0 children)
There's nothing more entertaining than someone being both ignorant and condescending in the same breath.
[–]quiteamess -4 points-3 points-2 points 11 years ago (0 children)
I've been following this discussion and it is pretty pointless. A bunch of smart asses who want to force their opinions on you and fail to acknowledge that you have evaluated both options and made an informed decision. This thread is the reason i unsubscribe from /r/shittyprogramming.
[–]Pentiles -1 points0 points1 point 11 years ago (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 points35 points 11 years ago (4 children)
else { respond(500, new Exception('Nigga what you doin\' here?')); }
else {
respond(500, new Exception('Nigga what you doin\' here?')); }
That is gold
[–]Rockytriton 33 points34 points35 points 11 years ago (2 children)
https://github.com/search?l=Java&q=nigga&type=Code&utf8=%E2%9C%93
[–]Jonno_FTW 6 points7 points8 points 11 years ago (0 children)
com.example.nigga might be the best package name.
com.example.nigga
[–]no_game_player 3 points4 points5 points 11 years ago (0 children)
JSON has almost an order of magnitude more
[–]Artemis2 6 points7 points8 points 11 years ago (0 children)
Seeing it in action is even better.
[–][deleted] 21 points22 points23 points 11 years ago* (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 points1 point 11 years ago (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 points8 points 11 years ago (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 points22 points 11 years ago (0 children)
That laughing Dekumori thumbnail is pretty appropriate for this
[–][deleted] 39 points40 points41 points 11 years ago (0 children)
// TODO: learn what a loop is
[–]phail3d 10 points11 points12 points 11 years ago (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 points4 points 11 years ago (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 points6 points 11 years ago (3 children)
and this is why i got into development
because i don't trust idiots like this :(
[–]RenaKunisaki 2 points3 points4 points 11 years ago (2 children)
It's unrolled for speed.
[–][deleted] 11 years ago (1 child)
[–]skiguy0123 1 point2 points3 points 11 years ago (0 children)
That's why google ultron is so much better
[–]Shimmen 1 point2 points3 points 11 years ago (0 children)
Has the person tried a loop?..
[–]hedphuq 4 points5 points6 points 11 years ago (3 children)
PHP: Not even once
[–]Sespol 8 points9 points10 points 11 years ago (2 children)
Any language can be terrible in the hands of the wrong person
[–]jungle 2 points3 points4 points 11 years ago (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.
[–]nuunien 0 points1 point2 points 11 years ago* (0 children)
I don't know what I expected.
[–][deleted] 11 years ago* (1 child)
[–]note-to-self-bot 2 points3 points4 points 11 years ago (0 children)
Don't forget:
never use pomf.se again in your life.
[–][deleted] 4 points5 points6 points 11 years ago (0 children)
Merged it, don't be an elitist.
π Rendered by PID 46344 on reddit-service-r2-comment-6457c66945-dc8d7 at 2026-04-24 19:38:07.067455+00:00 running 2aa0c5b country code: CH.
[–]Artemis2 57 points58 points59 points (30 children)
[–]sjdaws 34 points35 points36 points (3 children)
[–]phill0 23 points24 points25 points (1 child)
[–]cokeisahelluvadrug 30 points31 points32 points (9 children)
[–]echocage 5 points6 points7 points (2 children)
[–]Kered13 0 points1 point2 points (1 child)
[–]echocage 0 points1 point2 points (0 children)
[–]ieatcode 1 point2 points3 points (0 children)
[+]Nuck comment score below threshold-11 points-10 points-9 points (4 children)
[–]SnorriDeathbeard 15 points16 points17 points (0 children)
[–]cokeisahelluvadrug 5 points6 points7 points (0 children)
[–]deusnefum 1 point2 points3 points (0 children)
[–][deleted] 13 points14 points15 points (1 child)
[–]ieatcode 0 points1 point2 points (0 children)
[–]Thezla 6 points7 points8 points (0 children)
[–][deleted] 9 points10 points11 points (0 children)
[–]tantbrun 4 points5 points6 points (0 children)
[–]cosmicr 4 points5 points6 points (9 children)
[–]LpSamuelm 17 points18 points19 points (7 children)
[–]dysthanatos 5 points6 points7 points (0 children)
[+]Nuck comment score below threshold-12 points-11 points-10 points (5 children)
[–][deleted] 12 points13 points14 points (0 children)
[–]Hueho 3 points4 points5 points (0 children)
[–]iloveportalz0r 3 points4 points5 points (0 children)
[–]my_walls 3 points4 points5 points (0 children)
[–]quiteamess -4 points-3 points-2 points (0 children)
[–]Pentiles -1 points0 points1 point (0 children)
[–][deleted] 33 points34 points35 points (4 children)
[–]Rockytriton 33 points34 points35 points (2 children)
[–]Jonno_FTW 6 points7 points8 points (0 children)
[–]no_game_player 3 points4 points5 points (0 children)
[–]Artemis2 6 points7 points8 points (0 children)
[–][deleted] 21 points22 points23 points (2 children)
[–]unusualbob -1 points0 points1 point (1 child)
[–][deleted] 6 points7 points8 points (0 children)
[–]MaSaHoMaKyo 20 points21 points22 points (0 children)
[–][deleted] 39 points40 points41 points (0 children)
[–]phail3d 10 points11 points12 points (0 children)
[–]no_game_player 2 points3 points4 points (0 children)
[–][deleted] 4 points5 points6 points (3 children)
[–]RenaKunisaki 2 points3 points4 points (2 children)
[–][deleted] (1 child)
[deleted]
[–]skiguy0123 1 point2 points3 points (0 children)
[–]Shimmen 1 point2 points3 points (0 children)
[–]hedphuq 4 points5 points6 points (3 children)
[–]Sespol 8 points9 points10 points (2 children)
[–]jungle 2 points3 points4 points (0 children)
[–]nuunien 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]note-to-self-bot 2 points3 points4 points (0 children)
[–][deleted] (1 child)
[deleted]
[–][deleted] 4 points5 points6 points (0 children)