never done this NOW i know why I can't

never done this NOW i know why I can't

Post by Concerned Netize » Sat, 14 Sep 2002 06:55:48



D3 SCO

SUBROUTINE WIDGET(A,B,C,D)
IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
      B<1,A>=C<1,A>+B<1,A>
      IF B<1,A>='D' THEN
         C<1,A>='P'
      END
IF 'A'= 'ALL' THEN NEXT I
RETURN

wont compile... would anyone familiar with compiler design like to
explain why?

I Guess this an example of bad code. Could anyone explain why it's bad?

 
 
 

never done this NOW i know why I can't

Post by Patrick Latime » Sat, 14 Sep 2002 07:29:42


What's the value of 'A'

> D3 SCO

> SUBROUTINE WIDGET(A,B,C,D)
> IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
>       B<1,A>=C<1,A>+B<1,A>
>       IF B<1,A>='D' THEN
>          C<1,A>='P'
>       END
> IF 'A'= 'ALL' THEN NEXT I
> RETURN

> wont compile... would anyone familiar with compiler design like to
> explain why?

> I Guess this an example of bad code. Could anyone explain why it's bad?


 
 
 

never done this NOW i know why I can't

Post by Patrick Latime » Sat, 14 Sep 2002 07:39:05


Truth be told it looks like you cannot put the
end of a For/Next loop in a conditional. It makes
sense. If the IF statement is false, The NEXT statement
will never happen.

Had days like that too, Patrick <:=)


> What's the value of 'A'


> > D3 SCO

> > SUBROUTINE WIDGET(A,B,C,D)
> > IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
> >       B<1,A>=C<1,A>+B<1,A>
> >       IF B<1,A>='D' THEN
> >          C<1,A>='P'
> >       END
> > IF 'A'= 'ALL' THEN NEXT I
> > RETURN

> > wont compile... would anyone familiar with compiler design like to
> > explain why?

> > I Guess this an example of bad code. Could anyone explain why it's bad?

 
 
 

never done this NOW i know why I can't

Post by Luke Webbe » Sat, 14 Sep 2002 07:52:06


Top-posting because LookOut failed to quote the original post...

Your "NEXT I" is in a conditional statement, which screws up the blocking of
the code. I don't know of any language/compiler that would accept that
construct. But besides that, what's this 'A' = ALL business? ALL isn't a
variable name. And if you meant A = 'ALL', you've still got problems,
because A will be non-numeric, but you're using it as a VMC.

Also, it's innefficient to use a DCOUNT as a loop terminator. It gets
reevaluated on each pass through the loop.

Reading your mind, a partial answer is to move the code inside the FOR/NEXT
into a subroutine and call it once or inside a loop. But my preference might
be something like this...

IF A='ALL THEN
  ENDPOS = DCOUNT(B<1>,CHAR(253))
END ELSE
  ENDPOS = 1
END
FOR POS = 1 TO ENDPOS
  B<1,POS>=C<1,POS>+B<1,POS>
  ...
NEXT POS
RETURN

Luke


D3 SCO

SUBROUTINE WIDGET(A,B,C,D)
IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
      B<1,A>=C<1,A>+B<1,A>
      IF B<1,A>='D' THEN
         C<1,A>='P'
      END
IF 'A'= 'ALL' THEN NEXT I
RETURN

wont compile... would anyone familiar with compiler design like to
explain why?

I Guess this an example of bad code. Could anyone explain why it's bad?

 
 
 

never done this NOW i know why I can't

Post by Patrick Latime » Sat, 14 Sep 2002 08:21:54


Comment Embedded


> Top-posting because LookOut failed to quote the original post...

Shame on you !!!!!

Quote:

> Your "NEXT I" is in a conditional statement, which screws up the blocking of
> the code. I don't know of any language/compiler that would accept that
> construct. But besides that, what's this 'A' = ALL business? ALL isn't a
> variable name. And if you meant A = 'ALL', you've still got problems,
> because A will be non-numeric, but you're using it as a VMC.

> Also, it's innefficient to use a DCOUNT as a loop terminator. It gets
> reevaluated on each pass through the loop.

I saw that too , but was too lazy to correct it.

> Reading your mind, a partial answer is to move the code inside the FOR/NEXT
> into a subroutine and call it once or inside a loop. But my preference might
> be something like this...

> IF A='ALL THEN
>   ENDPOS = DCOUNT(B<1>,CHAR(253))
> END ELSE
>   ENDPOS = 1
> END
> FOR POS = 1 TO ENDPOS
>   B<1,POS>=C<1,POS>+B<1,POS>
>   ...
> NEXT POS
> RETURN

> Luke



> D3 SCO

> SUBROUTINE WIDGET(A,B,C,D)
> IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
>       B<1,A>=C<1,A>+B<1,A>
>       IF B<1,A>='D' THEN
>          C<1,A>='P'
>       END
> IF 'A'= 'ALL' THEN NEXT I
> RETURN

> wont compile... would anyone familiar with compiler design like to
> explain why?

> I Guess this an example of bad code. Could anyone explain why it's bad?

OK, Also

If the size is known, dim'ed arrays would be more efficient. Of course
only if they were passed in common. The variables would most likely be
better
passed in common as well. We could make this a contest.

Cheers, Luke ;)-

Can I send you some of my code for evaluation?
(only if you promise not to post it here) <g>

Patrick <:=)

 
 
 

never done this NOW i know why I can't

Post by Ed Sheeha » Sat, 14 Sep 2002 09:08:07


<snip>

Quote:> OK, Also

> If the size is known, dim'ed arrays would be more efficient. Of course
> only if they were passed in common. The variables would most likely be
> better
> passed in common as well. We could make this a contest.

Slightly askew observation:

In D3 you don't need to know the size; you can dcount the attr's, then
DIM ARRAY(SIZE). Way cool when you need to get thru a huge array in a
small amount of time, but have variable data.

Ed

 
 
 

never done this NOW i know why I can't

Post by Jeffrey Kaufma » Sat, 14 Sep 2002 09:25:29


How about this:

SUBROUTINE WIDGET(A,B,C,D)
IF A= "ALL" THEN
      CNT=DCOUNT(B<1>,CHAR(253))
      FOR I = 1 TO CNT
           B<1,A>=C<1,A>+B<1,A>
           IF B<1,A>='D' THEN
               C<1,A>='P'
          END
     NEXT I
END
RETURN

--

Jeffrey Kaufman
Key Data Systems Group
www.keydat.com
559-432-3832
559-432-4657 fax


D3 SCO

SUBROUTINE WIDGET(A,B,C,D)
IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
      B<1,A>=C<1,A>+B<1,A>
      IF B<1,A>='D' THEN
         C<1,A>='P'
      END
IF 'A'= 'ALL' THEN NEXT I
RETURN

wont compile... would anyone familiar with compiler design like to
explain why?

I Guess this an example of bad code. Could anyone explain why it's bad?

 
 
 

never done this NOW i know why I can't

Post by Mark Taylo » Sat, 14 Sep 2002 09:28:44




Quote:> D3 SCO

> SUBROUTINE WIDGET(A,B,C,D)
> IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
>       B<1,A>=C<1,A>+B<1,A>
>       IF B<1,A>='D' THEN
>          C<1,A>='P'
>       END
> IF 'A'= 'ALL' THEN NEXT I
> RETURN

> wont compile... would anyone familiar with compiler design like to
> explain why?

> I Guess this an example of bad code. Could anyone explain why it's bad?

You don't have clean IF-THEN-END statements first of all. This statement...

IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))

Since the IF-THEN falls on one line it does not need an END statment, but
the FOR-NEXT loop has no NEXT within the IF-THEN

You should probably write it like this...

IF 'A'= ALL THEN
        FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
        ...
        ...
END

And that brings up the...

'A'= ALL statement. Did you mean A = 'ALL'? As you have it written 'A' is a
literal and ALL is a variable. If you meant A = 'ALL' then you have the
other problem of using A as a VMC.

Then there is the problem of the loop. Your incrementing I each time
through the loop but never using it anywhere. The VMC is constant throught
the loop in your code. You probably meant to write it like this...

SUBROUTINE WIDGET(A,B,C,D)
        FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
       B<1,I>=C<1,I>+B<1,I>
       IF B<1,I>='D' THEN
          C<1,I>='P'
       END
        Next I
RETURN

Why not use A and 'ALL'?  Because you never had anything in the code about
what to do when A <> 'ALL' so why include it anyway?

What do we do when A <> 'ALL'? Let's add that to the code later...

Now, what are you trying to do with this...

B<1,A>=C<1,A>+B<1,A>

If the sub-values represented by B<1,A> and C<1,A> are numeric it all works
ok, but your next statement suggests that they could be alpha...

IF B<1,A>='D' THEN ....

So, there is more wrong here than we think.. Can you tell us more?

Mark

-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
   http://www.newsfeed.com       The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----

 
 
 

never done this NOW i know why I can't

Post by Luke Webbe » Sat, 14 Sep 2002 09:46:48




> > Top-posting because LookOut failed to quote the original post...

> Shame on you !!!!!

I hang my head in shame. OTOH, I don't know whether to blame LookOut for its
failure to quote or Concerned's newsreader for whatever put LookOut off.

[snip]

Quote:> OK, Also

> If the size is known, dim'ed arrays would be more efficient. Of course
> only if they were passed in common. The variables would most likely be
> better
> passed in common as well. We could make this a contest.

Actually, passing an array isn't much less efficient than passing a simple
variable. It's not like it has to pass each element separately or anything.

Quote:> Cheers, Luke ;)-

> Can I send you some of my code for evaluation?
> (only if you promise not to post it here) <g>

Shhh! I've got some code in my closet that would make a strong man weep. And
not all of it belongs to others. ;^)

Luke

 
 
 

never done this NOW i know why I can't

Post by Patrick Latime » Sat, 14 Sep 2002 09:56:02


This should most most likely be a GOSUB in the original
program. If it is used as an INCLUDE then all that is
needed is to extend the variable names to make them unique.

Patrick <;=)

P.S. yeah Luke I'm top posting. (a comment below though)


> How about this:

> SUBROUTINE WIDGET(A,B,C,D)
> IF A= "ALL" THEN
>       CNT=DCOUNT(B<1>,CHAR(253))
>       FOR I = 1 TO CNT
>            B<1,A>=C<1,A>+B<1,A>
>            IF B<1,A>='D' THEN
>                C<1,A>='P'
>           END
>      NEXT I
> END
> RETURN

Show off <g>.

- Show quoted text -

> --

> Jeffrey Kaufman
> Key Data Systems Group
> www.keydat.com
> 559-432-3832
> 559-432-4657 fax



> D3 SCO

> SUBROUTINE WIDGET(A,B,C,D)
> IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
>       B<1,A>=C<1,A>+B<1,A>
>       IF B<1,A>='D' THEN
>          C<1,A>='P'
>       END
> IF 'A'= 'ALL' THEN NEXT I
> RETURN

> wont compile... would anyone familiar with compiler design like to
> explain why?

> I Guess this an example of bad code. Could anyone explain why it's bad?

 
 
 

never done this NOW i know why I can't

Post by Luke Webbe » Sat, 14 Sep 2002 10:00:42





[snip]
> > SUBROUTINE WIDGET(A,B,C,D)
> > IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
> >       B<1,A>=C<1,A>+B<1,A>
> >       IF B<1,A>='D' THEN
> >          C<1,A>='P'
> >       END
> > IF 'A'= 'ALL' THEN NEXT I
> > RETURN
[snip]
> You don't have clean IF-THEN-END statements first of all. This
statement...

> IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))

> Since the IF-THEN falls on one line it does not need an END statment, but
> the FOR-NEXT loop has no NEXT within the IF-THEN

> You should probably write it like this...

> IF 'A'= ALL THEN
>     FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
>     ...
>     ...
> END

Nope. The intention seems to have been to execute that block of code once
only if A # 'ALL', or to iterate over the values of B<1> otherwise. Your
code will only work for the case where A='ALL'. The same is true for
Jeffrey's post.

Quote:> And that brings up the...

> 'A'= ALL statement. Did you mean A = 'ALL'? As you have it written 'A' is
a
> literal and ALL is a variable. If you meant A = 'ALL' then you have the
> other problem of using A as a VMC.

> Then there is the problem of the loop. Your incrementing I each time
> through the loop but never using it anywhere. The VMC is constant throught
> the loop in your code. You probably meant to write it like this...

[snip]

Yeah. It's a bit of a mess, I'm afraid.

Luke

 
 
 

never done this NOW i know why I can't

Post by Dale Benedic » Sun, 15 Sep 2002 00:15:00




> <snip>

> > OK, Also

> > If the size is known, dim'ed arrays would be more efficient. Of course
> > only if they were passed in common. The variables would most likely be
> > better
> > passed in common as well. We could make this a contest.

> Slightly askew observation:

> In D3 you don't need to know the size; you can dcount the attr's, then
> DIM ARRAY(SIZE). Way cool when you need to get thru a huge array in a
> small amount of time, but have variable data.

> Ed

Why even dim the array that way?

Pass the array in the parameter list and then use the statement: DIM ARRAY()

And the array gets sized to the one passed.  Using the extended compiler
option you can use the INMAT function to know what the size of the array
that was passed.

Regards,

Dale

 
 
 

never done this NOW i know why I can't

Post by Bill » Sun, 15 Sep 2002 01:54:33


Patrick:

If you really think bottom posting is good, try viewing these threads in
Google (hey, sometimes I have no choice).  Then, to read the responses you
have to click that darned
Read the rest of this message... (37 more lines)

message!  This is even more of a pain than using Outlook.  And besides, just
when did computer geeks get to know anything about manners? :-)

Bill


> Comment Embedded


> > Top-posting because LookOut failed to quote the original post...

> Shame on you !!!!!

> > Your "NEXT I" is in a conditional statement, which screws up the
blocking of
> > the code. I don't know of any language/compiler that would accept that
> > construct. But besides that, what's this 'A' = ALL business? ALL isn't a
> > variable name. And if you meant A = 'ALL', you've still got problems,
> > because A will be non-numeric, but you're using it as a VMC.

> > Also, it's innefficient to use a DCOUNT as a loop terminator. It gets
> > reevaluated on each pass through the loop.

> I saw that too , but was too lazy to correct it.

> > Reading your mind, a partial answer is to move the code inside the
FOR/NEXT
> > into a subroutine and call it once or inside a loop. But my preference
might
> > be something like this...

> > IF A='ALL THEN
> >   ENDPOS = DCOUNT(B<1>,CHAR(253))
> > END ELSE
> >   ENDPOS = 1
> > END
> > FOR POS = 1 TO ENDPOS
> >   B<1,POS>=C<1,POS>+B<1,POS>
> >   ...
> > NEXT POS
> > RETURN

> > Luke



> > D3 SCO

> > SUBROUTINE WIDGET(A,B,C,D)
> > IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
> >       B<1,A>=C<1,A>+B<1,A>
> >       IF B<1,A>='D' THEN
> >          C<1,A>='P'
> >       END
> > IF 'A'= 'ALL' THEN NEXT I
> > RETURN

> > wont compile... would anyone familiar with compiler design like to
> > explain why?

> > I Guess this an example of bad code. Could anyone explain why it's bad?

> OK, Also

> If the size is known, dim'ed arrays would be more efficient. Of course
> only if they were passed in common. The variables would most likely be
> better
> passed in common as well. We could make this a contest.

> Cheers, Luke ;)-

> Can I send you some of my code for evaluation?
> (only if you promise not to post it here) <g>

> Patrick <:=)

 
 
 

never done this NOW i know why I can't

Post by Concerned Netize » Sun, 15 Sep 2002 06:24:28


actually i was trying to simulate the problem I was experiencing. The code i'm working on is proprietary and I'm not allowed to post it.

i keyed in represntative code into notepad and pasted it here without testing it first.

I'm top posting too. Sorry to have taken up so many people's time. I was actually wondering theoretically it wasn't possible. I realize that no language to my knowledge allows for next as the end of a conditional, I was just wondering why it's not done.

it was easy enough though rather repetative to make the thing a subroutine and and make it work. Much thanks.

Oh and Sorry to top post...

(I think the best programmers are a bunch of eggheads)




> > D3 SCO

> > SUBROUTINE WIDGET(A,B,C,D)
> > IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
> >       B<1,A>=C<1,A>+B<1,A>
> >       IF B<1,A>='D' THEN
> >          C<1,A>='P'
> >       END
> > IF 'A'= 'ALL' THEN NEXT I
> > RETURN

> > wont compile... would anyone familiar with compiler design like to
> > explain why?

> > I Guess this an example of bad code. Could anyone explain why it's bad?

> You don't have clean IF-THEN-END statements first of all. This statement...

> IF 'A'= ALL THEN FOR I = 1 TO DCOUNT(B<1>,CHAR(253))

> Since the IF-THEN falls on one line it does not need an END statment, but
> the FOR-NEXT loop has no NEXT within the IF-THEN

> You should probably write it like this...

> IF 'A'= ALL THEN
>     FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
>     ...
>     ...
> END

> And that brings up the...

> 'A'= ALL statement. Did you mean A = 'ALL'? As you have it written 'A' is a
> literal and ALL is a variable. If you meant A = 'ALL' then you have the
> other problem of using A as a VMC.

> Then there is the problem of the loop. Your incrementing I each time
> through the loop but never using it anywhere. The VMC is constant throught
> the loop in your code. You probably meant to write it like this...

> SUBROUTINE WIDGET(A,B,C,D)
>     FOR I = 1 TO DCOUNT(B<1>,CHAR(253))
>        B<1,I>=C<1,I>+B<1,I>
>        IF B<1,I>='D' THEN
>           C<1,I>='P'
>        END
>     Next I
> RETURN

> Why not use A and 'ALL'?  Because you never had anything in the code about
> what to do when A <> 'ALL' so why include it anyway?

> What do we do when A <> 'ALL'? Let's add that to the code later...

> Now, what are you trying to do with this...

> B<1,A>=C<1,A>+B<1,A>

> If the sub-values represented by B<1,A> and C<1,A> are numeric it all works
> ok, but your next statement suggests that they could be alpha...

> IF B<1,A>='D' THEN ....

> So, there is more wrong here than we think.. Can you tell us more?

> Mark

> -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
>    http://www.newsfeed.com       The #1 Newsgroup Service in the World!
> -----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----

 
 
 

never done this NOW i know why I can't

Post by Patrick Latime » Sun, 15 Sep 2002 12:31:35



> actually i was trying to simulate the problem I was experiencing. The code i'm working on is proprietary and I'm not allowed to post it.

> i keyed in represntative code into notepad and pasted it here without testing it first.

> I'm top posting too. Sorry to have taken up so many people's time. I was actually wondering theoretically it wasn't possible. I realize that no language to my knowledge allows for next as the end of a conditional, I was just wondering why it's not done.

You could actually get the algorithm to work with a GOTO. <g> (making
friends<g>)

If you need the code let me know.

<;=), Patrick

P.S. still can't do anything with 'A' = 'ALL' ;)-

<snip>