"using static" - why not "with"?

Topics: C# Language Design
Feb 3, 2015 at 9:16 PM
Edited Feb 3, 2015 at 9:16 PM
Hi, guys!
I'm interesting, who and why offered idea for static import? Don't you know about Pascal's "with" operator? I think it could be way more useful than converting your code into a mess of imported methods. What a difference? THE SCOPE: "with" can be very local, while "using static" makes a whole file as a giant "with"!
with(obj1, obj2) {
    .Prop1 = .Meth2();
It's short and safe. Did this "with" ever considered???
Feb 3, 2015 at 10:28 PM
It's way too late to question this feature. It has already been discussed, accepted by the community and put into C# 6.0.

But, nevertheless, how does static imports and what you are mentioning relate to each other?

Static imports already existed in Visual Basic. How is what you mention closer to what Visual Basic already had that the C" implementation?
Feb 4, 2015 at 8:25 AM
@PauloMorgado It's not late, because any feature (like moronic "primary constructors") can be frozen. To avoid wasting time read what "with" operator does in Pascal - then we will talk on the same level.
Feb 4, 2015 at 10:07 PM
I think we're both talking about the same thing here. VB has a with operator that acts very similarly to Pascal's. It's too late for us to implement this feature for C#6, but I encourage you to file this as an issue on github for C#7.
Feb 14, 2015 at 6:59 PM
using static and with are not related to one another. using static only flattens the requirement to specify full class names when accessing static members. with deals with specific instances of variables.

Also, there have been arguments over whether to include with since before C# went 1.0. Of course the team is aware of it. They considered it and rejected it as unnecessary, which was a decision with which I agree. There is no benefit of with that isn't achieved through a simple temporary variable, and the latter has easier-to-control scoping. with brings additional caveats to scoping, especially when nested. It opens a completely different can of worms regarding ambiguity resolution which even when well defined can easily lead to subtle bugs. On top of that there are requests in the VB.NET forums to expand on With to allow access back to the expression, which is kind of silly since you can achieve that through a simple temporary variable too.

But at least you mentioned Pascal's implementation, which is sane. JavaScript managed to totally mess theirs up.
Feb 14, 2015 at 10:21 PM
We are no longer using codeplex for Roslyn. If you'd like the Roslyn developers to see your conversation, please start it as a new issue on https://github.com/dotnet/roslyn