Keeping Your Classes Shorter Than 250 Lines. Soroush Khanlou:

One way that Backchannel’s SDK maintains its readability is through simplicity. No class in Backchannel is longer than 250 lines of code. When I was newer at programming, I thought that Objective-C’s nature made it hard to write short classes, but as I’ve gotten more experience, I’ve found that the problem was me, rather than the language. True, UIKit doesn’t do you any favors when it comes to creating simplicity, and that’s why you have to enforce it yourself.

This is a fantastic guideline and a wonderful post. I stick to a similar guideline in my code and had been wanting to write an article about it for a while. Soroush saved me the trouble.

The exact number isn’t what’s important here (my guideline is to keep Swift files under 100 lines), what’s important is giving yourself a metric, a general feeling for when a piece (class, struct, enum, whatever) of your code gets too big. For me, when a piece hits about a hundred lines it’s generally time for me to start breaking things out into smaller pieces.

A hundred lines or less (including doc strings, liberal whitespace, and no functional funnybusiness) keeps my code well structured and highly readable.

Join the Discussion 👂🤔✍️

Please read the Discussion Guidelines before replying.

☑️ Email me when someone replies.

Speed of Light