dbTalk Databases Forums  

VFP: Comment or Line Continuation Gotcha

comp.databases.xbase.fox comp.databases.xbase.fox


Discuss VFP: Comment or Line Continuation Gotcha in the comp.databases.xbase.fox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Gene Wirchenko
 
Posts: n/a

Default VFP: Comment or Line Continuation Gotcha - 10-13-2004 , 12:53 AM






I use VFP 6 SP 5. I have also confirmed that the behaviour noted
is the same under the VFP 9 beta.

I was writing some table comparison code earlier this evening and
ran into an interesting gotcha with comments or line continuation. I
am not sure why it works the way it does, but I can reproduce the
problem and the kludge to deal with it.

Following is greatly-simplified code that illustrates the
problem. In the actual program, I have a very long condition for the
if necessitating breaking the line up with line continuation in order
that the line be readable. Obviously, here the line continuation
could be eliminated, but that is not the point.

set talk off
a1=1
a2=1
b1=2
b2=42
c1=3
c2=3
if a1#a2 or;
b1#b2 or;
c1#c2
? "different"
endif
return

Obviously, this code compares two sets of values and reports
"different" if any of the pair values are not equal. In this case,
they are not.

On second thought, say that b1 and b2 do not need to be compared.
I could just delete that part of the code, but I might want it back
later, so I comment it out. The if is now:

if a1#a2 or;
; &&***** b1#b2 or;
c1#c2

However, this does not compile. Neither does:

if a1#a2 or;
&&***** b1#b2 or;
c1#c2

This does compile:

if a1#a2 or;
; &&***** b1#b2 or
c1#c2

I use the ; && <comment> style of commenting heavily in my SQL
create tables, as in:

create table cwkc;
(;
;
wccseq c(4) not null,; && WCC Sequencer
; && (for crptwkc)
wccode c(3) not null,; && Work Classification Code
wccdesc c(35) not null,; && Work Classification Code
Description
altwccd c(3) not null; && Alternative WCC
)

but I suppose I am just lucky that I have not previously done
something like:

create table cwkc;
(;
;
wccseq c(4) not null,; && This will cause trouble;
; && I just know it.
wccode c(3) not null,;
wccdesc c(35) not null,;
altwccd c(3) not null;
)

This does compile:

create table cwkc;
(;
;
wccseq c(4) not null,; && This will cause trouble; it
will,
; && I just know it.
wccode c(3) not null,;
wccdesc c(35) not null,;
altwccd c(3) not null;
)

What exactly is going on here? The trouble appears to be the
semicolon after the && when the semicolon is at the end of the
physical line. Why though when it is part of a comment?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.

Reply With Quote
  #2  
Old   
Fred Taylor
 
Posts: n/a

Default Re: Comment or Line Continuation Gotcha - 10-13-2004 , 01:15 AM






You'll just have to learn to not be so grammatically correct in your
comments. <g>

Really, I'm not sure why it even cares what's in a comment, but a trailing
";", even in a comment is a line continuation. The fact that you can't do
that in all situations of multi-line code doesn't really surprise me.

--
Fred
Microsoft Visual FoxPro MVP


"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> wrote

Quote:
I use VFP 6 SP 5. I have also confirmed that the behaviour noted
is the same under the VFP 9 beta.

I was writing some table comparison code earlier this evening and
ran into an interesting gotcha with comments or line continuation. I
am not sure why it works the way it does, but I can reproduce the
problem and the kludge to deal with it.

Following is greatly-simplified code that illustrates the
problem. In the actual program, I have a very long condition for the
if necessitating breaking the line up with line continuation in order
that the line be readable. Obviously, here the line continuation
could be eliminated, but that is not the point.

set talk off
a1=1
a2=1
b1=2
b2=42
c1=3
c2=3
if a1#a2 or;
b1#b2 or;
c1#c2
? "different"
endif
return

Obviously, this code compares two sets of values and reports
"different" if any of the pair values are not equal. In this case,
they are not.

On second thought, say that b1 and b2 do not need to be compared.
I could just delete that part of the code, but I might want it back
later, so I comment it out. The if is now:

if a1#a2 or;
; &&***** b1#b2 or;
c1#c2

However, this does not compile. Neither does:

if a1#a2 or;
&&***** b1#b2 or;
c1#c2

This does compile:

if a1#a2 or;
; &&***** b1#b2 or
c1#c2

I use the ; && <comment> style of commenting heavily in my SQL
create tables, as in:

create table cwkc;
(;
;
wccseq c(4) not null,; && WCC Sequencer
; && (for crptwkc)
wccode c(3) not null,; && Work Classification Code
wccdesc c(35) not null,; && Work Classification Code
Description
altwccd c(3) not null; && Alternative WCC
)

but I suppose I am just lucky that I have not previously done
something like:

create table cwkc;
(;
;
wccseq c(4) not null,; && This will cause trouble;
; && I just know it.
wccode c(3) not null,;
wccdesc c(35) not null,;
altwccd c(3) not null;
)

This does compile:

create table cwkc;
(;
;
wccseq c(4) not null,; && This will cause trouble; it
will,
; && I just know it.
wccode c(3) not null,;
wccdesc c(35) not null,;
altwccd c(3) not null;
)

What exactly is going on here? The trouble appears to be the
semicolon after the && when the semicolon is at the end of the
physical line. Why though when it is part of a comment?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.



Reply With Quote
  #3  
Old   
Jack Jackson
 
Posts: n/a

Default Re: VFP: Comment or Line Continuation Gotcha - 10-13-2004 , 01:02 PM



On Tue, 12 Oct 2004 22:53:31 -0700, Gene Wirchenko
<genew (AT) mail (DOT) ocis.net> wrote:

Quote:
I use VFP 6 SP 5. I have also confirmed that the behaviour noted
is the same under the VFP 9 beta.

I was writing some table comparison code earlier this evening and
ran into an interesting gotcha with comments or line continuation. I
am not sure why it works the way it does, but I can reproduce the
problem and the kludge to deal with it.

Following is greatly-simplified code that illustrates the
problem. In the actual program, I have a very long condition for the
if necessitating breaking the line up with line continuation in order
that the line be readable. Obviously, here the line continuation
could be eliminated, but that is not the point.

set talk off
a1=1
a2=1
b1=2
b2=42
c1=3
c2=3
if a1#a2 or;
b1#b2 or;
c1#c2
? "different"
endif
return

Obviously, this code compares two sets of values and reports
"different" if any of the pair values are not equal. In this case,
they are not.

On second thought, say that b1 and b2 do not need to be compared.
I could just delete that part of the code, but I might want it back
later, so I comment it out. The if is now:

if a1#a2 or;
; &&***** b1#b2 or;
c1#c2

However, this does not compile. Neither does:

if a1#a2 or;
&&***** b1#b2 or;
c1#c2

This does compile:

if a1#a2 or;
; &&***** b1#b2 or
c1#c2

What I think is happening is:

; is a continuation ONLY if it is at the end of a line OR if it is
followed only by a comment.

a = ;
5
a = ; && comment
5

In the second case the comment is restricted to what is at the end of
the line - the continued line is not part of the comment.

; at the end of a line that is preceeded by a comment continues the
line AND the comment. I don't believe there is any way to stop the
comment - all continued lines will be part of the comment.

Quote:
if a1#a2 or;
; &&***** b1#b2 or;
c1#c2
and

Quote:
if a1#a2 or;
&&***** b1#b2 or;
c1#c2
are really the same. The trailing ; continues the comment.



Reply With Quote
  #4  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: VFP: Comment or Line Continuation Gotcha - 10-13-2004 , 07:55 PM



Jack Jackson <jacknospam (AT) pebbleridge (DOT) com> wrote:

[snip]

Quote:
What I think is happening is:

; is a continuation ONLY if it is at the end of a line OR if it is
followed only by a comment.
The rules must be a bit more complicated than that or
; &&***** b1#b2 or;
would work.

[snip]

Quote:
if a1#a2 or;
; &&***** b1#b2 or;
c1#c2

and

if a1#a2 or;
&&***** b1#b2 or;
c1#c2

are really the same. The trailing ; continues the comment.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I think you have it. It makes sense as to explaining the
behaviour, but it does not make sense for how it ought to be.

Yet another gotcha to watch for. Should I make an acronym out of
it? YAGTWF?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.


Reply With Quote
  #5  
Old   
Bill Browne
 
Posts: n/a

Default Re: VFP: Comment or Line Continuation Gotcha - 10-25-2004 , 08:57 PM



I don't quite understand the 'gotcha'. From the VFP 5 help file:

Remarks

Place a semicolon ( at the end of each comment line that continues to a
following line. You cannot place && and a comment after the semicolon used
to continue a command line to an additional line.

--
Bill Browne
www.edgefinderstudios.com


"Gene Wirchenko" <genew (AT) mail (DOT) ocis.net> wrote

Quote:
Jack Jackson <jacknospam (AT) pebbleridge (DOT) com> wrote:

[snip]

What I think is happening is:

; is a continuation ONLY if it is at the end of a line OR if it is
followed only by a comment.

The rules must be a bit more complicated than that or
; &&***** b1#b2 or;
would work.

[snip]

if a1#a2 or;
; &&***** b1#b2 or;
c1#c2

and

if a1#a2 or;
&&***** b1#b2 or;
c1#c2

are really the same. The trailing ; continues the comment.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I think you have it. It makes sense as to explaining the
behaviour, but it does not make sense for how it ought to be.

Yet another gotcha to watch for. Should I make an acronym out of
it? YAGTWF?

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.



Reply With Quote
  #6  
Old   
Gene Wirchenko
 
Posts: n/a

Default Re: VFP: Comment or Line Continuation Gotcha - 10-26-2004 , 10:43 AM



"Bill Browne" <bill (AT) excalibur-dbf (DOT) com> wrote:

Quote:
I don't quite understand the 'gotcha'. From the VFP 5 help file:

Remarks

Place a semicolon ( at the end of each comment line that continues to a
following line. You cannot place && and a comment after the semicolon used
to continue a command line to an additional line.
I tend to write comments in English. The semicolon is part of
English punctuation.

The gotcha is what if a && comment ends with a semicolon. The
time that I got bit, this was the case.

In this case, there are two rules of punctuation (English and
VFP) in conflict. I know of no other programming language with this
glitch.

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.