Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

A A 2 3 5 8 K posted:

http://codytaylor.org/?p=14122

Urge to update Blogging Considered Harmful... rising...

Adbot
ADBOT LOVES YOU

Flamadiddle
May 9, 2004

tef posted:

sort {$a+=$b} @list;

Forgive my naivety, but what would this achieve?

McGlockenshire
Dec 16, 2005

GOLLOCKS!

quote:

Forgive my naivety, but what would this achieve?

Well, let's find out!

code:
#!perl
use strict;
use warnings;
use Data::Dumper;
my @list = qw! -1 0 1 2 3 4 5 !;
my @sorted_list = sort { my $x = $a += $b; print "$x\n"; $x; } @list;
print Dumper \@sorted_list;
results in...

code:
$VAR1 = [
          5,
          9,
          7,
          23,
          3,
          4,
          0
        ];
Oh yegods, it actually did what I was afraid that it was going to do. :psyduck:

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? :psypop:

For shits and giggles, I modified the sort line:
code:
my @sorted_list = sort { my $olda = $a; my $x = $a += $b; print "$olda + $b -> $x ($a)\n"; $x; } @list;
The resulting output?
code:
-1 + 0 -> -1 (-1)
1 + 2 -> 3 (3)
3 + 4 -> 7 (7)
-1 + 2 -> 1 (1)
1 + 3 -> 4 (4)
4 + 5 -> 9 (9)
2 + 5 -> 7 (7)
7 + 9 -> 16 (16)
16 + 7 -> 23 (23)
Yup, it's returning the added value. :psyboom:

I love Perl!

McGlockenshire fucked around with this message at 10:41 on Jun 16, 2009

tef
May 30, 2004

-> some l-system crap ->
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:
$ cat getupgetonup.pl 
#!perl
use Data::Dumper;
my @list = qw! -1 0 1 2 3 4 5 !;
sort { my $x = $a += $b; print "$x\n"; $x; } @list;
print Dumper \@list;


$ perl getupgetonup.pl 
$VAR1 = [
          '-1',
          '0',
          '1',
          '2',
          '3',
          '4',
          '5'
        ];

Zombywuf
Mar 29, 2008

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.

deedee megadoodoo
Sep 28, 2000
Two roads diverged in a wood, and I, I took the one to Flavortown, and that has made all the difference.


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.

wwb
Aug 17, 2004

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.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



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.

Why would anyone do this? :psypop:

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.

Zombywuf
Mar 29, 2008

code:
#!/usr/bin/perl                                                                                                                                                

use strict;
use warnings;

my @foo = (0, 1, 2, 3);
my @bar = grep {$_++} @foo;
print join ", ", @foo, @bar;

quote:

1, 2, 3, 4, 2, 3, 4
This is simply how Perl works. It's the same mechanism by which the following works.
code:
for my $i in (@list) {
  $i++;
}

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

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?

Honest question - I'm not a Perl expert, I just tinker with it occasionally.
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.


code:
$ cat foo.pl 
#!/bin/perl

my @array = ( [1, 32, 21], [4], [492, 39, 192, 10, 2], [2, 92], [0, 1, 32, 31] );

map { print "@$_\n"} sort { scalar(@$a) <=> scalar(@$b)} @array;


$ perl foo.pl 
4
2 92
1 32 21
0 1 32 31
492 39 192 10 2
Personally I think the better solution would just be to enforce some sort of const correctness on the sorted list, or at the very least issue a warning when it's being modified.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



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.

Personally I think the better solution would just be to enforce some sort of const correctness on the sorted list, or at the very least issue a warning when it's being modified.

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.

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:
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');
}
?>

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
two great tastes that taste great together :laugh:

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"
:cry:

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:
// Original: "don't use auto-ptr, they don't work well" ... :smith:
SomeObject *obj = new SomeObject(this);
try { SomeMethodThatCanThrow(); }
catch (...) {
    delete obj;
    throw;
}
delete obj;

// Changed to
catch (...) {
    assert(0);
    delete obj;
    ...
code:
uint32_t Frobnicate(uint32_t offset) {

// Original
if (some condition that is unusual but legal)
{
    return offset;
}
...

// Changed to
if (some condition that is unusual but legal)
{
    throw "Condition happened !!";
}
...

Ensign Expendable
Nov 11, 2008

Lager beer is proof that god loves us
Pillbug
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.

TOO SCSI FOR MY CAT
Oct 12, 2008

this is what happens when you take UI design away from engineers and give it to a bunch of hipster art student "designers"

Ensign Expendable posted:

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.

:iiam:

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.

Bhaal
Jul 13, 2001
I ain't going down alone
Dr. Infant, MD
That reminds me of coming across a DIE macro at a startup years ago:
code:
#define DIE Foo* __die = 0; __die->blarg();
The person who wrote this would insert it like so:
code:
if( curious condition that happens but shouldn't )
{
  DIE 
}
So he could view the core dumps that came out of the testers (and customers!) when that condition got hit.

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

TSDK
Nov 24, 2003

I got a wooden uploading this one
I came across a good one-liner today:
code:
sbp->p_buffer = p_destination ? p_destination : 0;

Seth Turtle
May 6, 2007

by Tiny Fistpump

TSDK posted:

I came across a good one-liner today:
code:
sbp->p_buffer = p_destination ? p_destination : 0;

"Man, that ternary operator looks so professional. I'd better use it in my code somewhere. Ah, here's a good place."

king_kilr
May 25, 2007

TSDK posted:

I came across a good one-liner today:
code:
sbp->p_buffer = p_destination ? p_destination : 0;

I guess technically in C++ with an overloaded bool operator it does something useful :/

Zakalwe
May 12, 2002

Wanted For:
  • Terrorism
  • Kidnapping
  • Poor Taste
  • Unlawful Carnal Gopher Knowledge
From the Bullet SDK User Manual


quote:

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.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Zakalwe posted:

From the Bullet SDK User Manual

[mp3-yakety_sax]

zombienietzsche
Dec 9, 2003


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:
public static Fund[] RetrieveAvailableFunds(DateTime Date, Guid ProductId,
string fundName, string ticker)  //dont use this query i dont know what its suppose to do
{

zombienietzsche fucked around with this message at 22:33 on Jun 26, 2009

Roseo
Jun 1, 2000
Forum Veteran
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!

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

meinstein posted:



What font are you using?

Runaway Five
Dec 31, 2007
I hate gays almost as much as I hate good posting. Also, God is good. Amen

TSDK posted:

I came across a good one-liner today:
code:
sbp->p_buffer = p_destination ? p_destination : 0;

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."

dancavallaro
Sep 10, 2006
My title sucks

Runaway Five posted:

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."

Good thing you explained it, I don't think everyone got it already.

Zombywuf
Mar 29, 2008

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.

fritz
Jul 26, 2003

Runaway Five posted:

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."

Whoa whoa whoa slow down there buddy!

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

That pleb coder, he neglects the case where p_destination is both not equal to zero and not not equal to zero :pseudo:

That Turkey Story
Mar 30, 2003

Dijkstracula posted:

That pleb coder, he neglects the case where p_destination is both not equal to zero and not not equal to zero :pseudo:

You joke but that's actually the common case on X/329-compliant systems.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

That Turkey Story posted:

You joke but that's actually the common case on X/329-compliant systems.

:ohdear: That's a real coding horror.

Vinterstum
Jul 30, 2003

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.

Zombywuf
Mar 29, 2008

Vinterstum posted:

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.

If you do not think of that as a coding horror, you do not belong here.

baquerd
Jul 2, 2007

by FactsAreUseless

Zombywuf posted:

If you do not think of that as a coding horror, you do not belong here.

Hey concurrency, how's it going?

TSDK
Nov 24, 2003

I got a wooden uploading this one

quadreb posted:

Hey concurrency, how's it going?
I'm doWhat'ing fine,s con thankcurreyou for asking.ncy?

Triple Tech
Jul 28, 2006

So what, are you quitting to join Homo Explosion?

TSDK posted:

I'm doWhat'ing fine,s con thankcurreyou for asking.ncy?

Oh hilarity. :neckbeard:

Zombywuf
Mar 29, 2008

quadreb posted:

Hey concurrency, how's it going?

quote:

...for portability and compatibility reasons...

Vinterstum
Jul 30, 2003

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.

Adbot
ADBOT LOVES YOU

TheSleeper
Feb 20, 2003

Vinterstum posted:

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.

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).

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply