Skip to content
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

Closed
3 tasks done
izh1979 opened this issue Sep 16, 2023 · 4 comments
Closed
3 tasks done

Add line numbers to code snippets #9671

izh1979 opened this issue Sep 16, 2023 · 4 comments
Assignees
Labels
enhancement Improves an existing feature. involves: Product Requires the attention of the Product team.

Comments

@izh1979
Copy link

izh1979 commented Sep 16, 2023

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

  1. Open any article with the code snippets.
  2. The lines are not numbered.

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

@github-actions github-actions bot added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Sep 16, 2023
@caugner caugner added enhancement Improves an existing feature. involves: Product Requires the attention of the Product team. and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Oct 17, 2023
@s-sood
Copy link

s-sood commented Nov 2, 2023

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.

@s-sood s-sood closed this as completed Nov 2, 2023
@janbrasna
Copy link

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?)

@wbamberg
Copy link
Collaborator

wbamberg commented Feb 3, 2024

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 true as the third parameter to xhr.open()..."

@chrisdavidmills
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improves an existing feature. involves: Product Requires the attention of the Product team.
Projects
None yet
Development

No branches or pull requests

6 participants