-
Syntax Shortcut Suggestion
Does anyone else think it would be cool if we could declare the counting variable
in a For...Next loop within the For statement itself? For example, currently
we code this...
Dim a As Integer
For a = 0 To 9
Debug.WriteLine(a)
Next a
I find myself wishing I could code this instead....
For a As Integer = 0 To 9
Debug.WriteLine(a)
Next a
/Pat
-
Re: Syntax Shortcut Suggestion
I don't know - is our job to reduce the number keystrokes we must type to
accomplish a task, or is it to write something someone else can read 6
months after we hand it over to them to maintain it?
It would REALLY be cool for C and Java compilers to not be case sensitive.
don
"Patrick Troughton" <Patrick@Troughton.com> wrote in message
news:3caf8a0b@10.1.10.29...
>
> Does anyone else think it would be cool if we could declare the counting
variable
> in a For...Next loop within the For statement itself? For example,
currently
> we code this...
>
> Dim a As Integer
> For a = 0 To 9
> Debug.WriteLine(a)
> Next a
>
> I find myself wishing I could code this instead....
>
> For a As Integer = 0 To 9
> Debug.WriteLine(a)
> Next a
>
> /Pat
-
Re: Syntax Shortcut Suggestion
"dnb" <dnb@offramp.net> wrote:
>I don't know - is our job to reduce the number keystrokes we must type to
>accomplish a task, or is it to write something someone else can read 6
>months after we hand it over to them to maintain it?
Well, I'm not really suggesting this to decrease the number of keystrokes
although that's nice. It has more to do with code organization and consistency.
In legacy VB, I always kept my variable declarations and executable code
separate. All my variable declarations were at the top of each routine. This
was a great way to keep your code organized. But now that VB.NET includes
initializers/constructors, the line between variable declaration and executable
code is a bit blurred. In VB6, I always coded like this....
Dim x1 As Integer
Dim x2 As Integer
Dim y1 As Integer
Dim y2 As Integer
....
....
....
....
x1 = 1
x2 = 10
y1 = 1
y2 = 100
But in VB.NET, I find myself coding like this....
Dim x1 As Integer = 1
Dim x2 As Integer = 10
Dim y1 As Integer = 1
Dim y2 As Integer = 100
To me, it's a cleaner syntax. Also, instead of declaring the variable at
the top of the routine, I wait until the variable is actually used. Yes,
this means fewer keystrokes but it also can help increase maintainability
because you don't have to search through the code to find out where it's
used or what its (initial) value is.
To be honest, I'm not 100% sure which style I prefer but the more I code
in VB.NET the more I find myself using the latter style.
So if we can code this....
Dim y2 As Integer = 100
Why not this....
For a As Integer = 0 to 9
In my eyes, it's pretty much the same thing.
>It would REALLY be cool for C and Java compilers to not be case sensitive.
How about Option Case Sensitive? 
/Pat
-
Re: Syntax Shortcut Suggestion
On 6 Apr 2002 18:15:22 -0800, "Patrick Troughton" <Patrick@Troughton.com>
wrote:
> For a As Integer = 0 to 9
The c# version (yes I know *you* know):
for(int i = 0; i < 10; i++)
{
}
--
Turn on, tune in, download.
zane@mvps.org
-
Re: Syntax Shortcut Suggestion
"Zane Thomas" <zane@mabry.com> wrote
> > For a As Integer = 0 to 9
>
> The c# version (yes I know *you* know):
>
> for(int i = 0; i < 10; i++)
> {
> }
Would you want to show us a MSIL side by side comparison?
LFS
-
Re: Syntax Shortcut Suggestion
On Sat, 6 Apr 2002 21:47:07 -0600, "Larry Serflaten"
<serflaten@usinternet.com> wrote:
>Would you want to show us a MSIL side by side comparison?
IIRC, the last time that subject was raised the IL was identical whether
the declaration was inside the for() or just preceeding it.
--
Turn on, tune in, download.
zane@mvps.org
-
Re: Syntax Shortcut Suggestion
On 6 Apr 2002 15:51:39 -0800, "Patrick Troughton"
<Patrick@Troughton.com> wrote:
>
>Does anyone else think it would be cool if we could declare the counting variable
>in a For...Next loop within the For statement itself? For example, currently
>we code this...
>
>Dim a As Integer
>For a = 0 To 9
> Debug.WriteLine(a)
>Next a
I thought the Debug object had been replaced with the System.Console
class? Surely that should read: Console.WriteLine...?
MM ("Sorry if this opinion was controversial!")
-
Re: Syntax Shortcut Suggestion
Mike,
In message <3cb05f34.21870630@news.devx.com>, kylix_is@yahoo.co.uk (Mike
Mitchell) wrote:
> >For a = 0 To 9
> > Debug.WriteLine(a)
> >Next a
>
> I thought the Debug object had been replaced with the System.Console
> class? Surely that should read: Console.WriteLine...?
ROFL! As usual, you are wrong again.
Michael
-
Re: Syntax Shortcut Suggestion
.NET has both Debug and Console objects. Debug sents output to a window within
the VS.NET IDE and Console sends output to a 'DOS' Window.
/Pat
kylix_is@yahoo.co.uk (Mike Mitchell) wrote:
>
>I thought the Debug object had been replaced with the System.Console
>class? Surely that should read: Console.WriteLine...?
>
>MM ("Sorry if this opinion was controversial!")
-
Re: Syntax Shortcut Suggestion
"Mike Mitchell" <kylix_is@yahoo.co.uk> wrote
>
> I thought the Debug object had been replaced with the System.Console
> class? Surely that should read: Console.WriteLine...?
>
Do you see, Mike M, why I say your comments are uninformed, and devoid
of useful information?
LFS
-
Re: Syntax Shortcut Suggestion
On Sun, 07 Apr 2002 15:06:35 GMT, kylix_is@yahoo.co.uk (Mike Mitchell)
wrote:
>I thought the Debug object had been replaced with the System.Console
>class? Surely that should read: Console.WriteLine...?
Maybe you should spend some of your daily spew time reading instead, that
way you might not so consistently display your ignorance.
--
Turn on, tune in, download.
zane@mvps.org
-
Re: Syntax Shortcut Suggestion
Patrick Troughton <Patrick@Troughton.com> wrote:
And Trace objects alway goes to the output window, and can go to a file,
a database, or the console, depending on how you set up your listeners.
And I think they can fake-out a Response.Write in web apps, too.
> NET has both Debug and Console objects. Debug sents output to a window within
> the VS.NET IDE and Console sends output to a 'DOS' Window.
>
> /Pat
>
> kylix_is@yahoo.co.uk (Mike Mitchell) wrote:
> >
> >I thought the Debug object had been replaced with the System.Console
> >class? Surely that should read: Console.WriteLine...?
> >
> >MM ("Sorry if this opinion was controversial!")
>
>
--
Dave Rothgery
Picking nits since 1976
drothgery@alum.wpi.edu
http://drothgery.editthispage.com
-
Re: Syntax Shortcut Suggestion
Patrick,
>I find myself wishing I could code this instead....
>
>For a As Integer = 0 To 9
> Debug.WriteLine(a)
>Next a
As language changes go, this would be a good one IMHO. It adds a
feature and certainly doesn't affect existing code. I prefer
declarations at the top myself, but this doesn't keep me from doing
that.
In fact, it's functionally equivalent to "on the fly" code like
For a% = 0 to 9
>Next a
Lose the "a" in this line.
Then comes the question of scope of "a". That can either be local to
the For/Next or a level up. In *either* case it could be done without
affecting existing code (is there a trend here in consideration?<g>).
Dan
Language Stability is a *feature* I wish VB had!
(#6)
Error 51
Error 3
Error 9
....
-
Re: Syntax Shortcut Suggestion
G'day Larry.
I just ran up a test (in c#), with 3 scenarios:
1) Dec at top, for loop immediately after,
2) Dec in for loop
3) Dec at top, for loop after some other code.
In all 3 scenarios, the (relevant) IL was identical...
Basically it was:
.locals init ([0] int32 iLoop)
<Bla Bla>
IL_0004: ldloca.s iLoop
IL_0006: call instance string [mscorlib]System.Int32::ToString()
IL_000b: call void [mscorlib]System.Console::WriteLine(string)
IL_0010: ldloc.0
IL_0011: ldc.i4.1
IL_0012: add
<Bla Bla>
Cheers,
Paul
-
Re: Syntax Shortcut Suggestion
On 8 Apr 2002 09:47:42 -0800, "Jason" <jason@creative_nospam_corp.com>
wrote:
> FOR a AS INTEGER = 0 TO 9
> ...
> NEXT a
>
> FOR a AS LONG = 0 TO 9
> ...
> NEXT a
>
>In VB, both declarations for "a" are in the same scope. In C# or Java, a
>new scope is defined for the FOR loop.
Uhhh... since this feature doesn't exist yet (unless I misunderstand
something), the scope you *assume* has no meaning.
If they decide to allow "As xxx" in the For syntax (which currently
isn't allowed), they can decide how to implement it. They can scope
the variable to within the For/Next if they choose. However, they'd
need to leave current "For i% = 1 to 9" alone.
Language Stability is preserved doing this. Not that it matters.
Dan
Language Stability is a *feature* I wish VB had!
(#6)
Error 51
Error 3
Error 9
....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks