News for hackers. Stuff that matters.
Re:C#: No, you don’t get to use the “as” operator any more by Groxx on Friday April 29, 2011 @04:49PM (#2498935)
That seems like it would be a trivial thing to do in an early compilation step... why is the workaround necessary?
Re:C#: No, you don’t get to use the “as” operator any more by ssp on Friday April 29, 2011 @05:11PM (#2499008)
The problem is that if the code looks like this:

        if (object.some_field != null)  {
               some_unrelated_call();
               object.some_field.foo();
        }
proving that some_unrelated_call() didn't set object.some_field to null is very difficult.
Re:C#: No, you don’t get to use the “as” operator any more by kenjackson on Friday April 29, 2011 @07:00PM (#2499321)
In general, it's also difficult to prove that 'object' doesn't get set to null too.
Re:C#: No, you don’t get to use the “as” operator any more by ssp on Saturday April 30, 2011 @03:04AM (#2500073)
Depends on what you mean by "general", I suppose, but if 'object' is a local variable in a Java-ish language, then there is a fairly straightforward data flow analysis that can do a good conservative estimate.
Re:C#: No, you don’t get to use the “as” operator any more by kenjackson on Saturday April 30, 2011 @11:57AM (#2500860)
but if 'object' is a local variable in a Java-ish language, then there is a fairly straightforward data flow analysis that can do a good

But if it's not, and/or if it can be adress taken...

Re:C#: No, you don’t get to use the “as” operator any more by masklinn on Friday April 29, 2011 @05:09PM (#2499003)
1. properties mean field invocations are not referentially transparent (you can only mitigate this by removing properties, or having referential transparency as part of the type)

2. multithreading means the value of the field can change from under you between the check and the access (you can solve this by eliminating threads or by transactioning your accesses)

Re:C#: No, you don’t get to use the “as” operator any more by sirclueless on Friday April 29, 2011 @06:10PM (#2499190)
I'm pretty sure point 2 is incorrect. The compiler doesn't worry about multithreaded access to properties/variables when optimizing.

You're right that such access can cause problems though. If you do want the compiler to worry about multithreaded access when it compiles, you can use the `volatile` keyword.

Re:C#: No, you don’t get to use the “as” operator any more by masklinn on Saturday April 30, 2011 @03:41AM (#2500116)
> I'm pretty sure point 2 is incorrect. The compiler doesn't worry about multithreaded access to properties/variables when optimizing.

This is not about optimizing, it's about static verifications. And that's very much the point: you can't statically verify this piece of knowledge if the code can be used in a multithreaded context.