[OpenSIPS-Users] routing function variable scope

Kingsley Tart kingsley at dns99.co.uk
Mon May 10 08:27:34 EST 2021


Hi John,

I'm not offended at all, don't worry.

Personally I think it's counter-intuitive for a function to change
things outside of its scope. For example you wouldn't expect a call to
dp_translate() to change any of your own variables, apart from the AVP
into which you've told it to put the result.

I don't see how having locally scoped variables reduces readability but
as you note it does allow code re-use, which can be very useful.

Rookie programmers shouldn't be going anywhere near my OpenSIPS scripts
:) But they need to learn how to better program, and having a language
that can behave like many other popular ones is not something I see as
confusing for a learner.

Cheers,
Kingsley.

On Sun, 2021-05-09 at 18:20 +0100, John Quick wrote:
> Kingsley,
> 
> I hope you won't be offended, but in my opinion you are at risk of
> sacrificing code readability in the pursuit of code re-usability.
> If you accept that variables are in-scope both within the route and the
> sub-route, then why not just have one variable for the result - set it
> inside the sub-route and read the result from it immediately after the
> sub-route has returned. This may not be quite right for a code style
> perfectionist, but at least it would be easily understood by the rooky
> programmer who has to maintain your code in 5 years' time.
> 
> John Quick
> Smartvox Limited
> 
> 




More information about the Users mailing list