Hacker News new | past | comments | ask | show | jobs | submit login
#ifdef Confirmed Harmful – Promoting Understandable Software Variation (oregonstate.edu)
11 points by azhenley on Aug 27, 2021 | hide | past | favorite | 4 comments



Marlin project seems to abuse the hell out #ifdef and the project seems to work well. I don't know what I would use to replace them in an embedded space, they are counting every byte that gets created in binary, and used in memory.

I do agree anything larger than a project like Marlin the process turns into a mess, with little benefit.

Here is an example configuration file, it isn't that bad.

https://github.com/MarlinFirmware/Configurations/blob/import...


You can do something similar to what golang does. You can define an interface and then have a `thing_x86.c` and a `thing_arm64.c` etc. If you abstract the problem this way you are very explicit about what is being linked into the binary while not having the complex state management issues of preprocessor magic.


Embedded uses such HAL's extensively. There is no such nested ifdef mess mid-level devs love to create. Linux KConfig system is also properly designed, leading to properly seperated features.

Never mix compile-time logic with runtime logic, you get lost. No need for a study to verify this.

#ifdef is not considered harmful, only stupid usage of it.


Love this. Software needs to align more with people and this will certainly help.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: