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

Improve section ordering in scripts/github-changelog.cr #11770

Conversation

straight-shoota
Copy link
Member

This patch establishes a fixed order for sections in the changelog generator.

@@ -163,11 +165,17 @@ sections = array.group_by { |pr|
end || "Other"
}

titles = sections.keys.sort!
titles = [] of String
["Compiler", "Language", "Standard Library", "Tools", "Other"].each do |main_section|
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this could be changed to ["Language", "Standard Library", "Compiler", "Tools", "Other"] because language and stdlib are more impactful to the average user than compiler changes?

last_title1 = nil

titles.each do |title|
prs = sections[title]
prs = sections[title]? || next
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
prs = sections[title]? || next
next unless prs = sections[title]?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. I think assignments in trailing conditionals are a code smell.

Copy link
Contributor

Choose a reason for hiding this comment

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

And next in assignments is fine with you? What's the logic here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
prs = sections[title]? || next
prs = sections[title]?
next unless prs

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I think that's fine. It's handling a null state and breaks from the current iteration as a result. That's an established idiom, similar to x || return and x || raise etc. of which you can find many instances in stdlib, for example.
Separating the expressions is also fine, of course. I just don't see it's necessary.
Unless there's reasonable concern about the readability, I'd like to avoid useless style discussions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Using next / return or raise within the assignments should be considered as a code smell.

That's an established idiom, similar to x || return and x || raise etc. of which you can find many instances in stdlib, for example.

No, it's not. In stdlib is used only in 5 places (not counting specs) - see https://cs.github.com/crystal-lang/crystal?q=%2F%5Cs%3D%28.%2B%3F%29+%5C%7C%5C%7C+%28next%7Creturn%7Cbreak%29%5CW%2F+-path%3A%2Fspec%2F

Unless there's reasonable concern about the readability, I'd like to avoid useless style discussions.

Useless for you perhaps, so please keep your judgements for yourself.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I didn't mean to pass any judgement. Useless discussions are useless, that's a fact. Whether this particular style discussion is useless depends on the condition of whether there's reasonable argument.

Your link doesn't work for me, and I'm sure its results are incomplete. A local code search shows at least 80 instances of || plus trailing break expression in src, a quarter of them in assignments. So I'm pretty sure this can be considered established. If you'd like to change that, please start a separate discussion. But we should refrain from discussing general style issues in unrelated PRs.

@straight-shoota straight-shoota added this to the 1.4.0 milestone Mar 16, 2022
@straight-shoota straight-shoota merged commit bcf193a into crystal-lang:master Mar 17, 2022
@straight-shoota straight-shoota deleted the feature/github-changelog-improve branch March 17, 2022 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants