3 ms·
Do enums change often enough for this to be a problem though? Often just adding a comment reminding to keep the enums in sync is enough.
by ufo 8y ago
Do enums change often enough for this to be a problem though? Often just adding a comment reminding to keep the enums in sync is enough.
- lomnakkus 8y agoObviously it depends on the particulars of any given project, but if you're deriving more than just the string names of the enum values it may be worth it. Using X-macros can sometimes reduce boilerplate hugely simply through avoiding switch statements on the enum values.
- tom_ 8y agoI think "often" is an exaggeration, but even if it did work that regularly, what about the times it doesn't? Meanwhile, you're sat in front of a computer. Its entire job is to keep on top of stuff like this. Why not use it?
- jstimpfle 8y agoBecause it's harder to do it in a complicated formal way than simply do it in the most straightforward way. If a type of mistake happens only very rarely and is typically easy to detect, it's almost certainly not a good idea to worry about it. You pay each time you express something using the more complicated formalism, and each time you work on parts that somehow have to deal with the more complicated artifact, and only every Nth time there is a marginal gain from using it.
- tom_ 8y agoIn the abstract, sure - it's not uncommon for projects to start to become consumed by their own infrastructure. But I've never seen X-macro enum stuff contribute to that. (This does of course presuppose that you really want to be able to always get the string name of an enum values. I've found this to be reliably the case, if only for logging purposes, but I've only got my own experience to go on.)