19

OK, so what happened here?

Adding error handling to a function that loads data (but also needs to use default values sometimes)

This question was cross-posted to Software Engineering by the OP, because someone suggested that it was off-topic on Stack Overflow.

Why is it off-topic?

8
  • 17
    The person who said it was "clearly off topic" also said "more then" in the same comment. Disregard. Commented Dec 21, 2017 at 18:00
  • 5
    @BilltheLizard If you don't say more then you can't really conclude that was an error... Commented Dec 21, 2017 at 21:04
  • 3
    @Dukeling: He's referring to the fact that the word "than" in "more then" is misspelled.
    – Robert Harvey Mod
    Commented Dec 21, 2017 at 21:05
  • 1
    It seems like a best practices / code review / opinion-based question. It may or may not be on-topic for Software Engineering or Code Review, but it doesn't seem like a great fit for Stack Overflow. Commented Dec 21, 2017 at 21:07
  • 5
    @RobertHarvey Dukeling is pointing out that there are valid cases of using "more then" ;) Commented Dec 21, 2017 at 21:12
  • 3
    As long as there is an officially sanctioned design tag, users will ask questions about code design. At any rate, this particular question's solution may well be very developer-centric. Sometimes, you simply don't know, whether a question is on-topic or off-topic, at the time you are asking the question. It's not uncommon for that information to become available only after an answer has been posted. Which may just be an overall defect of the StackExchange network. One I wouldn't know how to pinpoint, and even less so how to address. Commented Dec 21, 2017 at 22:36
  • 1
    Very well put @IInspectable, I think this is the hardest and most important problem on SO.
    – alain
    Commented Dec 21, 2017 at 23:30
  • 4
    I've never had a problem with design questions on SO. To me, most of Software Engineering is by definition good subjective and would fit on Stack Overflow. If Software Engineering had been pitched in its current form on Area 51, I don't think it would would ever have started.
    – Michael Myers Mod
    Commented Dec 22, 2017 at 1:30

2 Answers 2

14

Playing Devil's Advocate here, this question has a kind of...texture to it. It's not a question that immediately strikes me as a programming* question, but more of one of application design and engineering.

The main things that jump out at me are this:

But the code duplication and the entire set-up feels just bad. Same goes for using some kind of flag to tell parseValue() to throw/not-throw exceptions.

I'd like to avoid the code duplication, but the 'flag' option looks equally unappealing. Does anyone know of a better way to do this?

These are engineering opinions as opposed to concrete problems with code. There may be a problem with the engineering, but there may not be a problem with the code as written.

This is where the gray area of Stack Overflow really shows up; it feels like it could be on topic, but the reality is that we're scoped to handle practical programming* problems and not really ones where the developer is metaphorically at the whiteboard. There's more subjectivity in how this should be engineered to avoid the problems the OP has described from an engineering perspective, and we're not programmed equipped to deal with five or six conflicting opinions on the matter.

In that rationale, I could see why one would consider it off-topic.

*: I disambiguate between programmers and engineers in that one only writes code and the other engineers solutions.

16
  • 2
    Fair enough. But does the disparity rise to the level of closure or migration? (note that the post doesn't have any close votes or flags). If it doesn't, are we dispensing bad advice?
    – Robert Harvey Mod
    Commented Dec 21, 2017 at 17:49
  • 4
    @RobertHarvey: I usually take extreme umbrage with commentators who suggest that someone's post may be on topic on another site. It leads to a lot of situations like this, in which the OP gets confused because someone said something in a comment. I remain mostly on the fence about this being on-topic (which usually means "I don't think this is on-topic"), but I'm concerned about its migration path or future, since I'm not entirely clear how it'd be received on Software Engineering.
    – Makoto
    Commented Dec 21, 2017 at 17:51
  • 3
    Well, I disagree that "code duplication" is not about code, and coding problems are fairly strongly discouraged at Software Engineering (coding problems are already well-represented at Stack Overflow, and we have no interest in troubleshooting broken code at Software Engineering).
    – Robert Harvey Mod
    Commented Dec 21, 2017 at 17:54
  • 6
    @RobertHarvey: That's an interesting disambiguation. I'm grateful for the clarity. However, I'm not convinced the OP has broken code; it sounds like (from their question) that their code works, but they don't agree with how it's written.
    – Makoto
    Commented Dec 21, 2017 at 17:56
  • We eliminated code troubleshooting and code writing from Software Engineering as an entire category, not just broken code.
    – Robert Harvey Mod
    Commented Dec 21, 2017 at 17:58
  • 1
    @RobertHarvey: Hence why it's a gray area. I have an opinion on it, you have an opinion on it, the person that gave out the spurious advice to the OP had an opinion on it. I feel like the best way to definitively prove out the opinion would be to talk it out on Meta (and get more people to weigh in) as opposed to the OP haphazardly cross-posting the question. Again, I state that I'm on the fence (which means I have to lean towards "no"), but I can be convinced otherwise.
    – Makoto
    Commented Dec 21, 2017 at 17:58
  • 2
    @RobertHarvey: Fair enough. I'm not saying it's on-topic over there explicitly. I'm just saying I don't believe/am not convinced that it's on-topic here. I'm just...on the fence, really.
    – Makoto
    Commented Dec 21, 2017 at 17:59
  • 1
    @Makoto whats strikes me as even weirder is how the same user suggests code review a couple of comments up. Almost as if they have no clue and just try random sites....
    – Patrice
    Commented Dec 21, 2017 at 18:05
  • 1
    @Makoto you didn't even need to apologize for it :p it was pretty tame, considering the very confused message this commenter is sending, and how much confusion will rise from this :(
    – Patrice
    Commented Dec 21, 2017 at 18:12
  • 3
    I hate suggesting sites that I'm not an active contributor of (which is only Stack Overflow), but wouldn't code review be an appropriate choice in this regard given that the code works as expected, and the user is really looking for a review of the code and how it can be improved in a specified direction.
    – user4639281
    Commented Dec 21, 2017 at 19:17
  • 1
    @TinyGiant: I don't feel confident in recommending Code Review much these days. Worse, the OP doesn't actually have enough code in their question to review. This is why they're stuck at a whiteboard in my mind.
    – Makoto
    Commented Dec 21, 2017 at 19:25
  • 3
    @Makoto It should be fairly easy for OP to write enough code to have something that can be reviewed. So it probably shouldn't be migrated to Code Review (as it doesn't seem on-topic there as is), but there's a version of the question that's probably on-topic there. Commented Dec 21, 2017 at 21:26
  • Nothing personal @Dukeling, but given your relatively low reputation on that site, I don't trust that advice.
    – Makoto
    Commented Dec 21, 2017 at 21:26
  • 8
    Hey guys, remember when Stack Overflow was more than just a debugging site?
    – BoltClock Mod
    Commented Dec 22, 2017 at 2:35
  • 1
    @BoltClock: Y'know, I don't disagree. I'd like to think that this could be answered concisely. I've simply seen these kinds of questions shot down over the past few years. I don't want to give advice that's totally out of touch with how the rest of the community is actually moderating this; I'd rather give them guidance that'll improve their experience here. Above all though, I haven't seen much to get me off the fence about the question. I think it'd be safer for me (and anyone who has mixed feelings on it) to abstain from the question period, since it's still wishy-washy.
    – Makoto
    Commented Dec 22, 2017 at 7:03
3

If it would be C# question I'd vote as "completely opinion based". OP has several versions of perfectly valid working code and it feels like they just ask which one to like more (or maybe discussing "exceptions vs. error codes").

The "...looks equally unappealing. Does anyone know of a better way to do this?" is way too open. "...avoid the code duplication" is not enough for me to know when OP wants to stop - some extremely complicated solution with metadata stored somewhere, lambdas and DI is indeed an option to refactor 3 lines of semi-repeated logic, but how much repetition is in code similar to:

 s = source.parseWithDefault(ITEM_1, "bob");
 x = source.parseWithDefault(ITEM_2, 42);
4
  • 2
    Meh. This isn't rocket science; anyone with a reasonable amount of experience in the OP's topic area ought to be able to discern what a sensible approach is.
    – Robert Harvey Mod
    Commented Dec 21, 2017 at 23:51
  • 1
    The OP isn't asking, which of the versions to prefer. They have already decided to report errors in newer revisions, while retaining compatibility with older ones, that use default values in case of an error. They aren't asking for opinion here. Commented Dec 22, 2017 at 11:23
  • @IInspectable: "They aren't asking for opinion here" -- of course they are. There are a number of different design approaches they could follow, any number of them qualifying as "sensible". There are no criteria provided that would constrain the answer to one single design, and any of the designs could work, leaving only an opinion based answer as an option. Commented Dec 24, 2017 at 3:46
  • @PeterDuniho: Even if there are multiple ways to implement, what the OP is trying to solve, an answer need not be based on opinion. It can provide rationale alongside each implementation, giving visitors the information they need to make a judicious decision. As for the criteria: While not explicitly stated, it can easily be inferred, that the OP is looking for a solution that's optimized for maintainability. Commented Jan 3, 2018 at 9:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .