You can kill the background for speed, if you wish.[x]

Friday, January 23, 2009

Oh, IRC...

So today I was working on QuoteBook, and needed to create an array for the page navigator - something like Perl's (5..10) syntax, cause I didn't want to make my code more ugly and complicated than necessary by using a loop. As I didn't know where to begin looking for such a function (Google doesn't index strings like '..'), I just hopped on IRC, where there is usually someone that is both bored enough and knowledgeable enough to help me out. Which there was. And as it turns out, there was also a troll. I've block out the names not to protect the innocent, but because I don't want to give the troll any more ego boost from whatever strange motivation he has than necessary, so here goes (I'm fiveofoh):
(06:10:46 PM) fiveofoh: Hey all, is there a way to do something like $array = (5..10)
(06:10:59 PM) fiveofoh: To get (5, 6, 7, 8, 9, 10), of course
(06:11:17 PM) fiveofoh: (other than a for loop)
(06:11:17 PM) [troll]: $x= array( 0=>1, 1=>2 ... );
(06:11:34 PM) DryGravyTrain: a while loop
(06:11:44 PM) fiveofoh: lol
(06:11:47 PM) DryGravyTrain: :D
(06:11:51 PM) fiveofoh: :P
(06:11:55 PM) fiveofoh: Not exactly what I was going for
(06:12:08 PM) DryGravyTrain: whats wrong with a loop
(06:12:17 PM) fiveofoh: So there's not a DynamicallyCreateAnArrayGoingFrom(start, end) function :P
(06:12:24 PM) fiveofoh: It's not as pretty :P
(06:12:25 PM) [troll]: what
(06:12:28 PM) [troll]: its always dynamic
(06:12:33 PM) fiveofoh: Okay, fine
(06:12:36 PM) [troll]: $x[0]=5;
(06:12:39 PM) fiveofoh: CreateAnArrayGoingFrom(start, end)
(06:12:40 PM) fiveofoh: ;
(06:12:42 PM) [troll]: $x[1]=6;
(06:12:48 PM) [troll]: use a fucking for loop
(06:12:50 PM) [troll]: or a while loop
(06:12:52 PM) fiveofoh: Haha oh fine
(06:13:01 PM) [troll]: or foreach
(06:13:01 PM) fiveofoh: Well if there was a way to do it, I didn't want to use a for loop
(06:13:19 PM) fiveofoh: But if there's not, I can use a for loop
(06:13:24 PM) [troll]: while ( $i<5 ) $x[$i++] = $i;
(06:13:33 PM) DryGravyTrain: you can do range()
(06:13:43 PM) fiveofoh: Ahhha
(06:13:48 PM) fiveofoh: See that's what I was looking for
(06:13:59 PM) [troll]: B=>
(06:14:03 PM) fiveofoh: It's a CreateAnArrayGoingFrom($start, $end) function :p
(06:14:14 PM) [troll]: for integers
(06:14:17 PM) [troll]: only
(06:14:23 PM) fiveofoh: Well that's all I need
(06:14:24 PM) [troll]: perhaps characters
(06:14:27 PM) [troll]: no float
(06:14:32 PM) [troll]: no complex objects
(06:14:35 PM) fiveofoh: So?
(06:14:43 PM) fiveofoh: I need to create an array of integers from $x to $y
(06:14:49 PM) fiveofoh: Range() will do the job
(06:14:52 PM) [troll]: why not use a for loop
(06:14:58 PM) [troll]: or a while loop
(06:15:00 PM) [troll]: or a foreach
(06:15:04 PM) fiveofoh: Cause range() is easier, and prettier, and more concise
(06:15:12 PM) [troll]: f***ing prettier
(06:15:20 PM) fiveofoh: $array = range($start, $end);
(06:15:39 PM) [troll]: the web is a gross mess of broken tools, and you are worried about the prettiness of range() versus for() or while()
(06:16:02 PM) fiveofoh: vs for($curval = $start; $curval <= $end; $curval++) { $array[] = $curval; }
(06:16:14 PM) [troll]: while ( $i<5 ) $x[$i++] = $i;
(06:16:16 PM) fiveofoh: or while($curval < $end) { $array[] = $curval++; }
(06:16:32 PM) [troll]: while ( $i<3 ) $x[$i++] = $i;
(06:16:47 PM) fiveofoh: Except I need to start from non-zero
(06:16:49 PM) fiveofoh: So it'd be
(06:17:03 PM) DryGravyTrain: you can also specify step fiveofoh
(06:17:06 PM) fiveofoh: I know
(06:17:12 PM) fiveofoh: I don't need to, but it's nice to have
(06:17:13 PM) DryGravyTrain: k
(06:17:17 PM) [troll]: $i=5; while( $i<10 ) $x[$i]=$i++;
(06:17:18 PM) fiveofoh: Thanks much
(06:17:47 PM) fiveofoh: DryGravyTrain: mostly I just needed the function name, I didn't know what to search for
(06:17:58 PM) fiveofoh: [troll]: But *why* would you do a for or while loop?
(06:18:07 PM) [troll]: function r($a,$b) { $i=$a; while($i<$b)$x[$i++]=$i; return $x; }
(06:18:12 PM) fiveofoh: holy frick
(06:18:20 PM) [troll]: there, now its just 'r'
(06:18:25 PM) [troll]: r(1,6);
(06:18:27 PM) fiveofoh: Why don't you just make your own functions for opening files
(06:18:35 PM) fiveofoh: Or min
(06:18:36 PM) fiveofoh: Or max
(06:18:45 PM) fiveofoh: Or array_sort
(06:18:48 PM) fiveofoh: I mean come on
(06:18:56 PM) [troll]: sure you might want to write your own sort
(06:19:07 PM) hrehf left the room (quit: "fdag").
(06:19:07 PM) [troll]: for instance, you could probably write a faster one
(06:19:36 PM) fiveofoh: I just don't understand your point
(06:19:46 PM) [troll]: the world of sorting always needs new ideas
(06:19:59 PM) fiveofoh: Is there any reason that I would *want* to use a while loop instead of range()
(06:20:00 PM) fiveofoh: ?
(06:20:11 PM) DryGravyTrain: simply for flexibility
(06:20:17 PM) DryGravyTrain: for what your using it for...nothing
(06:20:33 PM) [troll]: so you don't waste 5 minutes looking for range()?
(06:20:54 PM) fiveofoh: That's the only reason I could think of
(06:21:24 PM) [troll]: plus the time of other people
(06:21:30 PM) [troll]: 20 man-minutes
(06:21:33 PM) fiveofoh: And when I just played a game for 30 minutes to kill time, I'm not too worried
(06:21:47 PM) [troll]: great
(06:21:53 PM) [troll]: someone in africa starved to death
(06:21:54 PM) fiveofoh: It's your choice to argue with me, wasting your time...
(06:21:56 PM) [troll]: you played a game
(06:21:57 PM) fiveofoh: wtf
(06:22:23 PM) fiveofoh: All right, I'm going to go back to doing something useful, and leave you to your trolling
(06:22:32 PM) fiveofoh: Thanks for being helpful, DryGravyTrain :)
(06:22:34 PM) [troll]: your mother
(06:23:03 PM) ***[troll] burns the courthouse and pitches BRICKS, ppl.  That's right, FLAMING BRICKS.
...and that was the end of that. I love IRC.

No comments: