Daniel Keep wrote:

Steven Schveighoffer wrote:
On Tue, 22 Sep 2009 21:24:10 -0400, Daniel Keep
<daniel.keep.li...@gmail.com> wrote:
Well, if you're not looking at memoization, why is this discussion even
happening?
There are other pure optimizations that can occur without memoization. In fact I don't even know why memoization is brought up so much with
pure functions, it is an impossible-to-prove optimization.  How do you
know memoization helps when you don't know how often the same arguments
will be used?

What other optimisations?  The only other one I can think of off the top
of my head is common subexpression elimination.  Except that's
effectively caller-side memoisation.

The ONLY way I can see object casting being treated as a pure function
is if all references passed in are immutable and even then only if the
compiler can prove the reference cannot be changed (i.e. the reference
is always kept on the stack AND you assume you never manually delete it).
How is a thread going to come along and change a local variable in
another thread?

I don't know if you've noticed, but objects tend to be allocated on the
heap, not the stack. :P

There's nothing to stop another thread from killing the object you're
pointing to and then substituting in a new one.  It's pathological, yes,
but this is the sort of thing that, if it happens, you don't have a hope
of debugging.  This is why threads completely and utterly suck and I
frequently wish they'd never been invented.

It's also incidentally why I've personally come to regard reference
semantics, in general, as a really, REALLY stupid idea.

I myself couldn't live without threads or references, but I agree that mixing the two can lead to interesting scenarios to debug. Just try and code a responsive GUI without using threads, the application will "hang" everytime you're not going back to the main loop every few milliseconds. Or doing network I/O without bringing your program to a crawl, of course you could use async I/O but where is that I/O gonna run without a background thread to support it :)

Besides, the upcoming shared qualifier is there to address those issues.

You might want to look at this article, I came across it a few months ago and found it rather insightful, it just could change your view on references:
http://blogs.msdn.com/ericlippert/archive/2009/02/17/references-are-not-addresses.aspx

Reply via email to