Thanks Chris,
Will give this a go with the StringBuilder I was playing around with earlier.
Cheers,
Phil.
USING syntax ? - help please ...
USING syntax ? - help please ...
Chris,
FWIW, i don't get most of the use(fulness) of all this. If i know and want to get rid of a var at a certain point in my code, i can and should null it, with less keys to type and less visual clutter produced.
If i tend to reuse "names", i should better rethink my naming scheme and/or build smaller entities...
So, what remains?
Karl
FWIW, i don't get most of the use(fulness) of all this. If i know and want to get rid of a var at a certain point in my code, i can and should null it, with less keys to type and less visual clutter produced.
If i tend to reuse "names", i should better rethink my naming scheme and/or build smaller entities...
So, what remains?
Karl
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
USING syntax ? - help please ...
Hi Karl,
It's a matter of personal style, preferences etc. Purists will tell you that you should always use scopes and similar stuff, others will say all this is nonsense, personally I am somewhere in between
I'd say to everyone just use the way you prefer, no matter what is the "recommended" way to do something or not, just make sure you know the advantages and disadvantages of each method..
Chris
It's a matter of personal style, preferences etc. Purists will tell you that you should always use scopes and similar stuff, others will say all this is nonsense, personally I am somewhere in between
I'd say to everyone just use the way you prefer, no matter what is the "recommended" way to do something or not, just make sure you know the advantages and disadvantages of each method..
Chris
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
USING syntax ? - help please ...
Phil,
That notation in the docs is like the regular expression
END USING? garbage? eos
means:
END = mandatory end keyword
USING? = optional USING keyword
garbage? = optionally comments and other tokens until the end of the statement
eos = end of statement (either CRLF or semi colon)
END and USING are in capitals, they are tokens
garbage and eos are in lowercase, they are other parser rules.
Robert
That notation in the docs is like the regular expression
END USING? garbage? eos
means:
END = mandatory end keyword
USING? = optional USING keyword
garbage? = optionally comments and other tokens until the end of the statement
eos = end of statement (either CRLF or semi colon)
END and USING are in capitals, they are tokens
garbage and eos are in lowercase, they are other parser rules.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
- Phil Hepburn
- Posts: 743
- Joined: Sun Sep 11, 2016 2:16 pm
USING syntax ? - help please ...
Thanks for the explanation Robert.
I am about to spend a few hours on some 'Async/Await/Task' examples and so I will use the USING and scope stuff just to see how it works etc.
I am a bit like Chris, somewhere in between ;-0)
But over the years with .NET I do tend to declare variables much closer to where I need to use them - it feels right to me. And I try to dispose of some (external type) objects immediately after they have been used.
I can see what Microsoft are doing - trying to hide all/much code stuff that gets in the way of a more readable and descriptive business solution. They have done this in many places, some much bigger than others.
Must shoot - I think Alwyn wishes me to help him get going with XSharp, he's on the phone just now.
Best Regards,
Phil.
I am about to spend a few hours on some 'Async/Await/Task' examples and so I will use the USING and scope stuff just to see how it works etc.
I am a bit like Chris, somewhere in between ;-0)
But over the years with .NET I do tend to declare variables much closer to where I need to use them - it feels right to me. And I try to dispose of some (external type) objects immediately after they have been used.
I can see what Microsoft are doing - trying to hide all/much code stuff that gets in the way of a more readable and descriptive business solution. They have done this in many places, some much bigger than others.
Must shoot - I think Alwyn wishes me to help him get going with XSharp, he's on the phone just now.
Best Regards,
Phil.
USING syntax ? - help please ...
Hi Karl,
if I remember correctly what Fabrice said in his session: the "using" statement is very useful because you cannot forget to close a file - the runtime system does it for you.
And there is another important thing: after the end of a "using" statement the relative variable is collected immediatly (and the Dispose() method is also called).
Of course you can do that also by hand, but then you have also to provide a try-catch block to make sure the file is also closed when an exception occurs.
Personally, I don't like all of these new language features because I think some of them make the code harder to read, but the "using" statement is IMHO a very useful addition, and I'm pretty sure I will start to use it.
Wolfgang
if I remember correctly what Fabrice said in his session: the "using" statement is very useful because you cannot forget to close a file - the runtime system does it for you.
And there is another important thing: after the end of a "using" statement the relative variable is collected immediatly (and the Dispose() method is also called).
Of course you can do that also by hand, but then you have also to provide a try-catch block to make sure the file is also closed when an exception occurs.
Personally, I don't like all of these new language features because I think some of them make the code harder to read, but the "using" statement is IMHO a very useful addition, and I'm pretty sure I will start to use it.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
USING syntax ? - help please ...
Interesting. Is there a somewhat more "generic" description, what we can assume the runtime to do - and what not?Wolfgang Riedmann wrote:if I remember correctly what Fabrice said in his session: the "using" statement is very useful because you cannot forget to close a file - the runtime system does it for you.
TIA
Karl
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
USING syntax ? - help please ...
Hi Karl,
my earlier posted link to the MS documentation describes it:
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-statement
Wolfgang
my earlier posted link to the MS documentation describes it:
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-statement
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
USING syntax ? - help please ...
Wolfgang,
Nesting BEGIN USING is not really necessary.
This works, just like it does in C#
If you compile this and open it with reflector or ilspy you will see that under the hood indeed 2 nested using statements were generated.
Robert
Nesting BEGIN USING is not really necessary.
This works, just like it does in C#
Code: Select all
BEGIN USING LOCAL oStream := FileStream{"aa", FileMode.Open}, ;
oStream2 := FileStream{"bb", FileMode.Open} AS FileStream
? oStream:ReadByte()
? oStream2:ReadByte()
END USING
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
USING syntax ? - help please ...
Hi Robert,
thank you very much! Is is good to hear that this works also.
Personally I prefer the nested using statements because code is easier to read and to understand (IMHO readability is one of the most important advantages of X# over C#).
Wolfgang
thank you very much! Is is good to hear that this works also.
Personally I prefer the nested using statements because code is easier to read and to understand (IMHO readability is one of the most important advantages of X# over C#).
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it