|
A A 2 3 5 8 K posted:http://codytaylor.org/?p=14122 Urge to update Blogging Considered Harmful... rising...
|
# ? Jun 16, 2009 04:10 |
|
|
# ? May 28, 2024 16:10 |
|
tef posted:sort {$a+=$b} @list; Forgive my naivety, but what would this achieve?
|
# ? Jun 16, 2009 09:40 |
|
quote:Forgive my naivety, but what would this achieve? Well, let's find out! code:
code:
Okay, quick Perl tutorial. $a and $b in the sort routine are the "left" and "right" values to compare. The routine returns -1, 0, or 1 to indicate the sorting order of the values. Now, assuming that the assign returns some value (either the previous or new value of $a), given the list I provided, we'd get one negative, one zero, and lots of positives. Let's also assume that values greater than 1 are considered a 1. Much to our collective horror, the values are modifiable within the sort. I have no idea who thought this was a good idea, but I'm going to give him or her a piece of my mind should we ever meet. So, during the sort, the left value is always being modified. I'm not sure what method Perl uses internally to perform the sort, the results are the same every time on Perl 5.10.0. Why would anyone do this? For shits and giggles, I modified the sort line: code:
code:
I love Perl! McGlockenshire fucked around with this message at 10:41 on Jun 16, 2009 |
# ? Jun 16, 2009 10:38 |
|
That is wrong. I did sort {$a+=$b} @list;, you did my @sorted_list = sort { my $x = $a += $b; print "$x\n"; $x; } @list;. Let's try this again. code:
|
# ? Jun 16, 2009 10:49 |
|
Basically, Perl optimises away the crazy when it can (detects void context, does nothing). However if you are going to mutate the variables in your sort function you deserve everything you get.
|
# ? Jun 16, 2009 12:32 |
|
A A 2 3 5 8 K posted:http://codytaylor.org/?p=14122 quote:PHP makes life a lot easier for quick or dirty maintenance scripts, cron jobs or web applications If anyone I work with ever wrote a cron job or maintenance script in php I would brain them.
|
# ? Jun 16, 2009 13:57 |
|
HatfulOfHollow posted:If anyone I work with ever wrote a cron job or maintenance script in php I would brain them. Not before I chopped their thumbs off.
|
# ? Jun 16, 2009 14:53 |
|
McGlockenshire posted:Much to our collective horror, the values are modifiable within the sort. I have no idea who thought this was a good idea, but I'm going to give him or her a piece of my mind should we ever meet. So, during the sort, the left value is always being modified. I'm not sure what method Perl uses internally to perform the sort, the results are the same every time on Perl 5.10.0. Wouldn't a pass-by-reference system be the best generic way to do it in Perl if you want people to be able to, say, sort an array of arrays by the lengths of the constituent arrays? Honest question - I'm not a Perl expert, I just tinker with it occasionally.
|
# ? Jun 16, 2009 15:03 |
|
code:
quote:1, 2, 3, 4, 2, 3, 4 code:
|
# ? Jun 16, 2009 16:25 |
|
Munkeymon posted:Wouldn't a pass-by-reference system be the best generic way to do it in Perl if you want people to be able to, say, sort an array of arrays by the lengths of the constituent arrays? code:
|
# ? Jun 16, 2009 16:48 |
|
Dijkstracula posted:Indeed, you need to pass by reference, but in your example (unless I'm misunderstanding your question) there's no need to allow the dereferenced array to be modifiable. Wouldn't that basically be creating a seperate and logically inconsistent state for the interpreter to be in while sorting? I'd say it's better to just let a few profoundly stupid/crazy people to shoot themselves in the foot than to create new potential interpreter bugs and certian work for some maintainer.
|
# ? Jun 16, 2009 17:44 |
|
php:<? /** * Emulate a Java-style import statement. * Simply includes the associated PHP file (using require_once so multiple calls to include the same file have no effect). * @param $class string the complete name of the class to be imported (e.g. "core.Core") */ function import($class) { require_once(str_replace('.', '/', $class) . '.inc.php'); } ?>
|
# ? Jun 16, 2009 21:38 |
|
two great tastes that taste great together
|
# ? Jun 16, 2009 21:40 |
|
My supervisor loves subtly changing code in really dumb ways, and then I get to experience the joy of debugging a lovely c++ app riddled with "throw()" declarations, manual memory management, and templates: code:
code:
|
# ? Jun 16, 2009 21:51 |
|
Wait, what? Why? Even my minimal experience with C++ makes that seem like an awful, awful idea. Edit: I meant the first one. The second one makes no sense in any language.
|
# ? Jun 16, 2009 23:22 |
|
Ensign Expendable posted:Wait, what? Why? Even my minimal experience with C++ makes that seem like an awful, awful idea. He said he was "debugging" it, but the only lines changed in that checkin were adding assert(0) in a half-dozen places. He let me remove the ones that I was actually hitting while using the system, but the others are still there. Luckily, it crashes enough anyway that a few more probably won't be noticed.
|
# ? Jun 16, 2009 23:52 |
|
That reminds me of coming across a DIE macro at a startup years ago:code:
code:
He also bound F12 or one of those keys to trigger this, so if he or others had something weird you could "Just hit F12 and email me the dump file". Bhaal fucked around with this message at 06:41 on Jun 17, 2009 |
# ? Jun 17, 2009 06:37 |
|
I came across a good one-liner today:code:
|
# ? Jun 26, 2009 16:47 |
|
TSDK posted:I came across a good one-liner today: "Man, that ternary operator looks so professional. I'd better use it in my code somewhere. Ah, here's a good place."
|
# ? Jun 26, 2009 18:00 |
|
TSDK posted:I came across a good one-liner today: I guess technically in C++ with an overloaded bool operator it does something useful :/
|
# ? Jun 26, 2009 18:47 |
|
From the Bullet SDK User Manualquote:Often it is necessary to maintain an array of objects. Originally the Bullet library used a STL std::vector data structure for arrays, but for portability and compatibility reasons we switched to our own array class.
|
# ? Jun 26, 2009 18:49 |
|
Zakalwe posted:From the Bullet SDK User Manual [mp3-yakety_sax]
|
# ? Jun 26, 2009 18:52 |
|
Note: each of the retrieve funds methods are 150-250 lines long. They do completely different things. What each one does is kind of documented. Oh, and this is from the 14,000+ line DatabaseCommunicator class, that handles all communication with the database. Don't even get me started on the GetFunds(...) methods. EDIT: code:
zombienietzsche fucked around with this message at 22:33 on Jun 26, 2009 |
# ? Jun 26, 2009 22:24 |
|
print "The value of the variable is $variable\n" if $othervariable eq "1"; print "The value of the variable is $variable\n" if $othervariable ne "1"; gently caress yeah!
|
# ? Jun 27, 2009 05:58 |
|
meinstein posted:What font are you using?
|
# ? Jun 27, 2009 21:13 |
|
TSDK posted:I came across a good one-liner today: That can be completely reduced to: sbp->p_buffer = p_destination; No matter the logic, you get a copy of p_destination, how funny. "If p_destination is not equal to zero, set p_buffer to p_destination. If p_destination is equal to zero, set p_buffer to zero."
|
# ? Jun 27, 2009 21:48 |
|
Runaway Five posted:That can be completely reduced to: Good thing you explained it, I don't think everyone got it already.
|
# ? Jun 27, 2009 22:18 |
|
dancavallaro posted:Good thing you explained it, I don't think everyone got it already. You see, the ternary operator's kinda like a shamrock.
|
# ? Jun 27, 2009 22:34 |
|
Runaway Five posted:That can be completely reduced to: Whoa whoa whoa slow down there buddy!
|
# ? Jun 27, 2009 22:47 |
|
That pleb coder, he neglects the case where p_destination is both not equal to zero and not not equal to zero
|
# ? Jun 27, 2009 23:49 |
|
Dijkstracula posted:That pleb coder, he neglects the case where p_destination is both not equal to zero and not not equal to zero You joke but that's actually the common case on X/329-compliant systems.
|
# ? Jun 28, 2009 00:26 |
|
That Turkey Story posted:You joke but that's actually the common case on X/329-compliant systems. That's a real coding horror.
|
# ? Jun 28, 2009 01:43 |
|
Zakalwe posted:From the Bullet SDK User Manual So why is this a coding horror, exactly? There's been plenty of console SDKs with very dodgy STL implementations which could've prompted that, and not necessarily the good ol' "not invented here" syndrome.
|
# ? Jun 30, 2009 13:55 |
|
Vinterstum posted:So why is this a coding horror, exactly? If you do not think of that as a coding horror, you do not belong here.
|
# ? Jun 30, 2009 14:16 |
|
Zombywuf posted:If you do not think of that as a coding horror, you do not belong here. Hey concurrency, how's it going?
|
# ? Jun 30, 2009 18:00 |
|
quadreb posted:Hey concurrency, how's it going?
|
# ? Jun 30, 2009 18:16 |
|
TSDK posted:I'm doWhat'ing fine,s con thankcurreyou for asking.ncy? Oh hilarity.
|
# ? Jun 30, 2009 18:22 |
|
quadreb posted:Hey concurrency, how's it going? quote:...for portability and compatibility reasons...
|
# ? Jun 30, 2009 18:24 |
|
Zombywuf posted:If you do not think of that as a coding horror, you do not belong here. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html And if you do, you most definitely don't belong in the gaming industry.
|
# ? Jun 30, 2009 20:10 |
|
|
# ? May 28, 2024 16:10 |
|
Vinterstum posted:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html How many items in that "Motivation for EASTL" have to do with portability/compatibility? One. How many have to do with performance and/or common issues that come up in game programming but not elsewhere? (hint: it's all but the one).
|
# ? Jun 30, 2009 20:18 |