2

There seem to be a lot of C++ questions where the best answer is "don't do that!" Common examples might be implementing one's own string or list class (often, as homework), or explicitly managing dynamically-allocated memory.

Doing so is almost always a bad idea, even for experienced C++ developers. But the questions generate a fair amount of chaff for the c++ tag on SO; and students (especially, it seems) rarely take the time to create a [mcve] (with emphasis on minimal).

This in turn leads to answers to poor questions, further increasing the detritus; most of these questions are likely to be of little use to future readers. Even a trivial implementation of a string or list is hard, and it's unlikely that the questioner will ever get it right; let alone those attempting to provide answers.

11
  • 2
    Your title doesn't match your body. Do you want to know how to handle poorly asked homework questions, or answers saying that the solution the question is looking for isn't appropriate? They're quite different questions.
    – Servy
    Feb 2, 2017 at 19:13
  • 12
    Then don't spend the entire body of your question talking about low quality homework questions, because it certainly seems like that's what you're asking about.
    – Servy
    Feb 2, 2017 at 19:15
  • 6
    Side note: idea that implementing some basic string/collection from scratch does not teach anything and not useful at all feels very controversial to me. Different people learn differently and the fact you don't see value in particular approach does not make such approach invalid/unacceptable. Feb 2, 2017 at 19:18
  • 4
    And yet your question doesn't even mention anything about what your actual title is asking. If I didn't read the title, I would have no idea that you cared one bit about answers that tell the OP their question is flawed. If that's what you actually care about, then make sure that's the question you actually ask about.
    – Servy
    Feb 2, 2017 at 19:18
  • @Dan I'm not seeing that from your question, so it would seem you still aren't whatever it is that you're really trying to ask clearly.
    – Servy
    Feb 2, 2017 at 19:24
  • 4
    You do what c++ tag watchers normally do, right? Track them down, kill them, their family, and their pets? Right? You guys do that, don't you?
    – user1228
    Feb 2, 2017 at 20:07
  • @Will "You guys do that, don't you?" Sure. What do you expect? I usually also track down their whole network appearance and that of their anchestors and destroy as much as I can. I'm doing so in the small time gaps left seeing incoming bad questions at the c++ tag. Feb 2, 2017 at 20:40
  • 3
    Dupes, dupes and more dupes. Most if not all of these questions have answers already but the OP has no idea how to find them or is too lazy to do so. That doesn't stop us from closing them. About half of my favorites are all dupe targets. Hopefully one day SO will make finding dupes easier and we can close this stuff even faster. Feb 2, 2017 at 21:03
  • The bigger problem I currently see on SO is that totally valid questions are not answered, instead people are commenting why it is not a good idea to do so. In my opinion we should first answer the question and then state why it might not be a good idea. I've seen a lot of question over the time where someone tries to write it's own implementation of something (may it be a string class) simply to understand how such things are working and instead of getting help gets told why it is a bad idea. Same goes for usage of legacy apis where "Don't use that version" is also not helpful.
    – BDL
    Feb 2, 2017 at 23:42
  • I honestly don't understand what you're asking here. Are you asking what to do about low-quality C++ questions? Or are you saying that there is some kind of problem with posting "don't do that!" as answers? Feb 3, 2017 at 5:34
  • @Dan: I agree if the comment is "Is there a specific reason why you wan't to implement it yourself instead of using xyz?", but most of the time the comment is more like "Don't implement this yourself it will take a long time and is error prone.".
    – BDL
    Feb 3, 2017 at 8:05

2 Answers 2

9

It's the near the beginning of another college semester for a lot of students, and with that comes various C++ assignments.

February flood? Well, relax!

Some of these assignments are the (unfortunately) all-too-typical "implement your own string or list class;" this is almost always a bad idea for a new C++ student (or, almost any C++ programmer, for that matter). It results in a fair amount of chaff for the c++ tag on SO.

I've been expressing my opinions what, and what not should be taught in c++ beginner courses at an external blog post.

As soon, these poor pupils may start to practice in industry we'll have to bring them back to reality and efficiency in 1st place.

This in turn leads to answers to poor questions ...

Not necessarily. Feel free to add any side notes and critique of the (required) coding style.

Homework questions are on-topic in general, as long they obey all policies we made up for on-topic questions.

You can even leave answers, that show how these poor techniques (required) are considered harmful for good c++ designs and explain why in detail.

13
  • @Dan Gain priviledges to be able to close vote more, and also to delete them quickly. Feb 2, 2017 at 19:25
  • 2
    All I will say is I have yet to meet a student get those assignments, such as writing a string class, correct (and I used to teach). It just doesn't happen. If it does happen, guaranteed the student got ideas how to write one correctly from reputable books and websites, and not just on their own through trial and error. Feb 2, 2017 at 20:21
  • 6
    @PaulMcKenzie Of course the goal isn't to end up with a working string/list/whatever class. The goal is for them to learn more about programming. So the real question is, "How much did they learn from the process?" and perhaps, "Is there another way of teaching that information more effectively?"
    – Servy
    Feb 2, 2017 at 20:56
  • @Dan "except how to (not) use SO" Do you actually consider this a bad effect? Feb 2, 2017 at 21:03
  • 2
    @Dan Sure, the people that just dump their homework assignment on SO probably aren't learning anything. They wouldn't be learning anything regardless of what the assignment was. The people spending time, experimenting, and figuring things out on their own, rather than asking SO to do it for them, are the ones actually learning (regardless of what the assignment is).
    – Servy
    Feb 2, 2017 at 21:04
  • 3
    @Dan Sure. The same is going to be true of virtually any homework assignment you could possibly come up with. These assignments don't generate any worse SO questions than any other type of assignment, nor is the quality of questions posted to SO really much of a consideration for the teacher creating assignments.
    – Servy
    Feb 2, 2017 at 21:11
  • 1
    @Dan "But most of the questions generated by writing one's own string or list already have numerous answers on SO" Well, propose duplicates then. Hammer these with dupes as you should privileged to to so. Feb 2, 2017 at 21:13
  • 1
    @Dan What are you doing when you find yourself in the middle of a Tsunami? Swim? Feb 2, 2017 at 21:17
  • Why does your blog have a giant photo of Bill the Lizard? Are you his sock puppet? Feb 3, 2017 at 5:33
  • @Cody LOL no! I had these geckos as pets 'til last year :.( Feb 3, 2017 at 13:21
  • 1
    I'm going to totally disagree with you. If a developer never writes these data structures for themselves, they'll never really understand how they work, the tradeoffs, why doing things with certain data structures are efficient or inefficient, etc. It shouldn't be the first thing taught, but a developer who hasn't tried to implement all the basic data structures is half trained and unhirable. THe goal of doing so isn't to create a production quality version of a string/list/other class- it's to understand the algorithms and complexities that only doing it yourself will get you. Feb 4, 2017 at 18:46
  • @Dan the goal here isn't to teach C++. Its to teach programming. Data structures are the second class you take, after a course in variables, if statements, and loops. Besides, goes do you expect them to learn pointers without writing these types of data structures (or writing assembly)? They just can't be, you need to experience to learn. Feb 6, 2017 at 18:26
  • @Dan and they're teaching assignments to be done in C++. Doesn't mean perfectly C++ is the goal. The goal is to learn dates structures and algorithms, C++ is the medium. Just like when I get in my car, the point isn't to sit and turn a wheel, it's to go somewhere. Feb 6, 2017 at 18:32
-3

Due to my limited experience with C++, I'm making a parallel to Java here, but I believe I have preserved the point

Don't do it isn't an answer

Only during the last week I've committed several atrocities with swing by (ab)using various layouts and mouse listeners about which I'd rather not talk about. Under normal conditions I'd respond to similar stuff with "Don't do it" and I understand that point of view completely. However, sometimes the scale won't allow you to do everything in a pretty and good way ("nice" solution might only work for datasets which count hundreds of points, but you need completely different approach possibly with some homemade stuff for hundreds of thousands), other times that thing won't play nice with other stuff you have previously implemented, or you'd like to avoid touching some inherited codebase unless absolutely necessary.

Googling for my issues, I have come across several "Don't do it" answers on SO suggesting some alternative and usually much simpler approach. The problem is, that simpler approach doesn't work for me and more importantly it isn't an answer. Sure, it might have helped OP (and sometimes not even that), but the priority of SO should be helping the community. The moment it's one of the top of Google results, it's not only relevant to the OP. If you want to give a suggestion, do so in comments. But when I come across something you've written several years later, please don't disappoint me with a non-answer.

My vote goes to treating all questions equally whether they ask for the "right" thing or not. If it's a duplicate mark it as such. If it asks for some overly complicated code, explain the principle and point to additional resources if necessary (having a STL implementation somewhere around is always useful; I know I have learned some stuff from standard implementations, though I must admit Java code is much prettier than C++ templates). I don't remember writing a snippet longer than 5 lines for any SO answer, except when I have already had the required code in some project so the only thing I needed to do was digging it up. A few paragraphs should be enough for any answer, and if anything homework assignments should be simpler in their essence.

And, well, if someone needs help with his/her homework, why shouldn't he ask for it on SO if it's warranted? So if it's a legit question, I see nothing wrong with guiding someone to the solution. Of course code dumps do no good and should be discouraged; they only increase cognitive load of understanding the code if you actually need to commit it somewhere.

5
  • 3
    Actually, don't do it, is an answer.
    – Braiam
    Feb 4, 2017 at 17:55
  • If you have a circumstances why the "don't do that" answer isn't valid, explain it in the question. Otherwise you're going to get it, and its the right answer in a lot of cases. There's way too many low experience devs here who just don't know that something like storing a password in a file in plaintext is a bad idea, and have to be told why not. Of course any don't do that should be paired with an explanation of why not and if possible alternatives to be a valid answer. Feb 4, 2017 at 18:45
  • 1
    I don't think password is a good example, but if the question is "How do I make a network request in Android?" the answer isn't "Don't do network by yourself, use Volley/Retrofit/XY library", but rather "Use HttpURLConnection, set address, method, add headers, connect only after ensuring X and Y, if response is <400 read from stream A, otherwise stream B, close when you're done, in that order". I remember spending awful lot time on trial and error. Answer such as "Do this instead, but if you really want to do it your way here's how, shortly, in one paragraph" would be perfectly fine.
    – Luke
    Feb 4, 2017 at 19:39
  • 1
    That way you both benefit the OP and the random stranger coming from Google. I have stopped vowing of not doing "evil" things a long time ago when I realized there's always that one case when it really is the best/easiest/most suitable way, and sometimes my evil is a bit rusty so Google leads me to SO and far too often SO leads me to a disappointment.
    – Luke
    Feb 4, 2017 at 19:43
  • 2
    "Don't do it" may not be the answer that you accept, but that doesn't mean it is not a valid answer. It is, and it is the answer that will be most useful to the largest number of people in the long run. Which is, not coincidentally, what Stack Overflow is here for. As Gabe said, there are lots of developers who don't know what is and what isn't a bad idea, so they might come up with a bad idea and go looking for a way to implement it. Their circumstances, unlike yours, may not require that they use a glass bottle to hammer a nail, so an answer that says "don't: use a hammer" is very useful. Feb 5, 2017 at 8:15

You must log in to answer this question.

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