I know we have the control-K indent-by-4 operation. Unfortunately that doesn't do anything about the often horrible indentation within the querant's code.

How Hard Would It Be to add a minimal "indent by delimiter nesting" operation to SO? Just doing dumb counting of { and } characters -- with minor additional code for quotes -- would handle the basics for languages which share that notation. Making it count all the paired delimiters -- even if it didn't actually distinguish among them! -- would handle many of the edge cases and some other languages.

Not perfect, but it would help querants help us help them. And it's surprising how often simply fixing indentation exposes a code problem.

  • 7
    "It's surprising how often simply fixing indentation exposes a code problem." -- which is exactly why we sometimes shouldn't fix formatting, whether by automatic or manual means. If bad formatting is the root cause hiding an error, then fixing the formatting should be done as part of an answer... then it should be closed using the "it's a typo" OT reason. – Charles Feb 10 '14 at 1:43
  • Now, a neat trick would be to automatically fix Python indentation issues (thank you for teaching me a new word, today, btw). – Michael Petrotta Feb 10 '14 at 1:46
  • 1
    Disagree with @Charles. If we can make the error obvious, it saves respondants' time. If we can make it so obvious that the poster sees it, it saves EVERYONE'S time. I'm less concerned about scoring answer points than about spending our resources on things worth spending them on. – keshlam Feb 10 '14 at 1:46
  • 1
    I will only support this if the indent style is 1TBS with 3 space indents. Otherwise it is heresy and should be consigned to the hell of people who force other code styles upon me. Elses have ears 4ever! – user213963 Feb 10 '14 at 2:12
  • I'm surprised -- and a bit disappointed -- by the response. But it's your system, your decision. On the other hand, if this is how you do or don't value fixing code indentation, I'm less motivated to assist with that. – keshlam Feb 10 '14 at 3:29
  • This question has been alive for two hours. On a Sunday night, during the Olympics, and when most of Europe is sleeping. You might want to give it some more time (and more than one answer) before moaning that the community has decided. – Aaron Bertrand Feb 10 '14 at 3:45
  • The strength of the reactions suggests that more data is unlikely to change the result. If you honestly believe otherwise, I'll give it more time... but if people dislike the idea enough to downvote it, rather than to simply disagree, I really don't see much point in doing so. – keshlam Feb 10 '14 at 3:50
  • @keshlam well, for one, down-voting is how you officially and demonstratively disagree with a feature request. Optionally, you can comment and explain further why you disagree. That said, my comment missed Random's update of the status - still, you shouldn't update your question to complain about the response to it or make the title reflect that it has been rejected. – Aaron Bertrand Feb 10 '14 at 3:53
  • Wasn't so much complaining as trimming out the rationalle, but... OK, granted, I shouldn't edit while still reacting. BTW. the hover text for downvote does not convey that it's simply a disagreement; if that's how it's being used in meta, meta might want to change that text to clarify, and/or reconsider whether disagreement with a proposal should really cost the proposer points. Not that I'm worried about the numbers, but there's a(n unintended?) subtext there which isn't exactly encouraging. – keshlam Feb 10 '14 at 3:56
  • @keshlam Agreed. I do not understand how people's disagreements should affect reputation. Not only is the text misleading, this behavior creates huge potential for pile-on voting. A not-so-good question get's voted up, then everyone passing by looks at it and blindly votes up after minimal reading. Why? Because the proposal looks creditable, see? It already has 1 vote! Same thing for downvotes. – bjb568 Feb 10 '14 at 4:14
  • No, no, no. Please read. – Aaron Bertrand Feb 10 '14 at 12:05
  • @AaronBertrand OK, the consensus there is that the tooltip is wrong here on Meta. That's what I just observed. What's "no" about it? – keshlam Feb 10 '14 at 13:22
  • @keshlam that the change has been declined. Repeatedly. – Aaron Bertrand Feb 10 '14 at 13:32
  • Fine. If you're OK with relative newcomers rediscovering this and grumbling about it, and if you're OK with the fact that it makes suggestions seem unwelcome unless we're already certain they'll be popular, that's your call. – keshlam Feb 10 '14 at 13:41
  • @keshlam whether I'm okay with it or not is not the issue at all. You're off on a tangent suggesting that the tooltip on meta should be changed, and I'm telling you that it won't, because it's been argued several times in the past, with the same result every time. I'm actually trying to help you, a relative newcomer to meta, not spend too much time spinning wheels about changes that have proven to not be desired by the site owners (sometimes in spite of their community popularity). – Aaron Bertrand Feb 10 '14 at 13:50

All kinds of editors (and add-ins for popular editors) support code formatting of various kinds, so for the most part users already have the ability to solve this problem on their own.

Why duplicate that functionality so that people can have code formatted them in a way they don't like, which still doesn't guarantee it will help them spot the problem, or even the only problem (Cutsomer_ID is spelled wrong, whether the formatting hides other errors too).

People get mad when others edit their code to be readable, to remove horizontal scrollbars, etc.; imagine the onslaught of vicious complaints here when the system starts doing it automatically.

On top of that, given the effort it would take to implement a formatter that handled all the languages SO supports, and not massively screw over a single piece of code, what percentage of questions do you think would never have to be answered just because the site reformatted them as they were submitted? As I said above, fixing the formatting doesn't guarantee the OP will be any better equipped to solve the problem.

This happened just today and, while I made a comment about it, I'm not convinced that proper indenting would have made the problem obvious to the OP, nor am I confident that SO would want to spend time developing a code formatter that would undeniably make the problem obvious (and, once again, so obvious that the OP gets it). I think that indentation makes the problem more obvious to us, but not necessarily to the OPs of the world.

  • 1
    Have you noticed just how many questions over the past few weeks have immediately drawn the comment "fix your indentation, then we'll look at it"? I submit that this is wasted time for everyone. Users having the tools, and users understanding why they should use the tools, are different things. I'm not suggesting a boil-the-ocean solution. I'm suggesting that a minimum "better than nothing" effort would be worth far more than the effort needed to develop it. – keshlam Feb 10 '14 at 2:00
  • 1
    @keshlam Just because some people respond to questions that way does not mean it's the system's job to fix it. Do you know how many questions I've edited for readability without any such complaint? – Aaron Bertrand Feb 10 '14 at 2:02
  • Wouldn't you rather have been able to do so with two clicks and a keystroke? If folks really don't think the tool would be useful, that's fine; we agree that we disagree. If it's just "we've gotten by without it", I honor those who've been doing the work but I think it's worth taking some of that load off their shoulders, if it can be done cheaply (and I believe it can). Please note that this is not a bug report, but a feature suggestion. – keshlam Feb 10 '14 at 2:05
  • @keshlam you may think it would be cheap because you're probably thinking about a very small subset of the languages that SO supports. I have been working with SQL Server for 17 years and I can assure you that writing a code formatter that supports all the possible syntax involved with Transact-SQL would not be cheap, easy, or fast. – Aaron Bertrand Feb 10 '14 at 2:12
  • 1
    Please, reread exactly what I'm proposing. The fact that we can't boil the ocean does not invalidate the value of a cup of tea. The perfect is the enemy of the good enough. – keshlam Feb 10 '14 at 3:24
  • Answer accepted, since it's clear that the idea is DOA and there's no point in further discussion. – keshlam Feb 10 '14 at 3:45
  • @keshlam please see my comment above, in response to your (premature, IMHO) edit. – Aaron Bertrand Feb 10 '14 at 3:49
  • OK, we can take it back to comments on the question rather than on this answer. – keshlam Feb 10 '14 at 3:52
  • BTW, I also wasn't proposing "automatically". I was proposing it as an editor command, akin to existing control-K. – keshlam Feb 10 '14 at 4:17
  • @keshlam if it's not automatic, how does an unknowing newbie not realizing his error is one of simple syntax know that this new button will fix his code formatting and magically make the error obvious? – Aaron Bertrand Feb 10 '14 at 12:04
  • The same way he knows that control-K exists. Someone suggests it, and he learns. And again, I'm less focused on the magic (though it does sometimes happen) than on the fact that we are wasting our time doing this for them, or are not answering questions because they don't know how to help us. This isn't a miracle, nor is it hard to implement, it's just a simple improvement to the site's tooling. Heck, it could probably be done as a greasemonkey script, but I presumed SO wanted to stay browser-agnostic. – keshlam Feb 10 '14 at 13:18

You must log in to answer this question.

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