Ahhh! My eyes! Seriously, looking at some posts like this one and this (see revision history) can make you go blind.

Can we please have some sort of a code formatting tool like JSLint or something? It will:-

  • Be a boon for our eyes;
  • Result in more answers (no one would bother reading through that big pile of junk; if it was formatted properly though, I might still have tried..._);
  • Save more kittens! Save the kitten!

Of course, it should be made optional. Maybe an icon in the 'action bar' above the post editing dialog. The tool to use could be determined from a language tag (if there is one), or could use Prettify's inference tools.

Remember, it's all for the kittens!

  • 3
    Three minutes after you posted this, someone fixed the first question you linked. Second one looks OK too, after Will's edit.
    – user102937
    Sep 25, 2012 at 15:06
  • 7
    I think the community does an ok job already of fixing poorly formatted posts. Surely you don't expect that OPs will suddenly bother to take care in formatting just because you add an extra toolbar button? They already can't find the {} button. This is the way they write their code and they're unlikely to know enough that it doesn't look good to us. If they do know (and care), they have access to tools outside of this site that could help them.
    – Aaron Bertrand Staff
    Sep 25, 2012 at 15:18
  • @RobertHarvey I guess I got pwned... Sep 25, 2012 at 16:14
  • @AaronBertrand Maybe for editors? Sep 25, 2012 at 16:15
  • I guess if anyone wanted to do that, they could do it theirselves... Sep 25, 2012 at 16:15

1 Answer 1

  • OMG we must save the kittens!
  • What to do, what to do???
  • I know! Edit!
  • Oh, don't bother, already taken care of...

On a (perhaps) more serious note:

The time you spend writing this Meta question was more than enough to edit and fix both questions (and perhaps a couple more). And even post polite comments asking the OPs to be a bit more careful with formatting their code in the future, perhaps with a useful link to the revision history, showing them the edits you've made (showing is always easier than telling).

I don't see any reason for automation here. Messy code is (probably) a sign of a new(ish) developer, and if that's the case you want to help her understand why her code being messy is a bad thing, not give her a quick fix.

  • Umm... if that's what the SO community think, okay. Sep 25, 2012 at 16:13
  • BTW, what's the fastest way to automatically format some code? Sep 25, 2012 at 16:13
  • @YatharthROCK That's what I think, and three people (so far) seem to agree with me. Your question is still very new, I don't think it's clear (yet) what the community thinks.
    – yannis
    Sep 25, 2012 at 16:16
  • @YatharthROCK: If it's JavaScript, I copy the code into jsfiddle.net and click the "tidy" button (and then copy it back into the post).
    – Matt
    Sep 25, 2012 at 17:07
  • @Matt Oh yeah, forgot about it. Amazing tool, much needed upgrade from pastebins. Sep 25, 2012 at 17:10
  • I like Python though, it enforces indenting and other whitespace nightmares go away. The only bad part is mixing tabs and spaces, but then there's TabNanny... Sep 25, 2012 at 17:13
  • @YatharthROCK I've set up my IDE to format my code automatically before every commit. Don't know how easy this is for every platform, but it works flawlessly for my team...
    – yannis
    Sep 25, 2012 at 17:19
  • 1
    @YatharthROCK Python? That explains why your examples weren't that terrible, you're spoiled ;) How about you try some Perl? Here's some valid Perl code to get you started: @P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{ @p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord ($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&& close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
    – yannis
    Sep 25, 2012 at 17:22
  • @YannisRizos Oh God... why do people use Perl anyway? Sep 25, 2012 at 17:31
  • @YatharthROCK Because 1) it's a useful language, 2) is a beautiful language, 3) it's a language that doesn't enforces much, and encourages creativity (imho), and 4) it takes seconds to format it properly and have absolutely readable code, if you haven't written to be readable in the first place. Also the example was more of a joke, it's obfuscated on purpose.
    – yannis
    Sep 25, 2012 at 17:33
  • @YannisRizos Thank God! I need some advice. What should I learn/try next? Ruby or Perl or Java (don't puke, the only incentive I have to learn it is b'coz Android is implemented in it <groan> and I need to fix the crappy folder editing situation) Sep 25, 2012 at 17:36
  • @YatharthROCK On Programmers we've declared language choice questions off topic, because they are truly unanswerable. Perl is in a weird place right now, with Perl 6 coming out (soonish?) and being a very different beast than Perl 5 (there was a concious decision to not care for backwards compatibility), so it's probably best to avoid or you might need to re-learn a few things when 6 finally comes out. Between Ruby and Java, I've only used Java because I had to (work), and it's not really a language I enjoyed. But it did what I needed it to do, and that was good enough.
    – yannis
    Sep 25, 2012 at 17:45
  • @YatharthROCK If you are interested in picking up a new language, there's an excellent book you might find useful: Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages. Ruby is one of the languages, the others are not that popular (well they are, but not in the same circles as is Ruby).
    – yannis
    Sep 25, 2012 at 17:47
  • @YannisRizos I see. Thanks for the link :) Can you link me to a free PDF (the bad part of being 13 and living in Kuwait is that you don't get a credit card and Amazon's extra shipping charges aren't exactly cheap) Cirle me on Google+, BTW Sep 25, 2012 at 18:06
  • @YatharthROCK Well linking you to a free PDF of a non free book wouldn't be legal/ethical/nice. There's a big list of freely available books right here on SO though, and quite a few of them are about learning a new language. And I don't really use Google+, but you can find me on Twitter (my account is in my profile).
    – yannis
    Sep 25, 2012 at 18:09

You must log in to answer this question.

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