Dear Hans, Taco, Mojca and Wolfgang, I see #define macros and gotos in LuaMetaTex code which is not good coding practice and not recommended. These are my first observations. I have started learning plain TeX so that I can understand the code better and send more suggestions to the list. -- Respect, Shiv Shankar Dayal
On 19 Jan 2024, at 09:47, Shiv Shankar Dayal
wrote: Dear Hans, Taco, Mojca and Wolfgang,
I see #define macros and gotos in LuaMetaTex code which is not good coding practice and not recommended. These are my first observations. I have started learning plain TeX so that I can understand the code better and send more suggestions to the list.
Dijkstra’s “GOTO is harmful" article was not nearly as absolute as modern programmers’ mindset. Using more “modern" branching using "if" would not make the code faster, and it would not automatically make it easier to understand either. A thing that is often overlooked these days is that goto statements create a documentation label as well as doing actual program counter update work. The “else” branch of an if-else statement in C does not have that feature, and IMO it makes reading nested if statements more painful than code with a few well-placed gotos. Another issue is that when gotos are used to jump out of a switch statement, that code can usually only be refactored by introducing new helper functions. That will make the code base more cumbersome as well as larger (and therefore slower). In cases where that is feasible, switching to branchless code would indeed help with speed. But not with readability, at all. On the many #define’s I agree it would be nice if as many as possible of the constants would be changed to const variables, as that would help with debugging quite a bit. But in the end, all of it is Hans’ call. Best wishes, Taco — Taco Hoekwater E: taco@bittext.nl genderfluid (all pronouns)
On 1/19/2024 10:21 AM, Taco Hoekwater wrote:
On 19 Jan 2024, at 09:47, Shiv Shankar Dayal
wrote: Dear Hans, Taco, Mojca and Wolfgang,
I see #define macros and gotos in LuaMetaTex code which is not good coding practice and not recommended. These are my first observations. I have started learning plain TeX so that I can understand the code better and send more suggestions to the list.
Dijkstra’s “GOTO is harmful" article was not nearly as absolute as modern programmers’ mindset.
Using more “modern" branching using "if" would not make the code faster, and it would not automatically make it easier to understand either. A thing that is often overlooked these days is that goto statements create a documentation label as well as doing actual program counter update work. The “else” branch of an if-else statement in C does not have that feature, and IMO it makes reading nested if statements more painful than code with a few well-placed gotos.
Another issue is that when gotos are used to jump out of a switch statement, that code can usually only be refactored by introducing new helper functions. That will make the code base more cumbersome as well as larger (and therefore slower).
Amen.
In cases where that is feasible, switching to branchless code would indeed help with speed. But not with readability, at all.
Maybe but indeed worse readability. Actually I found that compilers do a pretty good job on inlining so there is little to gain. Even link time optimization doesn't bring more than a few percent. In a similar fashiom we dont'use libs that have assembler optimizing bit dependent on architecture. No gain in practice.
On the many #define’s I agree it would be nice if as many as possible of the constants would be changed to const variables, as that would help with debugging quite a bit. But in the end, all of it is Hans’ call. Most of these defines are already enums and those left over are kind of harmless (and stand out nicely in the code editor which is also a reason for doing some thing in some way.) But occasionally i change some more.
When luametatex is kind of stable, I'll make the decission to change some of these left overs but that also impacts compatibility (no big deal for context for which is it meant anyway). btw, as long as gaining a few milliseconds is offset by bad user macros, styling, etc we can better educate usage instead of staring at code. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
participants (3)
-
Hans Hagen
-
Shiv Shankar Dayal
-
Taco Hoekwater