# What's the best way to change how my code looks?

A long time ago the question avoiding Python multiline string indentation was asked. The question was well received with a score of 66 and 16 favourites. It was even answered by one of our previous mods (who deleted their answer).

However yesterday it popped up in the close queue where five out of five users voted to close the question. Later that day it was added to the reopen queue, one user selected to keep it closed, where a moderator mod-hammered it open, with an edit. This edit was noticed by Duga, and posted to chat. Where I noticed the question, agreed with the closure and voted to close it as broken, which started another review in the close queue. This lead to a user voting to close the question, and a different moderator mod-hammering to leave the question open.

It has also been reviewed in the past where all (3) reviewers in the queue elected to leave it open.

And has been reviewed again where 2 voted to close and 3 voted to leave it open.

• 1 Vote to keep closed
• 1 Vote to reopen
• 7 Votes to leave open

And so the votes so far have been:

• 9 People have voted in favour for the question to be closed.
• 7 People have counter-voted those close-votes to reopen or leave open the question.

To note the close reasons have changed since the question was originally posted. Here describes most of the story of the close reasons. Where, if you have 10k rep, you can also see all the changes to the close reasons here. And so we can see that when the question was posted it was when we had our previous close reasons:

1. Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it.
2. Questions must involve real code that you own or maintain. Pseudocode, hypothetical code, or stub code should be replaced by a concrete implementation. Questions seeking an explanation of someone else's code are also of-topic.
3. Questions must include the code to be reviewed. Links to code hosted on third-party sites are permissible, but the most relevant excerpts must be embedded in the question itself.

Where the broken code reason hasn't changed much:

Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review.

It seems like a lot of users think this question should be closed. However moderators have been mod-hammering it open.

Is the question on-topic or off-topic?

• It says: but this give different results so this means to me it does not work as expected. – Billal Begueradj May 24 '18 at 18:26
• @BillalBEGUERADJ - their attempt to rewrite the original code has broken results, not the actual code they want reviewed. You have to take the but this give different results in context.... – rolfl May 24 '18 at 19:03
• I've retitled the question, which should help make the question not about generic practices. – 200_success Jun 1 '18 at 20:06
• @Peilonrayz - can you explain why you rolled back the edits I put in that added additional data points about the question? codereview.meta.stackexchange.com/posts/8852/revisions – rolfl Jun 5 '18 at 20:57
• @rolfl I don't see how views and votes on questions and answers (popularity) has anything to do with something being on or off-topic. – Peilonrayz Jun 5 '18 at 20:59
• Peilonreyz, that may be your opinion, but clearly it is not representative of the expectation of voting: Why Vote. You are clearly happy to ignore the opinion of 70 people who voted because "it signals to the rest of the community that a post is interesting, well-researched, and useful". Are you suggesting that people upvote questions they feel are off-topic? – rolfl Jun 5 '18 at 21:19
• @rolfl People answer and upvote answers to off-topic questions. We also get a lot of people that don't know the rules of CR that upvote posts. – Peilonrayz Jun 6 '18 at 8:07
• @rolfl there are many clearly off-topic questions (e.g. without code or with broken one) that have been upvoted so this isn't a very reliable criteria. Especially that many users don't really know what on/off-topic is. – t3chb0t Jun 6 '18 at 8:07
• @t3chb0t it is very easy to look at the people who voted to close the post. Everyone of the 17,000 people over the past 4 years who had enough privileges viewed the post and thought: "Huh, that's off-topic" has been represented in the "9 votes to close and 1 vote to keep closed".... but, there is no representation in the statistics above for all those people who viewed the post and thought: "Huh, decent question". There is no measure of how many people who could have voted to close the post, but did not because they thought it was on topic, but only exactly 10 people have voted to close. – rolfl Jun 6 '18 at 11:14
• THe number of people who voted to reopen, or leave open, is not a comprehensive count of the number of people who thought it is on-topic, By definition, it can never, ever be larger than the number of people who voted to close. It's not possible. By definition a reopen or leave-open vote can only counteract a close or leave closed vote.... – rolfl Jun 6 '18 at 11:17
• @rolfl I cannot accept this argument because most people don't care about votings. On Stack Overflow there are countless people who constantly complain about closed questions (even locked questions - before they got locked) because they don't understand the reasons. Many of them are really interesting but their rules are being implemented more stricktly then CR's and even questions with many hundred votes more then this one get closed/locked. – t3chb0t Jun 6 '18 at 11:20
• you can't see how many people would vote to leave something open as on-topic because a user can only vote to leave open in a close vote queue or a reopen queue, where it takes 3 reopen/leave open votes versus 5 close votes. The Stats are always going to weigh heavily towards close votes, no matter how the Community feels. I cannot vote to leave open/reopen until someone has voted to close. – Malachi Jun 6 '18 at 13:46
• @Malachi You can always ask on Meta, and find the people that vote both ways. If you left it close, rather than hammering it open, we'd also be able to see more people that want it open. – Peilonrayz Jun 6 '18 at 13:48
• This is a circular argument, @Peilonrayz. the post has been voted open twice now, without moderator intervention, the community has responded with the evidence you require. – Malachi Jun 6 '18 at 13:51
• @Malachi What's circular about it? Use votes to close, open, leave closed and leave open. Where if that's not good enough go to Meta. Don't assume what people thought when they went on or upvoted a question. – Peilonrayz Jun 6 '18 at 13:54

• Is code included in my question?

Yes.

• Am I an author or maintainer of the code?

They probably are.

• Do I want the code to be good code?

Yes.

• Is it actual code from a project rather than pseudo-code or hypothetical code?

This is missing the stub code reason, and the code does look quite stubby to me:

def usage():

print(...)

• Do I want feedback about any or all facets of the code?

No they just want the string indented. They don't want a code review as they are asking a specific question, with the code to just answer that question.

• To the best of my knowledge, does the code work as intended?

I think we can all agree the second snippet doesn't work as intended, "this give different results".

Since print is printing a string literal, it shouldn't matter where the literal comes from. And so if we move the literal out of the function both code blocks are the same.

def usage(data):
print(data)

From this we can now test if the code works in the use cases provided. Which it doesn't. With the second string literal it doesn't work. And so it only passes one of the test cases.

Worst case the code doesn't work as intended. This can be shown by performing the same unit tests on the accepted answer. Which shows both unittests working.

def usage(data):
print(textwrap.dedent(data))

If you think string literals are code, then only the string literals matter. This means the question comes down to just the following. Which is a best practices in general question. Even without removing the unneeded code, the question is still a best practices in general question.

I want to make this code:

V = """
Usage examples:

Test deployment:
$fab [noinput] test deploy Staging deployment:$ fab [noinput] staging deploy

Production deployment:
$fab [noinput] production deploy """ to look more like this: V = """ Usage examples: Test deployment:$ fab [noinput] test deploy
Staging deployment:
$fab [noinput] staging deploy Production deployment:$ fab [noinput] production deploy
"""

but this give different results. What is the best way of writing this?

And so:

• They don't want feedback about any or all facets of the code.

They are asking how to de-indent indented multi-line string literals.

• The code doesn't work as intended.

The code doesn't work with all intended input, as it fails some of the provided unit tests.

• The question is a generic question.

And so for these reasons it's off-topic according to the help center.

• 1) The fact that they don't want feedback about any facets of the code rarely stops us from answering it anyway. If a question asks "How can I improve the performance of this code?" we don't close it for that reason. 2) The second part of the code is only an example of how the author wants to make the code print the same thing in a cleaner way. 3) Disagree, this question is about his current code (the first code block) that he currently things can look better. – Simon Forsberg May 31 '18 at 18:16
• 1) that is not the same as asking how to do only one thing with an MVCE. 2) So the code doesn't work as they intend? 3) What do you disagree with? And why isn't it example/hypo/stub? – Peilonrayz May 31 '18 at 18:24
• 2) The first half of the code works exactly as they want to. They just want to write the code differently but still do the same thing. 3) It's contains a complete method, with a reasonable name - usage - what this method does is totally reasonable to me. It does not contain any identifiers that indicates it's hypothetical - like doSomething() or foo(), it also does not contain any ... indicators. Just because it's only one method doesn't make it example code. I'm quite confident that's the exact code from some git commit in a real project. – Simon Forsberg May 31 '18 at 18:31
• For the record, this is one of those questions that I think can fit on both Code Review and Stack Overflow – Simon Forsberg May 31 '18 at 18:31
• @SimonForsberg 3) I guess I can agree with that reasoning, and looking at meta I'm wrong to think it's off-topic for being short. 2) I read the question to be "I have this, how can I make it like this". And so is asking for a feature request. But I guess we won't see eye to eye on this because they said 'look like' rather than just 'like'. – Peilonrayz May 31 '18 at 18:54

This question has nothing to do with improving anyhting. OP is clearly asking for a concrete solution and thus it should be closed. Only because a couple of people voted for it, doesn't mean it's ok to ask such questions.

I like the way Stack Overflow deals with similar situations by closing them and adding the Historical significance banner:

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. More info: FAQ.

• Is this question significant though? – Mast May 24 '18 at 17:02
• @Mast with 60+ votes and 17k views I'd say yes. – t3chb0t May 24 '18 at 17:04
• That makes it popular, not significant. – Mast May 24 '18 at 17:05
• Only because a couple of people voted for it, doesn't mean it's ok to ask such questions. - I absolutely disagree. This question has been in the close queue for a few times and has ended up as open. That means that it is okay to answer the question. – Simon Forsberg May 24 '18 at 19:07
• Either way 17k views would indicate outside traffic headed in, but I think that information is in mod tools. If that's the case, then it would have significance. – Raystafarian May 25 '18 at 4:46
• @SimonForsberg it ended up open because diamonds are either reopening it or vetoing the votings. The community seems to think differently. – t3chb0t May 26 '18 at 17:56
• @t3chb0t, there was a Close Vote review on this question --> codereview.stackexchange.com/review/close/75570 where the question was not closed, all 3 reviewers voted to leave it open – Malachi May 28 '18 at 14:28
• @Malachi this is not the entire truth. See here where the outcome was quite different: codereview.stackexchange.com/review/close/97015 – t3chb0t May 29 '18 at 14:52
• @Malachi I thought hammers were for places where things were black or white. Why use it where it is so grey we can't even get a consensus on Meta? Moderators are there to enforce the rules, not enforce what they think should be the rules. – Peilonrayz May 31 '18 at 8:49
• @Peilonrayz, Moderators are there to enforce the rules, not enforce what they think should be the rules. The Question was posted, went through a first post review, was upvoted over and over again for about 3 years, was flagged as off-topic, went into the review queue and unanimously voted to be left open. I think that this says what the community wants. The code works, but the formatting is not ideal, is there a better way to format the code? that is on-topic and has been on-topic for as long as I can recall. The moderators are enforcing the rules. – Malachi May 31 '18 at 16:09
• @Malachi I like how you completely ignored that there were opposing votes. There have been 8 for closure, 5 for open. You're also taking your opinion as fact, and casting others aside. – Peilonrayz May 31 '18 at 16:22
• I feel like the argument is whether or not making the code more readable is on-topic, I found that there is a precedence for White Space and Tabs, I will edit my answer to include this precedence. – Malachi May 31 '18 at 16:28
• @Malachi no, it is not. The question is about whether it's on-topic to ask about what do I have to do in order to format my code/string like that? [here the example] - which is a feature/code request and not asking for general feedback/improvement. – t3chb0t May 31 '18 at 16:31
• @t3chb0t and @Peilonrayz, the original wording (which is still there) is to look more like this the key words are more like which means they don't want this specifically, but something more like this. this looks like a very common CR question, how can I make my code more readable? or how do I make my code cleaner? – Malachi May 31 '18 at 16:47
• @Malachi take "I want to make a = b * c more like a = b c but this give different result." This doesn't ask for increased readability, or how to make the code cleaner. It asks how to multiply b and c without using *. The is the same as the question we're discussing. – Peilonrayz May 31 '18 at 17:28

In my opinion, the question is clearly on-topic:

• the code is included in the question
• it is the author's code
• it is actual code from a project
• the code works
• the author wants it to be good code
• they want a review on any/all facets.

The only issue that can been be misinterpreted on this question is whether the author's (failed) attempt at a refactor is the code they want reviewed, or whether it is just to provide context.

In my opinion, they want their working code reviewed (the first block of code), and their broken code is just an example of what they have tried so far, to make the code more readable. Since their refactor attempt is just for context, and not for review, it should not count towards the on-topic debate at all.

It all boils down to what code they author wants reviewed, and what code is just there for context. It is, in my mind, clear, that the author says:

I want to make this code: (insert REAL code here) to look more like this: (insert EXAMPLE code here) but this give different results. What is the best way of writing this?

In other words, the second code block is not there to be reviewed at all (whether it works, or not).

In an attempt to make it clear that the second code block is only there to provide context, I added the block-quote markdown to it, to visually identify it as not there for review. I did this when editing it in the reopen review queue.

• Yes the code works, but does it work as the OP intends? Reading just the text "I want to make this code to look more like this but this give different results. What is the best way of writing this?" It says both versions of the code don't work the way they want. – Peilonrayz May 24 '18 at 17:51
• @Peilonrayz - yes, it does work as he intends, it produces the right results.... it just does not have good readability (since the indentation looks wrong). – rolfl May 24 '18 at 18:05
• They want the code (input) to be indented as it is in the example, and they want it to output the same as the first code. Neither code works as they want. – Peilonrayz May 24 '18 at 18:09
• @Peilonrayz The original code works as they want, it just doesn't look as pretty as they want (in the code editor) – Simon Forsberg May 24 '18 at 18:13
• @Peilonrayz - you say: "They want the code (input) to be indented as it is in the example, and they want it to output the same as the first code. Neither code works as they want" ... but, that does not reflect the actual use-case. The user says their first code looks ugly but works, their second code looks pretty, but does not work. Please help me make my code work and look pretty. You say "Neither code works as they want"... that's not true, the first code does work as they want, it's just not pretty. This is the definition of why we have code review.... almost. – rolfl May 24 '18 at 18:50
• Debate (re:semantics) on this answer should be addressed codereview.meta.stackexchange.com/q/8796/75587 - where, conveniently, @rolfl has the top answer. – Raystafarian May 25 '18 at 4:45
• I would also contest the "they want a review on any/all facets" part. Nowhere in the question does it become apparant that they want anything besides their code looking closer to the second example. – Graipher May 27 '18 at 19:00
• @Graipher that really never stopped us here. We're explicitly saying that we'll outright ignore the concerns of the reviewee, if reviewer consider that justified – Vogel612 May 28 '18 at 14:41
• @Vogel612 While that may be so I think it is still wrong to state that they want that in this case. – Graipher May 28 '18 at 14:54
• I understand that you have a different view. However hammering things should happen when you are certain that it's off/on topic. Why hammer something we can't even on Meta come to a consensus on? – Peilonrayz May 31 '18 at 15:55
• @Peilonrayz - Note, when I hammered it, I had no idea there was controversy... regardless, is it not better to leave questions open when there's doubt, instead of closing them? Note the question is one of the top 25 on the site: codereview.stackexchange.com/search?q=is%3Aq+score%3A66.. how sure are you that it is worth closing? – rolfl May 31 '18 at 16:08
• @rolfl The question was closed, and so it should be clear that people have opposing views to you. What harm does closing it have? Excluding your edit, the last update was back in '16. Why should popularity of a question make it on or off-topic? Even if the question is closed it'd stay around. – Peilonrayz May 31 '18 at 16:17
• @rolf abuse of mod hammers was part of the question. "It seems like a lot of users think this question should be closed. However moderators have been mod-hammering it open." I'm confused why you're allowed to hammer something whilst ignoring the opinion of others. – Peilonrayz May 31 '18 at 17:36
• @Peilonrayz - this meta discussion is where the diplomacy comes in. Even putting my personal opinions aside, the voting on this meta question reassures me that my actions are justified. I am sorry you feel I have been "shutting down diplomacy" - but when you think about it more deeply, I have done no such thing. In fact, I have directly invited people to view this discussion as much as possible, including posting a comment on the original question to invite people to discuss things. And again, the community has decided to open, or leave open the question more than it has decided to close it. – rolfl May 31 '18 at 18:10
• You reopened the question instantly, without even giving it a chance to be voted upon... where the first vote was to leave it closed. You are saying someone voted to reopen it and it was the reason for you to do this by completely ignoring the vote for leaving it closed. Your link speaks against your premature decision. – t3chb0t Jun 1 '18 at 10:56

### This is how I read the question

And why I think it is on-topic.

I have this code from a project of mine, that prints the usage to the user:

def usage():

print(
"""
Usage examples:

Test deployment:
$fab [noinput] test deploy Staging deployment:$ fab [noinput] staging deploy

Production deployment:
\$ fab [noinput] production deploy
""")

However, I don't like to read it this way. It would be better if I could write it in a way that makes it easier for the eyes, like with indentation. How can I make this code still print the same thing but make the code easier for the eyes?

• The current code does work.
• It is a complete method from a real project
• They want the code to look better

This is one of those questions that are on-topic on both Code Review and Stack Overflow.

Being the Moderator that gave the "Leave Open Hammer", I would like to say that, I saw that Rolf had already edited and reopened the question, meaning that he felt it should be reopened. And I trust Rolf to close something if it needs closing.

The code that the user provided in the first code block works, and that is the code that they want reviewed, not the code that doesn't work. The user wants the functionality of the first code block with the readability of the broken code block, or better readability than what is in the broken code block.

I looked at the question further to decide if this was indeed stub code, but I don't believe that it is. The code appears to be runnable by itself and as such is not "Pseudocode, hypothetical code, or stub code"

• "The user wants the functionality of the first code block with the readability of the broken code block". You saying the first code block doesn't work the way that the OP intends, and so is off-topic. – Peilonrayz May 24 '18 at 17:54
• no, I did not say the first code block does not work. the first code block does work, but they want the code, not the output, to change in appearance. – Malachi May 24 '18 at 17:55
• I didn't say you said it doesn't work, it doesn't work the way the OP intends. To do that they have to change the codes functionality, so they are asking for code that isn't there. – Peilonrayz May 24 '18 at 17:56
• The code may be functionally different and still give the same output, that is the basis of Code Review. the fact that the code gives output and the OP wants the same output, means that the code works and is reviewable as working code and is not a GIMME TEH CODEZ. They have the functionality that they want, but they want cleaner code. – Malachi May 24 '18 at 17:59
• Yes, they want the same output. But they want to be able to enter different input, hence it changes the functionality of the code. They are asking how to remove white space from the beginning of strings, or another method to indent strings, without adding the indentation to the beginning of the string. – Peilonrayz May 24 '18 at 18:01
• "I think that this code can be written better and more efficiently, and perhaps made easier to read" is a Valid Code review request, would you agree? Is the post in question not asking the same thing? – Malachi May 24 '18 at 20:22