Long lines of text in source code [duplicate]

Possible Duplicate:
Is the 80 character limit still relevant in times of widescreen monitors?

I used to set a vertical line set at 80 characters in my text editor and then I added carriage returns if the lines got too long. I later increased the value to 135 characters. I started using word wrap and not giving myself a limit but tried to keep lines short if I could because it took a lot of time shortening my lines.

People at work use word wrap and don’t give themselves a limit.. is this the correct way?

What are you meant to do ? Many thanks.

2

Opinions differ wildly on this matter. The best thing to do is to follow the same style as the rest of your team. It helps if the style is codified in a style guide so you can all argue about what’s best in a productive way.

From my experience and from some random statistical data you can find on the Internet, the best is to keep lines at a maximum of 120 characters. That is about how much is comfortable for a human to read in a single line and also it does not require horizontal scrolling on most displays today.

I am strongly recommending to anyone to put and respect a limit because not all editors have a word-wrap feature and not all programmers enable word-wrap in their IDEs. In fact I do not personally know anyone who uses word-wrap in source code.

Word wrap can also be confusing when the code suddenly breaks the line in places that would lead to errors if there would be real new line at that point.

1

It depends on how your source code will be used/by whom.

If it will be printed with monospace font or shown through terminal use 80 characters.

If others with smaller monitors will look at it, use some limit to acomodate them (eg 80, but it can be more, but 80 is safe).

Another point of view, try to not use so long lines (sometimes it is unavoidable, often it is avoidable (and sometimes avoiding it is not worth it)).
Long lines are from:
1) too deep indentation (introduce functions)
2) too much done on one line
3) method chaining
4) too much parameters for one function
5) too long indentifiers

all of them are code smells (at least for someone).

if method declaration gets too long (without having enormous ammount of parameters), puting one parameter per line can be much more readable than wrapped line or scrolling to read it.

It depends on your team norms. Some people want the 80 character limit, some could care less.

The focus though is on readability. If code goes off the screen it tends to be unreadable. If it wraps around, that tends to be unreadable too. It’s often better to refactor the code to simply not be too long.

What’s “too long”? Most places I’ve been have had the same monitors, and the same IDEs with the same fonts. Baring some team norm, I would work off of “if your code goes off your standard screen using a full screen IDE with the standard font and configuration… then it’s too long.”

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