Does code formatting have to matter?

UPDATE: an issue would arise from stuff that is not strictly defined by a formatter, like consecutive empty lines etc., that would get lost in the process (local to server to local reformatting) which would annoy people (me as well 🙂

I’m used to adopting some shared code formatter so my question is not about “should I submit to that?”

I wonder does this (code formatting) have to matter at all? Isn’t it possible to have your repository store your commmits in some “default” formatting? You would never get to see what that style looks like, because every time you checkout all the sources get saved to your HDD after getting reformatted using YOUR formatter. Also every time you would browse the repository your client would show you the source reformatted using YOUR formatter. Also all diffs would be done after reformatting using YOUR formatter.

Is this possible to do? (E.g. client plugins, repository configuration, etc.)

2

Having no rules is not freedom, it’s just chaos. How would one write a book on programming language without any coding standards? Can you imagine each book having completely different formatting?

I have personal preferences about how the code should look like, but my personality is not really important when I work in a team. Collaboration is important, and coding standards make it possible, not just easier.

Is this possible to do? (E.g. client plugins, repository configuration, etc.)

Yes, but with worse performance, bugs, and additional setup phase. I have enough of configuration and plugins thanks to Maven, so I better stick with good old discipline.

However, there is an idea about storing a program not as it’s source code, but as it’s syntax tree. Like language-agnostic ASTs and stuff.


Update: On comments.

I see and understand your point, but I still believe my concerns are true.

Imagine you have those magic plugins which abstract away the formatting. You team up and code with other people without knowing about their preferences, and it’s all double rainbow all across the sky =)

Then, one of your colleagues tells you something like: “I’m writing a book about programming, need your help.” Then she sends you a manuscript and you see she’s gone completely opposite direction with not only formatting, but even with concrete syntax. Imagine she invented something like CoffeeScript on top of the language you both use: keywords are different, shorter syntax constructs, etc. It’s totally possible when you have such a magic plugin and people will do it (because of Murthy’s law, and it ain’t no joke).

So, you can’t help her, unless you both reject your personal preferences and use “standard”, “default” formatting and concrete syntax. Ta-a-da-a!

So I claim:

  1. If there are N people and each one is allowed to have his/her own concrete syntax and formatting styles, there eventually be N different styles.
  2. If there are people using those different styles, they would either write books using those different styles, or agree on using “default”.
  3. If you end up using “default” anyway to be able to collaborate, why bother with customization?

I’m not insisting on “purity” or something. I work with code which often has a mix of different formatting styles. But that’s mostly just slight differences which don’t affect the language. I’m totally fine with that.

But I don’t want to learn a new language just to feed someone’s ego (my own too, for that matter). I sometimes just copy-paste code in my instant messenger and I don’t want to have any plugin in it (on both mine and recipient sides, I’ll have you know) to send a snippet.

If you have such a magic plugin in your IDE, you have to have such plugins everywhere you want to stick you code to. That’s nothing more than additional problems.

Summary: you can do so, but you shouldn’t. Standards are better when customization. Conventions are better than plugins.


Update 2:

Image person A prefers to put an opening brace on a separate line:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>while (true) // endless loop
{
</code>
<code>while (true) // endless loop { </code>
while (true) // endless loop
{

Then this code can be stores in some kind of syntax tree and then shown to person B, who uses Egyptian style. That can be done either like so:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>while (true) /* endless loop */ {
</code>
<code>while (true) /* endless loop */ { </code>
while (true) /* endless loop */ {

or so:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>// endless loop
while (true) {
</code>
<code>// endless loop while (true) { </code>
// endless loop
while (true) {

And this second one has different order of tokens.

This shows that not all syntax constructs would fit in this model. So the language should be probably restricted in many ways to provide ability to customize formatting. Still I think it is possible, since there are programming languages like Google’s Blockly which have completely different concrete and “stored” syntaxes.

By the way, Blockly is a proof of concept, since you totally can customize the frontend to fit your artistic taste.

9

Technically, the main problem I see is with line numbers and debugging.
If you reformat the code, code might end-up on different lines, making it much harder to make sense of stacktraces and such. Also referring to code in general would be much harder, if your colleagues see different lines than you.

In context of collaboration, I think recognizability of the code is important. If I look at the same code on the screen of a colleague, it would be much harder to collaborate if I don’t easily recognize the code.

1

There’s an excellent tool uncrustify that takes a description of the source code formatting from a config file and outputs a formatted file as per specification in config file. However, there’s a few problems with this approach, most obvious and important are:

  1. File stored in the repository will be different than view of your file making looking into diffs much harder.

  2. It will be much harder for you to keep whitespace changes separated from the important commits.

I’m sure there’s more.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật