[Info-vax] BASIC (and Horizon)

Dan Cross cross at spitfire.i.gajendra.net
Thu Feb 1 08:41:03 EST 2024


In article <upg5s6$2346b$1 at dont-email.me>,
Simon Clubley  <clubley at remove_me.eisner.decus.org-Earth.UFP> wrote:
>On 2024-01-31, Dan Cross <cross at spitfire.i.gajendra.net> wrote:
>>
>> I would argue this is more idiomatic, shorter, simpler, easier
>> to both read and to reason about, and uses fewer variables.
>>
>
>I agree and this is the general style I use, but with one difference.
>In my code, I always, always, use braces in an if() statement, even
>if the conditional code is only a single statement. For example:
>
>	const bool parsed_ok = PyArg_ParseTuple(args, "Os", &items, &msg);
>	if (!parsed_ok)
>		{
>		return NULL;
>		}
>
>I think that makes it more clear and removes any possibility of future
>code changes accidentally not adding the braces at that time.

That's fine.  Indeed, many modern languages mandate braces in
around the bodies of conditionals and loops as part of the base
syntax of the language (Go and Rust both do).  I didn't bother
because I only made the minimal changes to that crank's code.

>[And yes, about the above indentation, Simon _is_ indeed a Whitesmiths
>person. :-)]

From, Henry Spencer's, "The Ten Commandments for C Programmers":

|8. Thou shalt make thy program's purpose and structure clear to
|thy fellow man by using the One True Brace Style, even if thou
|likest it not, for thy creativity is better used in solving
|problems than in creating beautiful new impediments to
|understanding.

It is somewhat odd to me how contentious this is after so many
years, but I kind of get how attached one can be to a particular
code style.  When I worked at Google, I thought the mandated
style for C++ code was hideously ugly; after a few weeks, I
stopped noticing.  When `clang-format` came along, it was great
because it essentially eliminated all of the stupid style things
from reviews.  Go and Rust (and other modern languages)
effectively ended this as an issue by shipping with code
formatters and making people use them.

The bottom line for me, for C/C++ code, is that I don't care
what style one uses, as long as one is consistent; it is
shocking the extent to which divergent styles within a code base
can increase cognitive load.

	- Dan C.




More information about the Info-vax mailing list