Ask HN: Do you limit your code to a certain line width?
If yes, then
1. How much?
2. How strict are you in following the limit?
3. What do you think about this?
I'm interested because I was trying to format code to 80 chars wide, but I find that a little less. I think between 100-110 is a sweet spot for readability.
PS: I write Ruby/JS.
24 comments
[ 0.97 ms ] story [ 56.1 ms ] threadI follow it completely, regardless of language.
Anymore I have been "ok" with 120 characters for most code, mostly because screen sizes have gotten so nice and I rarely print code anymore.
That said, I do still try and keep code around 80 characters wide where ever possible though, I just find the formatting and code legibility to be better in most circumstances. Also, I find this keeps people from nesting things too deep (C/C++/C# come to mind), because it becomes hard to follow the code, hence they start breaking code into more modular components.
My other reason, I sometimes work off only my laptop monitor and while it gets wide, I find myself scrolling left and right when code exceeds 90ish characters in width and that bugs me.
I wrote a post about it which generated some responses, and it seems IDEs are to blame. Once you get into some of those environments, keeping things (relatively) narrow for the sake of others might just go out the window.
I covered it here, including a screenshot of what a typical dev session for me looks like: http://rachelbythebay.com/w/2012/08/31/lines/
But foregoing a nice font and some basic syntax highlighting just seems masochistic.
For me, that is a nice font -- "9x15". It's one I deliberately selected instead of whatever the default would be.
Syntax highlighting drives me nuts, so I don't use it.
Now, try that in C++. You can loose 10+ chars to indentation (namespacing, etc) alone. I think the 80 chars puritanism is just plain idiotic, specially in some languages like Obj-C.
Take this kind of bureaucratic crap:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(whateverChanged:) name:UITextViewTextDidChangeNotification object:nil];
If you start hard wrapping every long call you find you will end up with incredibly long files, filled with framework crap instead of useful information.
http://google-styleguide.googlecode.com/svn/trunk/objcguide....
Edit: One single attribution that crosses the 80 columns rule (4 levels of indentation - 4 spaces each)
placeHolderLabel.lineBreakMode = UILineBreakModeWordWrap;
The person who wrote that is obviously not fluent in Obj-C and even says the rule is 'controversial'.
I still think that it's just common good manners to keep code to 80 chars, those languages should work better to not be so verbose.
If I were working on a team based project, then I would absolutely adhere to a basic style guide regarding whitespace, line widths, etc.
Edit: guess I should add I primarily work in Python, C, and Javascript.
I try to have two windows open on my MacBook Pro 80-100 chars per line allows me to do that, most of the time.
It is a pet peeve of mine when developers try to fit as much on one line of code as possible. There are tools to compile code, you as a developer should try to make your code as human readable as possible, that is unless you like being the only one to maintain your code.