× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



whatt,

If you have a variable passed as a Const parameter that is also defined as
a global variable, the yes, you can get problems. But that has nothing to
do with the Const parameter, and everything to do with the module design.
All you need to do is rename the parameter (and how it's defined in the
procedure) and the compiler will use a new variable.

Rory


On Mon, Apr 29, 2013 at 1:59 AM, whatt sson <whattssonn@xxxxxxxxx> wrote:

Hi Barbara,

I usually also default to const.
But i'm not sure if this is always a good idea because sometimes you get
aliasing problems.
And i would rather have a program that is correct instead of a program that
performs a little better but where you have a chance that some nasty bug
gets introduced.

Now i default to value instead of const when i'm coding a local procedure.
For example, when i call a local procedure with a const parameter and pass
a variable that is globally defined within the same module chances are that
the parameter value "suddenly" is changed while executing that procedure.
For example when this procedure calls another local procedure doing things
with this global variable. This happens more often that you (i) think, for
example if the variable is a (record) datastructure. I pass it to a local
procedure (by ref) which reads a file a fills the datastructure, etc. This
pattern is quite common (passing record structures) but in this case you
really have to be careful.

However, if the procedure is in another module chances are much less that
calling this procedure has these kinds of side effects (and we don't want
side effects) happen because the other module is in another name space.

So i've chosen to always default to value for local procedures (i.e. they
are by defnition only called from within the same module), and const for
the other procedue (which can also be called locally of course).

But i'm still a bit in doubt. Always defaulting to value will make the code
more robust and easier to reason about. And defaulting to const is a kind
of premature optimization. And in cases where you have to pass large chunks
of data (>1k ?) it could be a good idea to use const for performance. But
in our environment which is mainly I/O bound this shouldn't be a problem
most of the time.


On Sat, Apr 27, 2013 at 6:14 AM, Barbara Morris <bmorris@xxxxxxxxxx>
wrote:

On 4/25/2013 8:19 PM, Alan Campin wrote:

If creating a procedure.

d pWriteScaleLog...
d pr
d PR_InScaleMessage...
d 128a Value


I would normally use CONST rather than VALUE for the string parameters
of a procedure. The difference in performance between CONST and VALUE
can be noticeable, especially for large varying length parameters where
the actual length is small. Maybe not particularly noticeable for 128,
but I still think it's a good practice to default to CONST rather than
VALUE for strings.

Unless the called procedure needs to change the parameter for its own
use, and even then, it might still perform much better to pass the
parameter by CONST, and make a local copy inside the procedure.

--
Barbara
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.


--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.





As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.