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
NotShadowStar
Sep 20, 2000

Xenogenesis posted:

Behold Haml, Rails' elegant, beautiful templating solution:

Fire him.

Adbot
ADBOT LOVES YOU

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

yaoi prophet posted:

NSAttributedString is not a subclass of NSString, and RegexKit doesn't implement anything for NSAttributedString. So if you have one, and you want to do regex operations while preserving formatting, you have to convert it to a NSString, do your regex operations, then figure out the indices your regex matched on and then manually extract them from the original attributed string. Ugh.

I mean, I guess this sucks, but you just write a wrapper for the method that takes an NSAttributedString once and never have to deal with it again.

HIERARCHY OF WEEDZ
Aug 1, 2005

Xenogenesis posted:

Behold Haml, Rails' elegant, beautiful templating solution:

Don't blame Haml for that abomination. Did the guy work as a VBScript programmer before this?

Opinion Haver
Apr 9, 2007

Ryouga Inverse posted:

I mean, I guess this sucks, but you just write a wrapper for the method that takes an NSAttributedString once and never have to deal with it again.

I just felt like bitching about it.

Smugdog Millionaire
Sep 14, 2002

8) Blame Icefrog
My employer is a web development agency and we frequently fix projects that other agencies failed to deliver on. This means I often get to work with the dregs of the ASP.NET world.

The site I'm working on now has basically one function: to let users find 'locations' and 'request' information on a convenient location. I'm trying to introduce the notion of data integrity to the database and I find that most of the requests originating in our dev environment have a location ID like "309998.asp" instead of the expected "309998". Let's ignore, for the moment, that nvarchar(6) IDs are annoying, and there's no FK constraint on that column (and I can't easily add one because there's loads of garbage in the table that won't sync up).

I start to puzzle over the incorrect IDs in our dev environment. What could be different in on our development server that causes incorrect data to be inserted into the database? By chance, I notice that the URL for the request form for the page I'm on is /location-details/309998/?locationId=309998.aspx. What the hell is with the trailing .aspx? We don't have URL rewriting set up on development exactly as it's set up on production so we get some weird URLs sometimes. Apparently instead of keeping track of what location ID the user is currently viewing, the code just grabs the location ID from the query string which in this case has an extraneous .aspx in it.

Imperfect URL rewriting caused our dev site to insert bad data into the database.

Kamikaze!
Jul 10, 2001
On probation for postcount++
I like this one in Python:
code:
>>> def a(b,c={}):
...     c[b]=True
...     print c
...
>>> a(1)
{1: True}
>>> a(2)
{1: True, 2: True}
>>>

POKEMAN SAM
Jul 8, 2004

Kamikaze! posted:

I like this one in Python:
code:
>>> def a(b,c={}):
...     c[b]=True
...     print c
...
>>> a(1)
{1: True}
>>> a(2)
{1: True, 2: True}
>>>

I don't really have a problem with that because I understand it and it isn't something you're likely to do accidentally all the time. It's just a parameter with a default value that happens to be something that you'd store a reference to, so the next time you execute a(something) c is going to be pointing to the same object because it's only instantiated once.

Penrose Stares
Jan 3, 2011

by Ozma

A OBLIVION MOD... posted:

Don't blame Haml for that abomination. Did the guy work as a VBScript programmer before this?

Seconding this. Good Haml code is pretty much as simple as it gets.

evensevenone
May 12, 2001
Glass is a solid.

Ugg boots posted:

I don't really have a problem with that because I understand it and it isn't something you're likely to do accidentally all the time. It's just a parameter with a default value that happens to be something that you'd store a reference to, so the next time you execute a(something) c is going to be pointing to the same object because it's only instantiated once.

Why doesn't c go out of scope at the end of the function?

BigRedDot
Mar 6, 2008

evensevenone posted:

Why doesn't c go out of scope at the end of the function?
Because function argument defaults are created once, when the function is defined, not anew every time the function is invoked.

Munkeymon
Aug 14, 2003

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



evensevenone posted:

Why doesn't c go out of scope at the end of the function?

Python defaults are only evaluated once:

http://docs.python.org/tutorial/controlflow.html#id1

edit:

Big Red Dot posted:

Because function argument defaults are created once, when the function is defined, not anew every time the function is invoked.

Is the specifics of when they are evaluated an implementation detail or guaranteed to be at first evaluation time? I see the CPython interpreter does it at evaluation time but could it also be done lazily by a different implementation?

edit 2:
code:
>>> def immediate():
...    print 'done already!'
...    return 'what more do you want?'
...
>>> def gogogo(go = immediate()):
...    return go
...
done already!
>>> gogogo()
'what more do you want?'

Munkeymon fucked around with this message at 22:40 on Jan 3, 2011

Haystack
Jan 23, 2005





Munkeymon posted:

Is the specifics of when they are evaluated an implementation detail or guaranteed to be at first evaluation time? I see the CPython interpreter does it at evaluation time but could it also be done lazily by a different implementation?

Well, the default argument is actually a property on the function object, so I imagine that it must be created when the function object is made, ie at evaluation time.

Scaevolus
Apr 16, 2007

code:
class RenderGlobal {
    ArrayList<Chunk> pendingChunks;
    ...
    public boolean renderNewChunks(Coord camera, boolean firstRun)
    {
        Collections.sort(this.pendingChunks, new DistanceComparator(camera));

        int lastChunkIndex = this.pendingChunks.size() - 1;
        int nChunks = this.pendingChunks.size();
        for (int i = 0; i < nChunks; i++) {
            Chunk chunk = this.pendingChunks.get(lastChunkIndex - i);
            if (!firstRun) {
                if (chunk.distance(camera) > 1024.0F) {
                    if (chunk.ready) {
                        if (i >= 3) 
                            return false; // termination point 1
                    }
                    else if (i >= 1) 
                        return false; // termination point 2
                }
            }
            else if (!chunk.ready)
                continue;
            
            chunk.render();
            this.pendingChunks.remove(chunk);
            chunk.notRendered = false;
        }

        return this.pendingChunks.size() == 0; // termination point 3
    }
    ...
}
Context:

1) this.pendingChunks averages 3000-5000 objects.
2) Collections.sort allocates a new array of the same size, copies all the elements out of the ArrayList, sorts them, then copies all the elements back.
3) The code always terminates at point 1 or 2, unless firstRun is true (i.e., it only processes the last ~3 objects in the list)

This method is called every frame, and accounts for 30% of CPU time on slower systems.

Xenogenesis
Nov 8, 2005
http://www.exploringbinary.com/php-hangs-on-numeric-value-2-2250738585072011e-308/

quote:

I stumbled upon a very strange bug in PHP; this statement sends it into an infinite loop:

code:
<?php $d = 2.2250738585072011e-308; ?>
:kiddo:

gastownlabs
Oct 14, 2010

The real horror

@rasmus posted:

@Bjorn_W It's a gcc optimizer issue. Works fine with -O0 but not -O2

tef
May 30, 2004

-> some l-system crap ->
-funroll-loops :v:

Zombywuf
Mar 29, 2008

gastownlabs posted:

The real horror

Even worse:

Rasmus posted:

@AnthonySterling We still need to fix the code to make it immune to compiler switches.

The bug is in the double parser that iteratively approximates the correct value which doesn't work at MAX_DOUBLE. Rasmus decides that the problem is "compiler switches".

tef
May 30, 2004

-> some l-system crap ->
INT_MAX, MAX_DOUBLE php rocks at boundary cases

The Reaganomicon
Oct 14, 2010

by Lowtax

Zombywuf posted:

Even worse:


The bug is in the double parser that iteratively approximates the correct value which doesn't work at MAX_DOUBLE. Rasmus decides that the problem is "compiler switches".

Tiny Bug Childe... why... :negative:

Space Kablooey
May 6, 2009


Scaevolus posted:


Context:

1) this.pendingChunks averages 3000-5000 objects.
2) Collections.sort allocates a new array of the same size, copies all the elements out of the ArrayList, sorts them, then copies all the elements back.
3) The code always terminates at point 1 or 2, unless firstRun is true (i.e., it only processes the last ~3 objects in the list)

This method is called every frame, and accounts for 30% of CPU time on slower systems.

This came from Minecraft's source code, by any chance? :v:

mr_jim
Oct 30, 2006

OUT OF THE DARK

HardDisk posted:

This came from Minecraft's source code, by any chance? :v:

That was my first thought.

Zombywuf
Mar 29, 2008

It would explain why it's unplayable on my netbook.

SavageMessiah
Jan 28, 2009

Emotionally drained and spookified

Toilet Rascal

HardDisk posted:

This came from Minecraft's source code, by any chance? :v:

Haha I was going to ask the same thing. Great minds think alike I guess.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Zombywuf posted:

The bug is in the double parser that iteratively approximates the correct value which doesn't work at MAX_DOUBLE. Rasmus decides that the problem is "compiler switches".
the issue is only on 32-bit, because PHP uses 80-bit floats on 32-bit systems, but 64-bit floats on 64-bit systems. It can be fixed with compiler switches, but they aren't exactly the problem.

And apparently they didn't think to check "can we improve this number's error any further?" instead of just while(error > 0.05)

It's fixed in SVN so I'm wondering what horrifying method they used to "fix" it.

tef
May 30, 2004

-> some l-system crap ->
http://svn.php.net/viewvc/php/php-src/trunk/Zend/zend_strtod.c?r1=304407&r2=307095

code:
--- php/php-src/trunk/Zend/zend_strtod.c	2010/10/14 21:33:10	304407
+++ php/php-src/trunk/Zend/zend_strtod.c	2011/01/04 22:36:23	307095
@@ -2035,7 +2035,7 @@
 	int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign,
 		e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
 	CONST char *s, *s0, *s1;
-	double aadj, aadj1, adj;
+	volatile double aadj, aadj1, adj;
 	volatile _double rv, rv0;
 	Long L;
 	ULong y, z;
fwiw it looks like this bug isn't in the original http://www.netlib.org/fp/dtoa.c

edit: goes back as far as 4.3

tef fucked around with this message at 03:36 on Jan 5, 2011

MrMoo
Sep 14, 2000

Randomly sticking in volatile modifiers for a single threaded piece of code with no external IO, nice. I think Drepper would have a nice chuckle.

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
So is volatile in php magical? I am confused as to how this "fixes" the hang-on-certain-float bug.

Edit: Instead of blaming PHP programmers, they are blaming a design flaw in the x87 FPU.

Malloc Voidstar fucked around with this message at 04:21 on Jan 5, 2011

pseudorandom name
May 6, 2007

Slapping a volatile on those variables forces them to be stored to memory, which truncates the 80 bit x87 FPU representation down to 64-bits, nicely working around the fact their strtod is retarded, at the expense of performance and relying on the compiler's whims to get it right.

Never use volatile, folks. You aren't smart enough, and neither is the compiler.

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"

pseudorandom name posted:

Slapping a volatile on those variables forces them to be stored to memory, which truncates the 80 bit x87 FPU representation down to 64-bits, nicely working around the fact their strtod is retarded, at the expense of performance and relying on the compiler's whims to get it right.

Never use volatile, folks. You aren't smart enough, and neither is the compiler.
volatile isn't magic; I use it all the time. This is only a horror because PHP developers are incompetent.

MrMoo
Sep 14, 2000

pseudorandom name posted:

Slapping a volatile on those variables forces them to be stored to memory, which truncates the 80 bit x87 FPU representation down to 64-bits,

Or rather any operation on the volatile double causes the x87 register to be copied to a x86 register causing the down conversion, without the volatile the intermediate values can be kept in the x87?

tef
May 30, 2004

-> some l-system crap ->
x87 isn't IEEE floats. if you want ieee floats you have to ask for them.

it has higher precision internally, so if you do float operations on the registers
you'll get different results.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323#c109

volatile fixes this instance by preventing the optimizer from moving the floats out of memory,
so they won't get extra precision.


correct flag should be -fexcess-precision=standard i think

quote:

-fexcess-precision=style
This option allows further control over excess precision on machines where floating-point registers have more precision than the IEEE float and double types and the processor does not support operations rounding to those types. By default, -fexcess-precision=fast is in effect; this means that operations are carried out in the precision of the registers and that it is unpredictable when rounding to the types specified in the source code takes place. When compiling C, if -fexcess-precision=standard is specified then excess precision will follow the rules specified in ISO C99; in particular, both casts and assignments cause values to be rounded to their semantic types (whereas -ffloat-store only affects assignments). This option is enabled by default for C if a strict conformance option such as -std=c99 is used.

-fexcess-precision=standard is not implemented for languages other than C, and has no effect if -funsafe-math-optimizations or -ffast-math is specified. On the x86, it also has no effect if -mfpmath=sse or -mfpmath=sse+387 is specified; in the former case, IEEE semantics apply without excess precision, and in the latter, rounding is unpredictable.

tef fucked around with this message at 05:12 on Jan 5, 2011

tef
May 30, 2004

-> some l-system crap ->
to be fair to php floating point is pain and suffering

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
I like solution 5 in that link. I wish more PHP programmers took that advice.

pseudorandom name
May 6, 2007

MrMoo posted:

Or rather any operation on the volatile double causes the x87 register to be copied to a x86 register causing the down conversion, without the volatile the intermediate values can be kept in the x87?

Nope, volatile requires memory, not integer registers.

tef posted:

x87 isn't IEEE floats. if you want ieee floats you have to ask for them.

The x87 is a fully conformant IEEE 754 FPU. It doesn't operate internally using IEEE 754 single or double precision floating point values, but that's allowed by the standard.

MrMoo
Sep 14, 2000

pseudorandom name posted:

Nope, volatile requires memory, not integer registers.

But it isn't forcing software x87 emulation, so its copy from x87 registers to main memory and back to x87 registers for each op?

Scaevolus
Apr 16, 2007

HardDisk posted:

This came from Minecraft's source code, by any chance? :v:
Yes.

pseudorandom name
May 6, 2007

MrMoo posted:

But it isn't forcing software x87 emulation, so its copy from x87 registers to main memory and back to x87 registers for each op?

No software emulation involved, but, yes, it has to load the variable for every operation and then store it back to memory.

Zombywuf
Mar 29, 2008

pseudorandom name posted:

No software emulation involved, but, yes, it has to load the variable for every operation and then store it back to memory.

Not in the case of a local variable with no external visibility. The semantics of this are a bit weird, but it would be perfectly ok for the variable to never leave a register. Volatile is an ordering requirement. If the variable was ever referenced it would need an address and thus need to be stored in memory, then what you say would be true.

pseudorandom name
May 6, 2007

Zombywuf posted:

Not in the case of a local variable with no external visibility. The semantics of this are a bit weird, but it would be perfectly ok for the variable to never leave a register. Volatile is an ordering requirement. If the variable was ever referenced it would need an address and thus need to be stored in memory, then what you say would be true.

I don't think that's true, but if it is, than the compiler could just keep the variables in the x87 FPU register stack for the duration.

Which would also be amusing.

Adbot
ADBOT LOVES YOU

Zombywuf
Mar 29, 2008

pseudorandom name posted:

I don't think that's true, but if it is, than the compiler could just keep the variables in the x87 FPU register stack for the duration.

Which would also be amusing.

It would almost result in a swath of complaints about compiler optimisations breaking backwards compatibility.

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