0

I asked this question recently, which quickly got downvoted and closed as unfocused, giving the advice to rewrite it so that it focuses on only one problem. I don't understand this at all though- as far as I can see, my question is quite clear about what it is asking, and it is only asking one thing 'what changes can I make to my code to enable two computer programs to play against each other'. This is an open-ended question, but a lot of questions on stack overflow are open-ended, and that's not the same thing as being unfocused (is it?).

The two comments I received were not negative about my question and gave useful advice, though either would require a lot of rewriting to implement, and added complexity to all future additions to my code, so I would really like my question to stay open in the hope that someone proposes a different solution that scales better, and ideally avoids lots of rewriting.

The only thing I can think of that might be objectionable is that I didn't include my code, but given that the question is about the entire project that wouldn't be possible, and showing the structure of the main loop is the closest I can think of to that. But that doesn't seem to be what the question was closed for anyway.

So hopefully it's clear I've tried to figure out for myself why people are downvoting my question, and my only remaining avenue, at risk of incurring the meta effect, is to ask this question. I'm also not trying to beg for upvotes, I just want to know what I can do to avoid this happening again.


I have made revisions to my question which attempt to address issues raised in the comments. Hopefully this addresses those concerns, though I often haven't been able to take the approach suggested, and have added an explanation of why instead.

15
  • 12
    "The only thing I can think of that might be objectionable is that I didn't include my code, but given that the question is about the entire project that wouldn't be possible," doesn't the fact that you are talking about an entire project which you can't even include, imply to you the question is far too broad and would benefit from focus?
    – VLAZ
    Commented Aug 16 at 6:16
  • 10
    After reading the question...it's not even about one topic. You say you want to have to AI players in it. That's what the title and the opening is about. Then you also reveal you have achieved this. But seems the actual problem you say is about having many print statements. Well, maybe. There is a one issue that the output is cluttered due to all the printing. But also there seems to be an issue with speed which you guess is due to the print statements. In summary, where the question starts and ends aren't even the same place.
    – VLAZ
    Commented Aug 16 at 6:24
  • Basically what @VLAZ said, but trying to turn this into actionable suggestions: Your question has nothing to do with a pokemon game. Nor has it anything to do with AI (not even if we are calling machine learning AI). You need to edit your question to focus on turning off print statements. We don't need to know what your program is trying to do, to help you turning off print statements. Commented Aug 16 at 6:51
  • 5
    Also, sentences like this often aren't too well received: "I don't have a very good idea about what takes what amount of time [...] I suspect printing might take the majority of the processing time". If you have a performance problem, you should measure the impact of printing and be sure about it. If you don't have a problem with performance, no need to mention it. (Though I expect printing could actually have a considerable impact). Commented Aug 16 at 6:55
  • @VLAZ Thank you for your advice. I'm not sure how I could narrow it down, as I wasn't sure what aspect of the project would need changing, so I could only ask about the project as a whole. I thought the solution might lie with a change in logging, but I didn't know, and my print statements are scattered all through my code, so I couldn't show them all. Is there a better way I could ask questions like that? or are questions about the design of whole projects just not appropriate?
    – Zoe Allen
    Commented Aug 16 at 6:56
  • 1
    @VLAZ I haven't rewritten the code as I indicated in my question, it was just to illustrate what I was trying to achieve, and what the problem was with trying to do it. I have edited my question to hopefully avoid giving that impression. My question is about what change to make, not about how to fix a specific change I've already made.
    – Zoe Allen
    Commented Aug 16 at 6:58
  • @JeanotZubler Thank you for your suggestions. I will change the title to something that fits better. Do you have any suggestions? The reason I didn't do that initially was because I didn't know the solution lay with print statements, so I didn't want to make the question about that. I was talking about performance because I want to avoid future performance problems. I haven't made the modifications I talk about yet, because I wasn't sure how I could do it that would work.
    – Zoe Allen
    Commented Aug 16 at 7:02
  • 4
    Meta effect check: The question's score on the main site is at 0/-4 at the time of my writing this comment (just under 1 hour after this Meta question was posted).
    – Cody Gray Mod
    Commented Aug 16 at 7:12
  • @CodyGray it was at -3 when I posted the question btw
    – Zoe Allen
    Commented Aug 16 at 7:14
  • 1
    The question is also a bit vague on if you actually need to turn off print statements, or if it's fine to run the program and redirect the prints to nothing (which is a common thing people do, and is very easy to do).
    – Erik A
    Commented Aug 16 at 7:53
  • 1
    A title change alone doesn't make the question more focused. What do you mean with "I didn't know the solution lay with print statements"? because that's the only actual question I can extract out of your post. It doesn't necessarily have to be turning the print statements off, redirecting might be fine, but the whole question revolves around the print statements, doesn't it? Commented Aug 16 at 8:18
  • @JeanotZubler I don't know what other options are available, I'm new to python. Maybe there are alternative modes you can run code in? maybe I could call the code from a different project? Maybe there's something else? I don't know if these ideas make sense, but I don't know what I don't know, which is why I wasn't sure if changing the printing was where the solution lay. That seems to be the conclusion though, and I have tried to change my question to reflect this.
    – Zoe Allen
    Commented Aug 16 at 8:23
  • @ErikA That's not something I was aware of. I am new to python.
    – Zoe Allen
    Commented Aug 16 at 8:33
  • 1
    @ZoeAllen That's not exclusive to Python as well, all common shells allow output redirection of programs. See stackoverflow.com/q/617182/7296893 and stackoverflow.com/q/1262708/7296893 for examples. That's a problem with your question, if this would be a valid answer, literally everything in your question including that you use python would be irrelevant, and the only relevant thing would be which OS you're using, which isn't listed in the question.
    – Erik A
    Commented Aug 16 at 8:41
  • 7
    Being new to something is not usually the best state to be asking Stack Overflow compatible questions. They are likely under-researched or even a duplicate. But because you don't know, you can't recognise it. Be careful what questions you ask on Stack Overflow in this stage of your learning journey, not all questions belong on Stack Overflow. Sites like Codidact and Reddit are ready and willing to assist you as well.
    – Gimby
    Commented Aug 16 at 8:47

1 Answer 1

12

On a close read, I think you do indeed have a single, clear, appropriately scoped question underlying all of this. I don't think it should be deleted (unless you're giving up on asking it). After writing most of this post, I also don't think it's a duplicate. (I don't think you're really asking about logging, although that's a reasonable guess reflected by the initial attempt someone else made to answer.)

But it needs to be fixed. It's buried under so much irrelevant discussion that the question creates the impression of asking multiple unrelated additional things.

A well-asked question should almost always fit on your screen without scrolling, unless asking it really does require too much code for that to work. In order to get there:

Get rid of the code

In your case, I don't think any code is necessary, because:

  1. You are asking a "how-to" question, not asking us to explain the behaviour of existing code—therefore, any code that you do show us should be part of what's needed to specify the problem. In other words, a minimal reproducible example is not necessary or appropriate, because there isn't anything to "reproduce".

  2. But describing your problem doesn't require code either, and the code structure that you do show doesn't help with describing the problem. The problem is that you have some main loop for your program that will call into more complex functionality, and you want to make some global change (disabling prints in bulk) in that functionality. The only interesting feature of the omitted code is that there's presumably a lot of it (and, in particular, a lot of places where print is called). It doesn't matter what the main loop looks like, because by your own description, the problem isn't there.

It's not about you

We ruthlessly eliminate "noise" from questions here. That is, we don't want social pleasantries, comments about yourself or your mindset approaching the problem, or anything that isn't necessary to understanding the question. It's all well and good, for example, that you want to avoid running into an XY problem; but it isn't really actually our responsibility here to steer you away from one. This is not a discussion forum, and the purpose of the question is not to make your code the best it can be, or even to solve the apparent problem. The purpose isn't even to help you (which is part of why we expect more than a request for help in questions). The purpose is to help everyone, by creating a question that could meaningfully be asked by others, found by said others by using a search engine, and be answered in a way that is useful to everyone who would ask it.

What's actually relevant?

It should be obvious that using PyCharm doesn't matter. Why? Because you aren't asking about the process of using an editor to write the code; you're asking about what the code should contain. You can make the code contain anything you want, with any editor you want. Programs like PyCharm don't control how the code works. Python is Python.

Furthermore, it doesn't matter that you want to add machine learning to the project. (Also, please stop worrying about this now! Make the existing code work to your satisfaction first. It's vital to have a solid understanding of the fundamentals of programming, before you try to use anything more sophisticated.) Why? Because you would have the same problem regardless: the prints are already in your code. Yes, putting two machine learning bots against each other would allow for the games to be much faster (the program would never be waiting for an input). But that's just forcing you to realize a problem that's already there. Further, you already apparently have "AI" in the program, since there's a decide_computers_move function. You could equally well make that algorithm compete against itself.

Finally, it doesn't matter how long print takes, and that will also depend a lot on the environment (but if it concerns you, then you could look up how to time things—see: How do I get time of a Python program's execution? ; How do I measure elapsed time in Python? ; How can I time a code segment for testing performance with Pythons timeit? —and find out by trying it). "I want to control how much text appears in the terminal, and which text" is already sufficient justification.

Is there actually a question?

In the existing code, when you call decide_computers_move, does it still print detailed information about the gamestate? Or does that function simply use the gamestate that was passed to it to do some calculations?

If it already works without printing, then why should there be any problem with using the same approach to get an answer from the ML bot?

Conclusion

Here's an example what a question of this sort should typically look like:

I'm making a game that includes some complex logic and which supports both human and computer (AI) players. There are a lot of print statements scattered throughout the code, intended to describe the game state to human players. I want to have two computer players play against each other, and not see all those messages.

Suppose I have separate functions that determine a player's next move, for human and AI players, and a main loop that chooses and calls these functions. How can I structure the rest of the code, such that the program only displays messages to human players?

Yes, good how-to questions really are normally that short. The best ones are often even shorter.

Notice that the "I" statements here aren't actually about you—they're about the code and about the desired result. That's important.

What will happen at this point, most likely, is that people will ask for a bit more detail, to make sure they understand the question—maybe because they think you do have an XY problem and want to get that out of the way in the comments. (They're trying to be helpful, but again it's not relevant to the purpose of the site.) Or maybe they think the question is trivial ("... just don't write print inside the function that gets moves for the computer players? What's the problem?") and you can re-think whether there actually is a question, and if so, how to make that fact clear.

You must log in to answer this question.

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