[OpenSIPS-Users] Correct syntax with statement if

Liviu Chircu liviu at opensips.org
Tue Oct 31 10:13:37 UTC 2023


Hi, Dmitry!

> how different will this expression be from: ### example 2

They are identical, regardless of the presence/absence of any code below.

> To what extent is it correct to use one or another type of if statement?
>
It's not about correctness, rather readability.  Example 1 uses 3 LoC, 
while example 2 uses only LoC and it more readable, thanks to the 
absence of the braces.

> I understand that if we have to use else, then only the first option 
> will suit us, but here it’s more about a single if.. thanks
>
I recommend going through the Linux kernel coding style 
<https://www.kernel.org/doc/html/v4.10/process/coding-style.html#placing-braces-and-spaces> 
docs, there is a "placing braces and spaces" section, which includes 
several if-statement examples, with braces, "else" blocks, etc.  Why not 
borrow the same ideas for our own /opensips.cfg/ coding style? :-)

Best,

-- 
Liviu Chircu
www.twitter.com/liviuchircu  |www.opensips-solutions.com
OpenSIPS eBootcamp, Nov 6-17 |www.opensips.org/training
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20231031/f72a9f6f/attachment.html>


More information about the Users mailing list