Hacker News new | past | comments | ask | show | jobs | submit login

It's looks great.

I think for me biggest problem with code snippets is that I encounter them with mobile device. Lines are quite long, like who uses 80 character line limits these days, more like 160. This combined with reality that most websites don't allow mobile device to zoom out.

I wish I could read full lines of code instead of trying to scroll back and forth.




I hard wrap at <=80 columns, and enforce those standards in codebases and in CI. Prettier's default is 80, and I don't change it.

I have three huge monitors, but long lines just makes most of the right-hand side of an editor window wasted.

Text files (source) are documents, and documents are much taller than they are wide: portrait orientation, like letter or A4. My two side monitors and oriented in portrait mode for this reason, and their quadrants (also portrait) are where I put editors.

I made this comment not to show my age, but to overcome the loudness bias of trends. There are plenty of us out here who still do it the old way, because the new way isn't better.


The new way is to make the lines as long as a human needs it to be, and use the computer to automatically wrap them when you need a narrower view.


The Linux kernel style guide expresses a different rationale.


Even 80 characters could be too long for some screens / font size. Long lines could be broken (like white-space: pre-wrap does), with an indicator that the line has been broken at the beginning of the continued lines. This is what Kate does and I think it is a good default, better than having to scroll horizontally.


I guess one could use prettier with different max line lengths on the same code, then hide irrelevant versions with a media query. Feels a bit overengineered TBH

Alternatively, on a mobile device, you could try to display the "desktop view" and put your phone in landscape mode.


That's... actually a brilliant idea, in my opinion. Overengineered? Idk, seems like something you'd have to implement once with like 100 lines of glue code for different libraries and then it could just work. And it could seriously benefit mobile viewers. Personally I read a lot of programming blogposts on my phone while commuting etc.


ideally, there should be one content and exclusively handled with styling.

maybe using some combination of pre tags and white-space pre-wrap


It may be possible to use `<wbr>` in a single representation, assuming the indentation is solvable.


In mobile Safari, you can reduce the text size to 75% to fit more in the viewport but on the posted page, there's a max-width set that still makes horizontal scrolling necessary.

What you'd probably rather have is for the `<pre>` element's default styling of `white-space: pre` to be changed to `white-space: normal`, that would make the text wrap as it does in paragraphs and such. It's easy to tell when such wrapping is happening in the code block styling that includes line numbers.


or possibly pre-wrap


I have the same problem. I've taken to reformatting code that I post on my blog to fit in something like 60 columns, with a modified code style that takes less horizontal space (using clang-format & prettier to do the work for me).


Could be interesting to explore using media queries to change the code layout itself, like setting indent levels and line break placements (in listing method parameters, for example). Maybe even variable/class/method name collapsing.


If two people look at the same webpage with different size monitors, they see different code.

Probably not the best solution.


Certainly getting out of the scope of the orignal discussion here, but you would think people should be able to have their code layout and style to their own preference suited for their device. There are problems with that to overcome certainly, for e.g. referring to line numbers, but they seem fairly solveable.

But commenters here suggesting the 80 char limit, inherited from IBM punchcards and typewriters before that, for diplaying code on smart phones half a century later is a little hilarious to me.


80 characters is a widely-agreed-upon standard, and standards with lots of buy-in are useful for a variety of reasons, regardless of origin.

Units of precisely 20 feet is also a standard, used mostly in countries that use SI. It doesn't diminish the value or utility of containerization.


Yes standards useful and workplaces can easily enforce their own internal ones for things like line length limits. But they are useless if they do not work for everyone who they apply to and especially not if they don't adapt to world around them. Cubit used to be a standard, too! But then we developed better ways to measure things than our inconsistently sized forearms.


Character limits are obsolete.

Enter a line break if you need one. No need to force. We have high-res widescreen monitors now and it results in much more productive viewing. And editors can automatically wrap text if you need a narrower window.


That's the point. The renderer doesn't word wrap


I consider 80 a soft limit, and 128 (nice round number) a hard limit. I find that even 80 is seldom reached, since I tend to use sane identifier lengths and small indents. The longest lines in my code are usually comments.


Depends a lot on the language. I've also seen people write lines of code that don't fit on my 4k TV


I use 80 character limits, and suggest corrections to that effect during code reviews. I feel it helps readability.

Is it becoming a tend to have longer limits?


I loath having 80 char limits. Nothing worse than you end up 3 characters over on a condition and need to try format it nicely across 2 lines. More often it’s less readable splitting it than just having it on 1 line.

If 80 char is a warning it’s ok. Because obviously if every line is super long that’s not readable either. Needs to be a balance.


I feel like it hinders readability. Sometimes the end of a line isn't that important and can mostly be inferred from the start of the line or only occasionally needs to be inspected, meanwhile being able to see more of the whole file on screen at once can be really beneficial.


My workplace has a C++ character limit of 80. A lot of people complain but I can have three code windows side-by-side plus a source tree so I think it's great.


I still use 80 character line limits. Thanks to a wide monitor, I can fit 4 windows side by side and still read them without eye strain.


thank you! mobile is my biggest issue as well.

to add to what you wrote, mobile web has this nasty bug with code sections with a horizontal scrolling bar inside a page that already has a horizontal scrolling bar. these two don't play well.


Agreed, soft wrap exists in editors and could be added here.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: