lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>I guess technically you don't need the brackets in statements like:
>
>if (depth == 0) {
> luasdorintf("%-5i | ", stackIndex);
>} else {
> luasdorintf("       ", stackIndex);
>}
>
>It could be written like:
>
>if (depth == 0)
> luasdorintf("%-5i | ", stackIndex);
>else
> luasdorintf("       ", stackIndex);
>
>but IMO this is a stylistic choice, and I usually prefer the former, as it prevents mistakes like:
>
>
>if (depth == 0)
> luasdorintf("%-5i | ", stackIndex);
>else
> luasdorintf("       ", stackIndex);
> do_another_thing(); //oops, not conditional

Well, as for me, it's not a matter of preferences. I've been facing a lot of issues with this unconditional 'do_another_thing' in somewhat large projects with 5+ developers. So, for me it's not a style, but the guideline. Fun fact, it is not so for linux kernel, as stated in chapter 3 of the linux kernel coding style. I guess that's where this idea comes from mostly. However, for all us non-hackers, the safest approach is the best IMO. Plus, even if you are cautious enough, placing the braces in advance allows to minimize the patch size and layout when adding another statement. This is particularly true for K&R braces, because in this case adding the damn brace will trigger the condition line to be "changed" as well.


On Tue, Oct 11, 2016 at 1:19 AM, Kevin Martin <kev82@khn.org.uk> wrote:
Have a look at luaprompt. That includes a pretty printer, luap_describe, I incorporated it into the software of the company I used to work for, don't think we ever found an issue.

Thanks,
Kevin

Sent from my iPhone

On 10 Oct 2016, at 21:31, Nagaev Boris <bnagaev@gmail.com> wrote:

On Mon, Oct 10, 2016 at 11:06 PM, Rena <hyperhacker@gmail.com> wrote:
On Mon, Oct 10, 2016 at 3:52 PM, Igor Ehrlich <iehrlich@iponweb.net> wrote:

And, overuse of brackets...
At this point I got really curious. Could you please be more precise?


I guess technically you don't need the brackets in statements like:

if (depth == 0) {
luasdorintf("%-5i | ", stackIndex);
} else {
luasdorintf("       ", stackIndex);
}

It could be written like:

if (depth == 0)
luasdorintf("%-5i | ", stackIndex);
else
luasdorintf("       ", stackIndex);

but IMO this is a stylistic choice, and I usually prefer the former, as it
prevents mistakes like:


if (depth == 0)
luasdorintf("%-5i | ", stackIndex);
else
luasdorintf("       ", stackIndex);
do_another_thing(); //oops, not conditional

Anyway, bikeshedding aside, it's been pointed out on this list before that
"public domain" isn't legally recognized in some parts of the world, and
you're better to use something like the MIT License (that Lua uses itself)
which gives the same effect without any potential hassle for those who want
to use it.

--
Sent from my Game Boy.

+1 for not omitting { and } in one-line if and else.

--


Best regards,
Boris Nagaev




--
Best regards,
Igor A. Ehrlich