3

I recently had my question closed, and subsequently deleted. The close reason is:

This question needs details or clarity.

How can I make it more clear that I want to find list comprehensions in some code I have? I mean, I'm sure some people did understand it since I got an answer from it that solves my problem. Also, in the comments people seem to have understood what I need.

I'd love to improve the question and help others understand it as well, so could you help me do it?


For those with <10k reputation, the contents of my question is as follows:

I am trying to refactor some Python modules which contain complex list comprehensions within their code. An example of a not so complex list-comprehension is:

some_list = [y(x) for x in items if x != 2]

To find the list comprehensions, I am using PyCharm's search functionality with the following regex pattern:

\[.+ for .+ in .+\]

This however matches simple lists as well, which I don't care about.

Is there a better way to find list comprehensions?

If it's done by regex or another way, I don't mind.


15
  • 3
    Some people evidently understood the general direction you were going in, but probably you weren't specific enough about the requirements - a lot of the comments are asking you to clarify what should happen in certain scenarios, as far as I can see. As a programmer, hopefully you understand from experience that coding against ambiguous and/or incomplete requirements can be quite difficult. P.S. A lot of people will not be able to see your link since the question has been deleted, only those with sufficient privileges can access it.
    – ADyson
    Aug 25, 2022 at 14:28
  • 5
    "Also, in the comments people seem to have understood what I need." You have also received more than one comment stating that the requirements in the question were vague. Questions should be self contained and sufficient, and from that alone, it was not clear which cases you wanted to match and which ones had to be excluded. It seems that the answerers had to work on hunches and anecdotal examples spread behind regex101 links and comments.
    – E_net4
    Aug 25, 2022 at 14:28
  • 7
    The question you ask, "Is there a better way?", is somewhat opinionated as well. Better than what? What defines "better"? More succinct code? More Performant? Easier for someone with no knowledge of the language to understand? Something else? It's not really an answerable question.
    – Thom A
    Aug 25, 2022 at 14:30
  • 5
    P.S. "The moderators" didn't write "This question requires details or clarity" as such. That's automatic text generated when sufficient numbers of people vote to close your question because it's unclear. It's one of the official closure reasons, not a custom thing for your specific case. More details here: meta.stackoverflow.com/questions/417476/…
    – ADyson
    Aug 25, 2022 at 14:31
  • 6
    On another side note, it also wasn't really moderators who closed the question. It was closed by three regular users with the moderation privilege of voting to close questions. What we call moderators are elected/appointed and have a diamond next to their display name.
    – E_net4
    Aug 25, 2022 at 14:33
  • Part of the issue is that you used the regex tag which is notorious for having downvote- and delete vote-heavy power users that frequent that tag, unfortunately. That being said, your question was opinion-based, so was rightly closed. Instead of asking for something "better", ask for what you really want. What is it that makes another solution better, specifically?
    – TylerH
    Aug 25, 2022 at 14:34
  • @TylerH Regarding this particular Meta question, that is a distraction more than anything. The question would not have been deleted if it were not closed as needing details. And the fact that it lacks information is a reason to downvote.
    – E_net4
    Aug 25, 2022 at 14:38
  • @E_net4thecommentflagger Yes, it would not be deleted if it were not closed, but deletion also prevents the user from getting the question reopened after it was edited, too, by passing users or by the reopen queue. You need to rely on people looking at it via the 10k moderators tool which is probably a total of less than 100 users site-wide. As it happens this is why in SOCVR for example we emphasis del-pls requests are for stuff that needs to be deleted now because it's that bad, not just because it's "currently off-topic".
    – TylerH
    Aug 25, 2022 at 14:40
  • Fair. In this case it makes sense to undelete the question. Should only need one more vote I think. (although it is a bit of a double-edged sword in this case, since we'd be making it open to votes)
    – E_net4
    Aug 25, 2022 at 14:42
  • "Should only need one more vote I think." Done. I've left the a"being discussed" comment; hopefully it'll deter delete voters (especially if anyones wants to upvote said comment for the time being, just so it's not hidden initially).
    – Thom A
    Aug 25, 2022 at 14:43
  • 1
    Thank you all for the feedback. I'll try fix it later in the day when I get some free time. Aug 26, 2022 at 6:12
  • 1
    ALWAYS edit the question and NEVER post a new one. If you post a new one you are vulnerable to downvotes for deleting a question and or for posting a duplicate question. I tried posting a new one and ended up with 4 downvotes in the process. Feb 1 at 15:00
  • @skinnedKnuckles thank you for the tip. I ll make sure to avoid that mistake. Feb 2 at 7:25
  • I suspect the q-ban algorithm has a good memory because some of the downvoted questions (which were deleted) that likely contributied to my q-ban are from 9 years back. Although to be fair I haven't added many questions since then. Feb 3 at 19:30
  • @skinnedknuckles Perhaps the algo needs a change then. 9 years is an eternity for developers, it shouldn't care at all for so old content. Feb 7 at 8:56

1 Answer 1

3

In a regular question where you want code to do something, a lot of information can be inferred from the situation. For example, if you provide Python code then we can infer you have a Python interpreter and need a Python solution. The code is the canvas and the tool and the language etc. for the solution.

In a "meta" question where you want to do something with code, suddenly a lot of information is not defined by the code itself. For example, just because you show Python code does not mean you can use Python code to work with it.1 The code is merely the object of the task and it says nothing about the rest.

A "meta" question must explicitly provide all the information that can be inferred in a regular question.


Practically, let us look at some missing pieces of information for your question.

What tool are you working with?
Refactoring is commonly done in an IDE, but many people use beefed-up editors such as NotePad++, and there are veritable use-cases for having refactoring scripts/programs. Even for just Regex there are different engines with their own capabilities and limitations.
All of these will allow – or prevent – wildly different approaches.

What cases do you need to cover?
The comprehension syntax is a much more complex and less standard thing than the usual runtime objects and values. For example, one can often infer whether "integer" is just a stand-in for "any number", yet for syntax... Do you need just list or also set, dict and generator displays as well? Do you need nesting? Do you expect comments? Newlines? Is the syntax actually always valid to begin with?
Define the requirements as closely as possible.2 If you need to rely on examples, provide multiple examples including pathological cases.

What is the goal of the task?
So you want to "refactor some Python modules which contain complex list comprehensions" – but why does that involve matching the comprehensions? For example, reformatting line breaks at comprehensions needs much less code understanding than refactoring comprehensions into loop statements. For many tasks there are quick and simple solutions if we just need to solve specific cases.
It can be a good idea to tie this to the example cases: Alongside each input case provide an example or description of the output or information desired.


1Anecdotally, while I have lots of reputation in the Python tag many of my day-to-day problems actually use the Puppet language to assemble such code.

2That also means using the appropriate technical terms. It is probably a good idea to look at how the language is defined.

1
  • 4
    "What tool are you working with?" that is my mistake while editing the question. OP had actually mentioned they were using PyCharm (I wanted to entirely remove mention of regex but left it there since an answer is referring to it) Aug 26, 2022 at 8:31

You must log in to answer this question.

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