Easy initializer list editing

I’m usually into keeping my code nice and neat, but sometimes its also difficult to edit too. But this tip is not like that actually.

Setting up your initializer lists this way not only makes them nice and tidy, they’re easy to edit too. When you add or remove a member variable,  you add or remove the entire line. No shuffling commas about or re-straightening up. The other reason I like this is because if you have the following:

It’s difficult to tell where the parameters end and the initializer starts. In my opinion, this isn’t any better:

It still looks like a function with 6 parameters.. It’s just more difficult to read.

But I think this is substantially easier to read:

You can immediately identify what is the initializer list by the ‘:’ and the ‘,’ at the beginning of the lines.

Leave a Reply

You must be logged in to post a comment.