Skip to main content
Share Your Experience: Take the 2024 Developer Survey

New answers tagged

0 votes

Is it good practice to rely on headers being included transitively?

My rule: Every header should compile on its own, so if a.h needs b.h then it includes it. Every header has protection against multiple inclusion. And source files include only what they need. In ...
gnasher729's user avatar
  • 45.7k
-1 votes

Is updating a macro value in Xcode preprocessors marcos violating open closed principle?

Step back a bit, and look at the purpose of the OCP: it is part of a set of principles or rules used to make your code better, more robust and maintainable. Making your code better is the actual ...
Technophile's user avatar
7 votes

Is updating a macro value in Xcode preprocessors marcos violating open closed principle?

First, make sure you have understood that the OCP is not violated at the time when you change some source code, see my answer here for a detailed explanation. The OCP is followed or violated at the ...
Doc Brown's user avatar
  • 209k
-1 votes

Is updating a macro value in Xcode preprocessors marcos violating open closed principle?

The open-closed principle is there to help you. So if you have the choice between violating the open-closed principle and not getting your job done, you get the job done. But you also have a ...
gnasher729's user avatar
  • 45.7k
12 votes

Is updating a macro value in Xcode preprocessors marcos violating open closed principle?

If your requirements have permanently changed, just change the code already. Anything else - including slavish devotion to the open-closed principle - is abstraction for abstraction's sake and does ...
Philip Kendall's user avatar
0 votes

Why are magic numbers bad practice?

In general, and as others have said, things used in multiple places should have a single source of truth to update when you need to change the value. The other primary reason is that a plain number ...
Iiridayn's user avatar
  • 237
1 vote

Is there a standard way or standard alternative to packing a struct in c?

Alluded to elsewhere, but not obvious to me until I saw it explicitly, is the option to use byte arrays everywhere. So instead of: struct aligned { uint16_t s; uint32_t i; uint8_t c; }; which ...
Heath Raftery's user avatar

Top 50 recent answers are included