has there ever been a proposal for establishing a formatting style file for programmers? In web programming, we have CSS files that help separate style from 'code', so two people can see the same code while each can see it in his/her preferred way.

I was thinking something like this could theoretically be achieved for programming. How many times have you read code from another programmer with a formatting that you can't stomach? If you change the formatting, you're changing the source file, so whoever comes after you to read the same file could have the same issue against your formatting that you had.

You could say "define coding standards" but this is usually not done in small or individual teams before the company grows.

Why not separate formatting from code? You could define how you like code formatted (brackets here, new line after this, etc) and the IDE would take the source code and auto-format it to your liking (without changing the source code). I guess it wouldn't be a trivial thing, but I'm curious if there are languages or IDEs in which this has been done.

Has something like this been done or attempted ever? Is it doable? Could something like this be incorporated in, say, Visual Studio?

  • I like this idea, but this assumes that you'll always want your code to adhere to a well defined style. You wouldn't have the option to go into "unstyled" mode without explicitly declaring an unstyled block... and then you run into the meta-issue regarding styling of untyled blocks (user A wants them unstyled, while user B wants then styled anyhow).
    – MetaFight
    Commented Feb 4, 2014 at 16:15
  • 1
    Automatic code formatting has been done many times over. (The first large Pascal application I created in the 80s was a Pascal source code prettifyer.) The question is always what your workflow is, why differences exist and who profits from removing them. Commented Feb 4, 2014 at 16:18
  • I seem to remember that with Haskell there was an option to write programs with comments first and code second. And, of course, with Haskell the formatting was important since there were no braces. haskell.org/haskellwiki/Literate_programming#Bird_Style Commented Feb 4, 2014 at 16:25
  • I'm sure it's doable. Most IDEs already let you define formatting rules and can reformat code based on those rules on demand. You could probably write a set of plugins for different IDEs and different languages that can export formatting rules in a common, easy-to-use standard format. Maybe based on CSS, if you like. Eclipse and NetBeans would probably be good platforms to start experimenting with. I don't know if such as thing has been done already, and I honestly don't know how much demand there is, but it could be interesting. I would like to see something like this for syntax highlights. Commented Feb 4, 2014 at 16:29
  • 1
    Take a look at JetBrains MPS.
    – SK-logic
    Commented Feb 4, 2014 at 19:15

2 Answers 2


Yes - but not the way you're thinking.

What has been done for decades now is 'beautifying' code. You supply your code to a program that has a set of configuration options, and it formats your code accordingly.

A VS plugin that reformatted your code when you checked it out would be interesting, but... the huge problem with such things (and a formatting document too) is that your code will be re-formatted when you commit it, which will always create huge diffs so you won't be able to see the "good" changes from the automated bits.

I guess you could automatically reformat all code before it goes in, using a standard style, which would minimise this problem, but probably not eliminate it.

  • Or you could perform an in-memory/temp file formatting when doing a diff so the diffs are only done on code that's had the same formatting rules applied. Commented Feb 4, 2014 at 16:52
  • that's the thing, just like applying CSS doesn't change the HTML, I think a standard could be defined where formatting is separate from code. When you save/check-in the file, the code would be saved stripping extra lines and what not. If the same 'stripping' algorithm is always used, then only when the actual code changes is where differences would show.
    – Rodolfo
    Commented Feb 4, 2014 at 19:13
  • Which is kinda what I said - you just have to format it according to some rule (and TBH you might as well format it with a readable style). The ultimate problem with an IDE that shows code formatted using a stylesheet is that you could never view it in a different editor. Expect this lock-in feature in the next Visual Studio :-)
    – gbjbaanb
    Commented Feb 5, 2014 at 8:44
  • @gbjbaanb well if the standard is public, like CSS is for example, then it'd be up to the editors/IDEs to use it.
    – Rodolfo
    Commented Feb 5, 2014 at 16:06
  • Tools like prettier solve the "reformat" problem by converting the code to an abstract state tree first (to normalize it), and then convert the AST back into code using a specific format.
    – Ian Dunn
    Commented Feb 28, 2020 at 19:44

In some way, syntax highlighting, as it is done in most editors and IDEs, could be seen as a form of CSS for program text. It seems however that most programmer do not customise the syntax highlighting according to their needs (if it is possible).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.