|
I always thought that With (for all the time I used it) was simply to save keystrokes and on compiling, automatically prefixed all the statements beginning with ".property" with whatever object was in the With header.
Maybe even wrapping it in some code to cache the object since you would presumably be accessing it several times in the immediately following statements.
Ninja (the Nerd)
Confused? You will be...
|
|
|
|
|
The VB "with...end with" not only saves you typing, if the object being qualified is long and there are a lot of uses of it that you wrap between the "with...end with" you can potentially see some performance improvement. The fully qualified name only has to be evaluated once for the "with" statement, not for each line that references it within the block.
|
|
|
|
|
JMBeyer wrote: you can potentially see some performance improvement. The fully qualified name only has to be evaluated once for the "with" statement, not for each line that references it within the block.
What? C# is compiled language, what kind of run-time performance improvements you think you can gain by not evaluating fully qualified names at compile time?
|
|
|
|
|
VB.NET and C# are both compiled to byte code called MSIL (Microsoft Intermediate Language). When the executable is run, it is JIT (Just in Time) compiled. This means the code is actually being compiled on the fly on the user's computer. As it is compiled (on the user's computer at run time), the CLR performs some optimizations.
Some good links to look at for futher information:
http://msdn.microsoft.com/en-us/library/ms973838.aspx
http://msdn.microsoft.com/en-us/library/ms973839.aspx
http://msdn.microsoft.com/en-us/library/aa289513(VS.71).aspx
Finally this from Microsoft's documentation on the "With" keyword: "With...End With allows you to perform a series of statements on a specified object without requalifying the name of the object. If the qualification path to the object is long, using With...End With can improve your performance. A With block also reduces repetitive typing of the qualification path and the risk of mistyping one of its elements."
|
|
|
|
|
I don't see how you could improve performance of something the compiler needs to do for you.
The with keyword does save on typing and can improve the readability of the code, but that's it
|
|
|
|
|
That's a feature I'd like to see in C#.
The Java flavor where it is a contract from callee to caller (as opposed to the C++ "oh by the way this might happen" approach).
|
|
|
|
|
|
Yeah it does come with pros and cons. I like it because exceptions are hidden type couplings that throws makes explicit. But then again I was always one of those guys that liked to have my C++ classes const correct so maybe I'm just like that.
Perhaps it could come with a compiler switch to enforce or not enforce and thus be a design decision.
|
|
|
|
|
Instead of adding the throws statement it would be nice if the IDE would give you some sort of notice which errors could be thrown.
|
|
|
|
|
With statements in pascal and vb were rather useful, but it was a long time ago when a programmer had to remember all the field and variable names, not like today when you can't write without code completion.
Laziness is the programmers best friend.
|
|
|
|
|
Whenever creating a clone i'm using a with keyword.
Of couse one could write a private constructor. But then the arguments are named the same so i would probably use a 'with me'
|
|
|
|
|
I voted no because then I'd have to rename all my variables called with...
|
|
|
|
|
Oh, Crap! My # define s !
|
|
|
|
|
First of all I think that C# should be itself!
I mean that adding such a keyword will make C# more like VB -which I really don't like!-
Thats not the only reason because C# has lots of keywords, and I think adding a new keyword will make C# a language with a lot of keywords which will be a little confusing for some newbies.
In the other hand there is no need for this keyword, well consider this example:
class A
{
public void Foo();
public void anotherFoo();
}
class B
{
public void Woo
{
A a = new A();
with(a)
{
.Foo();
.anotherFoo();
}
}
}
Well I can write class B in another way which is better-at least I think so-
class B
{
public void Woo
{
A a = new A();
a.Foo();
a.anotherFoo();
}
}
as for the Ain't keyword, well as I said before about with keyword, however consider the above example:
class c
{
public A a;
public B b;
public bool isA(object obj)
{
return (obj.GetType() == typeof(A))? true: false;
}
}
Thats it.
What do you think guys?
Aamer A. Alduais
final_zero
My Favorite Qoute
"Faliure is the beginning of Success"
Aamer A. Alduais (^_^Me^_^)
|
|
|
|
|
I am not sure, but the With keyword disposes the current object (if it implements Idisposable) rather then waiting for the GC to come along.
|
|
|
|
|
[sarcasm]
try resume on ObjectReferenceException
{
object o = null;
string s = o.ToString();
return 0;
}
catch (Exception)
{
}
finally
{
}
[end sarcasm]
|
|
|
|
|
How about
Option Explicit Off ?
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep!
|
|
|
|
|
Oh ouch. I forgot about that one!
|
|
|
|
|
Something like this...
System.CSharp.OptionExplicit(false);
Best regards,
Lizandro Campbell
|
|
|
|
|
Under the hood, .NET actually can support that exception model IIRC. C# doesn't face it, however. I always figured it was left in their during initial planning for VB.NET.
--
Russell Morris
Morbo: "WINDMILLS DO NOT WORK THAT WAY!"
|
|
|
|
|
OMG, somebody shoot me ,)
|
|
|
|
|
Begging here: Should MS fix GDI+/WinForms not to cause 10,000 page-faults in 3 seconds of operation.
|
|
|
|
|
No point in starting a "Should Microsoft fix Personal Issue #4,712".
There's always things that can be done better, but for the moment we're busy whining about the keywords.
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
I so wish it was a 'personal issue'.
Never mind, I guess no one cares about something that has meaning, and background on around 9 million references to the problem, as well as every PC issue with a .NET framework on it.
Keywords are far more important I guess..
|
|
|
|
|
Guess I gotta state the obvious to the oblivious here.
For one, wrong forum.
For two, exactly what do you expect CP to do? Want them to mount a bronco and mosey on over to Washington to lasso up Billy G and make him watch Linux installs for days until he caves in and makes MS fix your issue?
Here's a thought, if it's a bug in .NET, email MS. If they ignore you, well, get a mac.
|
|
|
|