input parameter defined as constant

Posted by agent_008_nl on 03-Apr-2015 06:16

While reviewing some code I stumbled on an input parameter which is (mis)used as a variable: it's value is changed in the internal procedure where it comes in. Wouldn't it be nice to have constants in openedge. You could define the param as constant to make the intent (which is my default) clear.

Kind regards,

Stefan Houtzager

Houtzager ICT consultancy & development

All Replies

Posted by Evan Bleicher on 06-Apr-2015 16:04

Hi Stefan:  Some languages support the ability of defining a variable as a constant.  In your example, you would like procedures and functions to be able to specify that an INPUT parameter should only be used as a constant.  In this model, who should specify that the parameter is a constant, the caller or the callee?  Does there need to be agreement between them?

Please consider adding your request to the OpenEdge Enhancement Request portal so that Product Management and others can review this request.


Evan Bleicher

Posted by agent_008_nl on 07-Apr-2015 09:15

The callee, no agreement needed. I'll see that I post an enhancement request, thanks.


Kind regards,

Stefan Houtzager

Houtzager ICT consultancy & development

Posted by Marian Edu on 08-Apr-2015 01:05

I'm not aware of any language that have 'constants' parameters and not fully understand in which way updating the value of an input parameter can be seen as a misuse... I have to admit, this is something I do from time to time just to avoid defining an extra variable. I'm perfectly aware the change won't get propagated out of the method/procedure and if anyone else gets confused about how an input parameter behaves then I don't think adding a 'constant' option on it will make it more clear, guess not everyone should be allowed to 'read' code :)  

At most I see this something to be flag as a warning in a lint process.

Posted by agent_008_nl on 08-Apr-2015 03:18

Quick google result (more to be found doubless):


Kind regards,

Stefan Houtzager Houtzager ICT consultancy & development

Posted by Marian Edu on 08-Apr-2015 03:33

hmm, guess this is what catch you eyes... "When writing industrial-strength code, you should always assume that your coworkers are psychopaths trying to get you any way they can" :)

how would you see constant being applied to a reference/object... say a temp-table or dataset, are you allowed to update data in those or not because it's constant? if it's an object can you delete it or the compiler should forbid you to do so, maybe you can't even update it's properties or call any methods that affects it's state as a matter of fact...

still think will add more confusion instead of making it more clear but I'm open minded so feel free to show me a better way :)

Posted by agent_008_nl on 08-Apr-2015 04:27

No, I just googled this link to provide an answer. For temptables/datasets/(complex) objects I would not use const as default. It could be handy in cases though.

Posted by agent_008_nl on 08-Apr-2015 05:59

On what you admit here: "Remove Assignments to Parameters" is one of the refactoring patterns defined by Martin Fowler. See google.


Kind regards,

Stefan Houtzager Houtzager ICT consultancy & development

Posted by Marian Edu on 08-Apr-2015 06:53

I was merely agreeing with on-going refactoring this doesn't mean I agree/follow all refactoring patterns defined by Fowler or anyone else as a matter of fact :)

For by-value parameters I don't see any issue with doing that, yeah I might be lazy but for instance on pagination routine when I get the limit as input parameter I just decrements that till it hits zero and don't bother to use a local variable and don't expect any psychopath to hunt me down for that.

For references we already have a qualifier 'by-reference' for temp-table/dataset so 'constant' addition in that case is confusing. When passing handles (including temp-table/dataset but just as handle) and memptr's that might work but even there you expect the developer to impose restrictions on his own routine (callee) while, if anything, I can see a case when the caller would want to make sure his reference is not trashed away or made to point to something else.  

Posted by agent_008_nl on 08-Apr-2015 07:08

That is very independent of you (LOL!). I was very independent also, just stumbled on this refactoring after noting the smell (all by myself! :-)) in the review I was doing. So I thought let's notify Marian of the big name I found agreeing with me. :-)  I was btw not talking about on-going refactoring in this thread. You must be confusing communities and linkedin.

Posted by Marian Edu on 08-Apr-2015 07:56

lol, come on Stefan... I'm sure you don't need any big name to agree with you.

hope you're not reviewing my code by any chance, although if that was the only smelly thing that catch your attention it's definitively none of mine - I have to code with windows open because of the smell over here :)

Posted by agent_008_nl on 08-Apr-2015 08:36

I alway like to tease famous peggers/community personalities like you. ;-) You know me by now, I like to sustain my horrible name a bit.

  In fact I'm using the references to some big impressive names in the codereview I'm working on. Others might be sensitve for that, I trying to make an academic impression. ;-) It's all for charity.

  I should add that I have great respect for Martin Fowler, I like his books, articles and lectures (see youtube). 

This thread is closed