What's wrong with aligning the initialization code?

From Google JavaScript Style Guide:

Long identifiers or values present problems for aligned initialization lists, so always prefer non-aligned initialization. For example:

CORRECT_Object.prototype = {
  a: 0,
  b: 1,
  lengthyName: 2

Not like this:

WRONG_Object.prototype = {
  a          : 0,
  b          : 1,
  lengthyName: 2

The wrong one looks better. I do not understand what kind of problems they are talking about. In what way inserting a couple of tabs before the colon could hurt my code?


There is nothing wrong with either.. Its more a personal preference than anything. Avoiding those extra tab/space characters, will shave some bytes off the file size, but if you are using some kind of minifier or compressor, it shouldn't matter as these extra characters will be stripped off. So you should probably stick to what you like best as it doesn't really matter.

I think the problem is that it's not as easy to tell which key on the left goes with which value on the right when they're so far apart.

You could compromise and use a TAB stop for the alignment, so most values will be aligned but there won't be any huge horizontal spaces.

Need Your Help

Best practice on connecting Activities

android android-activity

I'm writing my first Android app and want to pick up good coding practices. I have an Activity which contains a 2-column grid of all the data items available in the app (listActivity). There's an

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.