3 ms·
> Try to debug a 10 level depth of nested #ifdef, across a 10000+ lines source code file My experience doing this is exactly why I'm saying do NOT split into O
by knorker 7y ago
> Try to debug a 10 level depth of nested #ifdef, across a 10000+ lines source code file
My experience doing this is exactly why I'm saying do NOT split into OS and arch.
Many times what should have "just worked" without even needing porting by anyone, turns into a multi thousand line refactoring just because of hard coded operating system names in the source code.
Let's say you have your sound code in sound_linux.cc and sound_freebsd.cc (and sound_openbsd.cc, and...) and then 10 years from now freebsd switches to entirely using ALSA.
Your code now breaks. If you'd instead done "sound_alsa.cc" and detected the ability to use ALSA at build time, then zero coding needs to be done.
The one exception I think is Windows. It's uniform enough over time, and entirely different from everything else, that it does make sense to have sound_windows.cc.
There are antipatterns other than foo_os_arch.cc, such as the one you point out (nested mess of #ifdefs in code), but that doesn't invalidate that module_os_arch isn't an antipattern. Because it is.
Go (the language) does "list of OS names", and it's a complete mess. Syscalls that actually are the same are not in the std library, because they were split by OS name. Had they tested for features the implementation would have been the same. And this hurts all users of that language as a result.
- pjmlp 7y agoThat just reveals that the architecture design was wrong to start with. We need more developers reading books like " Large-Scale C++ Software Design". It is such an anti-pattern that C and C like C++ codebases are the only ones that go down the #ifdef spaghetti route, with large majority of everyone else using modules to isolate architecture dependences. So not sure about it being an anti-pattern when it is the architecture design pattern with winning votes.
- knorker 7y ago> It is such an anti-pattern that C and C like C++ codebases are the only ones that go down the #ifdef spaghetti route Like I said the Go way is by far worse. Not sure if you're familiar with how this works in Go. > So not sure about it being an anti-pattern Well it is. I've given you enough examples.
- pjmlp 7y agoI am quite vocal about Go's language design, yet this is one thing I do agree with the design team. Well, it is an anti-pattern for you, not for those that write best practice large scale architecture design books, and the large majority of language designers out there that have created programming languages that eschew C like pre-processors. So I guess better leave at that, because we aren't going to agree.
- pjmlp 7y agoSomething I forgot to mention, I can also give you CERT, MISRA, JPL and AUTOSAR examples of anti-patterns, including this one being discussed.