As always, ignore radiolisterer.
Let's keep the discussion respectful and focused on technical arguments rather than insulting personalities. It's perfectly fine to disagree, but dismissing someone's input by telling others to ignore them adds no value to the conversation.
It's more productive to debate the merits of different approaches based on facts and best practices rather than suggesting whose opinions should or shouldn't be heard. Let’s keep the conversation constructive.
So please refrain from resorting to cheap trolling and personal attacks by shifting the discussion towards personalities rather than the technical subject at hand
Macros are very much present in every non-trivial real world high-quality project for very good reasons; they are one of the fundamental reasons why C still is a popular language. Used right, they make the difference between unmaintainable copy-pasta spaghetti mess, and a readable/maintainable project.
The name of the relevant concept is Don't Repeat Yourself.
While it's true that macros are still commonly found in modern projects, they are largely a relic from older versions of C compilers, where the language syntax was less developed, and features like enum, constants, and inline functions weren't available. As a result, macros were used to achieve similar functionality.
Refactoring old legacy code is often a complex and time-consuming task that typically doesn't provide significant benefits, which is why such code is often left as is. However, it is important to acknowledge that macros come with well-documented downsides, including reduced readability, lack of type checking, and an increased potential for hidden bugs.
Many high-quality, modern projects actively avoid macros in favor of safer and more maintainable alternatives, such as const, inline functions, and enum. These alternatives not only improve the readability and safety of the code but also support better maintainability in the long term.
In other words, the old code using macros has already been debugged and is functioning as expected. While refactoring it to modern syntax will result in more readable and safer code, and you may uncover and fix some issues in the process, it will require a significant investment of time in development and debugging to achieve a version of the code that ultimately behaves in much the same way as the original. As a result, such legacy code is often left as-is. Additionally, macros may sometimes be used in new code to maintain consistency within the project, but this does not imply that it is the best or most appropriate approach for writing readable and safe code.
Goto is an excellent tool for people management. Once you hear stuff like... "goto is considered bad practice which leads to spaghetti code"... you instantly know that this person is operating like a bot
It’s important to separate technical practices from personal opinions. When someone says, "goto is considered bad practice and leads to spaghetti code," it typically means they understand the issues that come with using goto - such as creating hard-to-follow control flow and making debugging more difficult. Recognizing these problems is a sign of someone being aware of best practices and trying to avoid common pitfalls.
I worked in the highly regulated medical device industry, where the quality of code is critically important. This is because the code we wrote directly impacted human lives - it was responsible for the success of heart surgeries and other critical procedures. In such an environment, every line of code had to be meticulously reviewed and tested to ensure reliability and safety, as any failure could have severe consequences.
If you’ve had heart surgery at one of the leading hospitals in the United States, Israel, or Europe, it’s quite likely that my code was involved in the procedure. The software I developed played a critical role in ensuring the success of such complex and life-saving operations.
Engineers working on such projects understand the risks that come with poorly structured code. In fact, goto is often avoided precisely because it can introduce maintainability and reliability issues.
In our company, the use of goto in code reviews or interviews would have been a major red flag, and anyone who demonstrated a reliance on it would not have passed the interview.I understand that not all projects require such strict coding practices, and in my personal hobby projects, I sometimes take a more relaxed approach, but I never use goto statement even in my hobby projects and don't see any reason to use it. So, while goto might be considered acceptable in some niche cases, in general, it’s better to follow practices that enhance readability, maintainability, and safety - which is why goto is discouraged in modern development.