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

Embrace for-of #10820

Closed
wants to merge 1 commit into from
Closed

Embrace for-of #10820

wants to merge 1 commit into from

Conversation

hlfan
Copy link
Contributor

@hlfan hlfan commented Feb 27, 2025

Convert some for loops to for of loops to increase readability

Copy link
Member

@tyrasd tyrasd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ususally I'm not the biggest fan of project-wide refactoring of single JS syntax features, for example because it will likely create merge conflicts with other open PRs/branches. Also, often the old code will typically have other stuff in dire need of a modernization as well.

That said, I think this does actually significantly bump the readability of the loops 💯 , and any potential merge conflicts should be quite easy to spot and resolve.

Only one thing: please don't use for (var foo of …) and choose either const or let instead, depending on the situation at hand.

@tyrasd tyrasd added this to the v2.33 milestone Feb 27, 2025
@tyrasd tyrasd added the chore Improvements to the iD development experience or codebase label Feb 27, 2025
@hlfan
Copy link
Contributor Author

hlfan commented Feb 27, 2025

There's much more possible that I didn't include, for now I only regex-replaced the loop heads when the index wasn't needed, including copying the declarations.
for ?\(((?:var|let|const) )?([^\s,=;]+) ?= ?0; ?\2 ?< ?([^\s,=;]+)\.length; ?\2?\+\+\2?\) ?\{\n\s+((?:var|let|const) )?([^\s,=;]+) ?= ?\3\[\2\];
for ($4$5 of $3) {
Therefore, I didn't take a closer look at var/let/const and also because I want to keep merge conflicts easily fixable.

@tyrasd
Copy link
Member

tyrasd commented Feb 28, 2025

ok, I see. Then let's not do it this way.

@tyrasd tyrasd closed this Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Improvements to the iD development experience or codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants