Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

My ideal programming language would let me define a custom css that would lay out code according to my specifications of columns/space/brackets placement etc. and check in only content. Everybody gets their own layouts - and hence we avoid all the long winded discussions about styles. A language that could do refactoring of variable names / function names as per my style requirements would be better. Another one that could translate to local language would be awesome!

Is there one such language variant of C/C++? What are the negatives of this?

share|improve this question
2  
@Subu Subramanian - This is not a function of a language. Style/content seperation is dealt with via paradigms like MVC, MVVM, even an ASP.NET code behind page. This has nothing to do with C/C++/Java etc. Nor would I ever want that kind of coupling with a language itself. Even ASP.NET webforms controls are annoying to modify vs MVC where you have full control. –  P.Brian.Mackey May 19 '11 at 14:53
6  
@P.Brian.Mackey he is talking about the format and layout of the source code not web pages. And to that point, Python gets this more right than most languages. Everyones code looks identical if they follow the standard conventions. –  Jarrod Roberson May 19 '11 at 14:57
    
Thanks @Jarrod - you are right. All I want is a C or C++ compiler + css format + IDE etc. that will let everyone in the team use their own styles/notations. –  Subu Subramanian May 19 '11 at 14:58
4  
-1 @Subu Subramanian - So, you want to be able to change the look, style, syntax of a language according to personal preference? This basically nullifies syntax, readability, teamability and turns everyone into a cowboy programmer. How is this a good thing? –  P.Brian.Mackey May 19 '11 at 15:04
3  
@Jarrod: Code in any language looks the same if everyone follows the same conventions. Python just doesn't give you a choice. Kind of like Henry Ford's "Any color you like, as long as it's black." –  TMN May 19 '11 at 15:05
show 9 more comments

6 Answers

up vote 15 down vote accepted

Those are functions of tools for languages. Many programming environments have refactoring tools. Eclipse has pretty decent ones for Java. Many programming environments also let you define a formatting style (I don't know if it's actually stored as CSS or some other representation). You could then autoformat all of your code as soon as you check it out of source control, and then re-format with a company-standards style on check in.

What you're asking for I don't think ever falls in the the language specification. I suppose it could but I've never heard of it. In my experience, this functionality is implemented in tools for a language.

share|improve this answer
    
Precisely. My IDE absolutely lets me specify the style. Annotations are also a way to separate out layers of meaning. –  Alex Feinman May 19 '11 at 15:02
    
+1 - This I agree with. –  P.Brian.Mackey May 19 '11 at 15:08
    
If there are languages like python which attach meanings to indents, I don't see why we can't have languages that are agnostic to the same. +1 for the reformat view ==> reformat checkin idea though. –  Subu Subramanian May 19 '11 at 15:14
    
@Subu Subramanian: So it sounds like you like the idea of Python being able to attach meaning to formatting, but at the same time you want to be able to control that yourself, through a language-required stylesheet? As for the reformat on checkout/checking, the only problem you might have is doing diffs with files in source control. To do a diff properly, you'd have to check out the file as a second copy, apply local formatting, and then compare. A bit of a pain, but could be managable... –  FrustratedWithFormsDesigner May 19 '11 at 15:26
1  
+1 for the right answer. –  Kristofer Hoch May 19 '11 at 16:22
add comment

If you just want formatting, you could do that using git (The awesome distributed VCS). Ofcourse you will have to find/write your own stand alone scripts that format code. I think there are tools available to do that which read in an xml and apply styling to source code.

http://progit.org/book/ch7-2.html

It turns out that you can write your own filters for doing substitutions in files on commit/checkout. These are the “clean” and “smudge” filters. In the .gitattributes file, you can set a filter for particular paths and then set up scripts that will process files just before they’re checked out (“smudge”) and just before they’re committed ("clean")

share|improve this answer
add comment

I see a few problems with what you are suggesting.

For one, the syntax and spacing are sometimes are core part of the language definition. You can't say, for example, "I don't want to see curly braces in C#" because the braces are an integral part of the language and perform an important function. You just can't use the language without them. Other languages, like Python, are very specific about spacing and indentation. In that case, it's also not a matter of personal preference.

Now, the question is, "why are those things required in a language?" And I think part of the answer is that parsing a language's grammar can be non-trivial. It gets more and more complex the more you relax the rules of the language's syntax. And even the more natural languages still have "marker" keywords that denote start or end of blocks if code and such.

Another consideration is being able to communicate with other developers. If you were able to define your own "view" onto the code, how would you talk about it with other people who are potentially looking at something completely different?

Machine-based translation is also not at the point where it'd be reliable. How would you decide which parts to translate? Just the keywords? Keywords and literal strings? Would you input new code in your local language and expect it to be accurately translated into a common base language?

There are some IDE plugins (such as ReSharper for Visual Studio) that will help enforce a coding style, but that style has to be maintained across the entire dev team that works on the code and, like you say, that style often has to be discussed. I don't see that as a bad thing. A team that can't agree on something as simple as a coding style is likely having bigger issues than that.

share|improve this answer
    
The moment you separate out the styling concerns from a language, parsing becomes relatively trivial - not complex IMO. Regarding translations, I meant only the variable names etc. After all, it shouldn't be hard to give a Japanese wrapper over C. I do agree on the communication point though - now if only we can find a way to solve that. –  Subu Subramanian May 19 '11 at 15:05
2  
@Subu I don't know if I agree with your parsing point. Presentation also drives input, right? You have to have some way of not only translating some base representation into your personal style, but also translating your personal style back into the representation. I think it can be done, but I also think it'd be needlessly error-prone. I can see bugs sneaking in that aren't exposed because of an issue with the display style. –  Anna Lear May 19 '11 at 15:07
1  
@Subu Subramanian: Unless your idea is to pre-parse the program (or just write it in parse tree format like Lisp), stylistic changes aren't going to make parsing easier. If anything, by providing more options, they'd make parsing harder. Translating computer language keywords into other human languages has been tried, and never gained much popularity. A compiler that would translate multiple language keywords would be slower, since the lexer would not be able to recognize keywords. Doing automatic global replaces on text can have unexpected effects. –  David Thornley May 19 '11 at 16:20
add comment

Sounds like what you need is a system that stores the AST or some other partially-compiled form, and then reconstitutes the "code" for editing. There were repository-based systems that did something like this (they stored modules in a tokenized / condensed format) back in the '80s, but I don't know of any systems that do this today.

I've had good luck in the past with code formatters linked with version control; they format the code according to my preferences when I check things out, and format it into "standard" format on check-in. That way, everyone gets to work with the code the way they like it, but we don't wind up with massive diffs due to formatting changes in version control.

share|improve this answer
add comment

Most programming languages use plain text as source code. Introducing a (in the worst case, mandatory - plain text formats have HUGE benefits, like easy diffing, little storage requirements, displayable by every single machine still in use, and propably many more) display layer over the actual content just for the sake of this seems like overkill to me.

Moreover, it's already possible to some degree with plain text. Tools can convert indentation, automatically rename things, perhaps even convert from mixedCase to lowercase_with_underscores etc. if the input uses one style consistently. Fiddling with spacing around brackets seems possible as well, although I've never seen it and most styles seem to agree in this regard. Translating (well) is plain impossible for machines at the moment and I don't see the need for it - programming happens in english, period, new paragraph.

There are languages that don't use plain text but live in a graphical enviroment. I don't know these very well, but in principle it should be possible to display the same program in different ways - you'd just have to replicate the editing facilities, which might be quite some work.

share|improve this answer
    
The diff'ing etc. can happen on the original text in my proposal. Source code Storage requirements don't matter in today's world. I do know that most IDE's let you convert the format, but this screws up the diffs because you end up checking in a file that has 2000 lines of changes when you changed only one line + the file format. I would rather separate out the formatting. –  Subu Subramanian May 19 '11 at 15:01
    
So what's the difference between your proposal (introducing a wholly new layer and a LOT of complexity) and just running these tools over the source on checkout and converting back on commit? (And while we're at it - what's wrong with simply agreeing on a single coding style?) –  delnan May 19 '11 at 15:05
    
running a checkstyle kind of tool as a part of checkin gauntlet, that will auto fix actually makes sense. I will try and see if I can configure my setup to do this. Agreeing on single coding style: Why force when you can have options! –  Subu Subramanian May 19 '11 at 15:07
add comment

You should take a look at Squeak Smalltalk as an example of language/environment where it's possible to, and people relatively often do, display code in formats that are specific to the programmer.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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