I'm writing this C code in which inheritance is emulated by means of composition, and I'm unsure whether I should give each child struct
its separate .c and header files as is normally done in other OO languages, or if I'd be better off just keeping them in the same two files. Would it be on topic to ask if there is a "right" answer to this problem, provided an MRE illustrating how the inheritance is emulated?
-
1OK, "...inheritance is emulated..."– Peter MortensenCommented Jul 7, 2023 at 23:50
-
3define "right". "works"? "maintainable"? "build performant"? see also /help/dont-ask– starballCommented Jul 8, 2023 at 0:06
-
@starball more understandable, flexible, and maintainable, basically the option most conforming to the SOLID principles.– Mehdi CharifeCommented Jul 8, 2023 at 0:12
-
6All these "understandable, flexible, and maintainable" terms are subjective and opinion-based.– Gino MempinCommented Jul 8, 2023 at 4:10
-
2It will be very difficult to formulate such a question so that the answer does not depend on the individual's opinion. Consequently, it will most likely be closed as off topic. But the answer to your question is, of course, separate files - IMO ;-)– 4386427Commented Jul 8, 2023 at 6:01
-
@KarlKnechtel I don't think so. The accepted answer does, though.– Mehdi CharifeCommented Jul 8, 2023 at 17:20
-
2@KarlKnechtel: I don't know if you read this question properly, as the proposed duplicate you linked has absolutely nothing to do with it. The question didn't ask to discuss the naming of a closure reason - it asks if a certain type of question is on topic here.– Ken WhiteCommented Jul 8, 2023 at 17:31
-
1@KenWhite it's quite simple. The question is "is a question like this on topic?" and the answer is "obviously not, because it's opinion based". I found the best reference question I could about why opinion based questions are off topic generally. Unfortunately I can't VTC questions as duplicates of stackoverflow.com/help/dont-ask, which is primarily dedicated to laying out the logic of what kind of subjectivity is unacceptable for questions here.– Karl KnechtelCommented Jul 8, 2023 at 17:37
-
@KarlKnechtel "I found the best reference question I could about why opinion based questions are off topic" Is this question on-topic and why opinion-based questions are off topic are totally different questions with different answers. As you have stated, the answer to the first is "because it's opinion-based", while the answer to the second is more like a follow-up question on why the first answer is correct about opinion-based questions being off-topic. It's not simple, it's wrong and totally convoluted.– Mehdi CharifeCommented Jul 8, 2023 at 22:24
Add a comment
|
1 Answer
No. They are almost always (if not always) closed as being opinion-based, as what is right is subjective. Who defines right? Right in what sense? If you're working on your own, find a good book or tutorial on your language of choice and follow their advice. If you're working with a team, ask the other developers you work with how they (or your company) prefers things to be done.
-
1Yea. Basically you need to work out what is "right" ... for you. Commented Jul 8, 2023 at 6:27
-
@Ken This question stackoverflow.com/questions/6316987/… seems to be asking a similar question, but was relatively well-received, which doesn't necessarily prove that it's on topic, but would you say that it falls under the same category of opinion-based quesitons? Commented Jul 8, 2023 at 17:29
-
5Very many old questions were well received that would be considered off topic today. We don't make it a particularly high priority task to close them. That said: there are objective consequences to putting a structure definition in a header file, because of the one-definition rule. Putting definitions for related classes in the same file or different files, on the other hand, is much more a matter of taste, and any specific reasons to choose one way or another will be idiosyncratic to the project. Commented Jul 8, 2023 at 17:39
-
4@MehdiCharife: Existence of other questions isn't relevant. There are thousands of questions here that were asked in the early days of SO's existence that were allowed then (because they needed the traffic) that are not acceptable today. They typically still exist because of historical reasons (posts linked to them, for instance), What matters are the guidelines that are in effect at the time the question is being asked, as those guidelines evolve over time. Commented Jul 8, 2023 at 17:44
-
@KarlKnechtel I don't understand what you mean by objective. Every decision has consequences, and those are real, by definition. The term "objective" here is a mere redundancy. Commented Jul 8, 2023 at 22:27
-
1@MehdiCharife: I don't understand your question. I never used the word objective in either my answer or comment, AFAIK. I've re-read both of them a few times, and if it's there I can't see it. Commented Jul 8, 2023 at 22:32
-
@KenWhite Yes, I didn't claim otherwise. I was tagging the other user who believes that my question is a duplicate. Commented Jul 8, 2023 at 22:34
-
2"The term "objective" here is a mere redundancy." No, it very clearly isn't. It clearly matters whether the consequence is "the compiler fails to produce a working program" vs. "the project doesn't meet someone's opinion of good coding practice." There's a clear difference between something that consistently and reproducibly produces a compiler error, vs. a choice that makes some projects easier to maintain and others harder to maintain. Commented Jul 8, 2023 at 22:57
-
@MehdiCharife: Sorry. Karl didn't address the comment to you specifically (using the @ syntax), which caused it to appear in my inbox. I saw his comment appear, noted it was to this answer, saw your comment, and missed that you had addressed it to someone else (probably because the name you responded to started with the same letter as my first name). My fault entirely. Commented Jul 8, 2023 at 23:14