DO block for single statement - pros and cons

Gasoline

New Member
Hi,

I've been trying to find out if it is good or bad, to put a single statement within a DO block.

E.g.

Code:
IF iValue > 1000 THEN DO:
    ASSIGN iHighValue = iHighValue + 1.
END.
versus

Code:
IF iValue > 1000 THEN
    ASSIGN iHighValue = iHighValue + 1.
The only information I've found is that the DO - END adds to the r-code.
I guess if a whole big system is build using DO END even when not needed, this would decrease performance/consume unnecessary disk space.

Could you please tell me which is the preferred way (best practice) and also why?

Thanks!
 

GregTomkins

Active Member
In our shop nobody does that and I would say it's unnecessary verbiage. I know a lot of C#/Java types espouse curly braces even when you don't need them, but I would not, and in any case, curly braces are lot less visually distracting, IMO.

I don't really care and I hate arguments like this, though. If this post doesn't get dozens of increasingly emotional responses defending whatever style they were taught, it's only because I wrote this paragraph.

Now, try to stir up a quality debate about something that requires more than a knee-jerk preference-based response, and watch the silence unfold. It's not just PT, either, the whole world is like this.
 
Knee-jerk preference-based responses are the only way forward, precisely because quality debates give too much weight to consideration of arguments.

Its all very well having a good understanding of the subject under discussion, but shallow, tribal back-and-forth is particularly well-geared to involving everyone, no matter how useless their opinion.

Anybody who says that's a bad thing must be some kind of fascist.
 
Hi,

I've been trying to find out if it is good or bad, to put a single statement within a DO block.

E.g.

Code:
IF iValue > 1000 THEN DO:
    ASSIGN iHighValue = iHighValue + 1.
END.
versus

Code:
IF iValue > 1000 THEN
    ASSIGN iHighValue = iHighValue + 1.
The only information I've found is that the DO - END adds to the r-code.
I guess if a whole big system is build using DO END even when not needed, this would decrease performance/consume unnecessary disk space.

Could you please tell me which is the preferred way (best practice) and also why?

Thanks!

It's only likely to have an impact if you are running Progress on a ZX81. So its down to personal choice. ie. the second example is correct.

Anyway, never mind that. Why is your DO: not aligned with your END?

Here:

Code:
IF iValue > 1000 THEN 
DO:
    ASSIGN iHighValue = iHighValue + 1.
END.
Much better, I think you'll agree.
 

TomBascom

Curmudgeon
Proper ;) alignment:
Code:
IF iValue > 1000 THEN 
  DO:
    ASSIGN iHighValue = iHighValue + 1.
  END.

Proper "casing", elimination of Hungarian notation & ridiculous variable names plus elimination of spurious DO and ASSIGN:
Code:
if i > 1000 then j = j + 1.

Commentary on original question...

Personally I would not use a DO in that situation but some seasons, good, bad or indifferent; these are just what pop into mind, to add the DO anyway:

1) Habit.
2) Planning for potential future code changes.
3) Symmetry with the ELSE portion of the IF.
4) Use of other aspects of a DO block such as TRANSACTION or FOR.
 

tamhas

ProgressTalk.com Sponsor
To your list I might add error handling as a reason to use the DO. But, then, you actually have to include the error handling.
 

Gasoline

New Member
Hi all,

Thanks for all the responses! I wasn't looking for an endless discussion, just facts, whether a DO block around a single statement affects performance or not. Maybe I should have put it like that in my original post. :rolleyes:

Since you seem to be the gurus of this forum, I trust and put much value in your answers.

Conclusion: Having or not having a DO block around a single statement doesn't affect performance. (other than possibly programmer performance)

To avoid further discussion about things that are just a matter of taste, I won't comment on the rewriting of the example code. After all, beauty is in the eye of the beholder ;)

Once again, thanks a lot!
 

GregTomkins

Active Member
Sorry for sounding like a jerk. We waste so much time on it though! There is even a name for it: Parkinson's Law, which states that it's easier to build a nuclear reactor than it is to pick a color for a bike shed.
 

Gasoline

New Member
Sorry for sounding like a jerk. We waste so much time on it though! There is even a name for it: Parkinson's Law, which states that it's easier to build a nuclear reactor than it is to pick a color for a bike shed.

No worries Greg. :up: :)
 
Top