-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add line numbers to code snippets #9671
Comments
Hi @izh1979, We had line numbers in the past for the code snippets and we decided to remove them, some of the discussion about this decision is mentioned in this issue. The main reason is that line numbers in code can help but when we start referencing those line numbers in text, it can be a maintenance overhead to keep the reference in text in sync with any updates to code. |
What is the consensus to do with similar occurrences like the one reported: XMLHttpRequest/Synchronous_and_Asynchronous_Requests — should all the references to line numbers in text be considered a bug, reported for improvement, and potentially rewritten somehow more contextually? I remember lines & highlighting not being brought over to the new system mdn/content#3512 (comment), but not sure what to do with pages that rely heavily on that in text. (Any ideas @wbamberg @chrisdavidmills 👋 what should be done in such cases?) |
If we're committed to not having line numbers in code samples then we should update pages that don't make a lot of sense without them. I don't think there are that many of these. Documentation like https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest_API/Synchronous_and_Asynchronous_Requests, even if we had line numbers would still be hard to use because the text is quite far from the code, so I have to keep scrolling up and down to see which line is referred to. It's also unclear which of the 2 code blocks the line numbers are referring to. Perhaps comments might work better? Although I'm not that keen on documentation-in-comments either. If it were me, for example in this case, I would try to split up the example into 3 separate code blocks and discuss each one separately. And instead of "Line 15 specifies true for its third parameter...", for example, I might say something like: We pass |
Hi @janbrasna! It's been a long time since I heard from you; hope you are well ;-) Totally agree with @wbamberg on this one — we made the decision a long time ago not to have line numbers because of the maintenance nightmare they created (code examples going out of sync with text explanations and associated example repos), and it is better to split up snippets into smaller pieces and explain them contextually in different ways. So yes, these should be removed/rewritten. We really shouldn't be showing large code blocks on pages. If we do need to refer to huge code blocks, they should be in a repo somewhere and linked to. |
Summary
Currently many MDN articles refer to particular line numbers in the code. E.g., "Line 16 actually initiates the request." However, the code snippets do not have the line numbers. So, it is inconvenient to find the corresponding line.
Having lines numbered could be better.
URL
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Synchronous_and_Asynchronous_Requests
Reproduction steps
Expected behavior
The lines are numbered.
Actual behavior
The lines of the codes snippets are not numbered.
Device
Desktop
Browser
Firefox
Browser version
Stable
Operating system
Windows
Screenshot
No response
Anything else?
No response
Validations
The text was updated successfully, but these errors were encountered: