Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@setanarut
Copy link
Collaborator

Change Log

Refactoring (modernize)

  • Version updated to Go 1.24.4
  • Replace manual slice manipulation with functions from the slices package (optimization)
  • Modernize for loops (second batch, manual changes)
  • Modernize for loops (modernize Command line tool)
  • Change interface to any

t := -INFINITY

for i := 0; i < count; i++ {
for i := range count {
Copy link

@RikusLategan RikusLategan Jul 2, 2025

Choose a reason for hiding this comment

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

As much as I like C++'s notation, Go is just always easier to read, thank you.

Copy link

@RikusLategan RikusLategan left a comment

Choose a reason for hiding this comment

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

image

Master:

@RikusLategan ➜ /workspaces/cp (master) $ go test .
ok      github.com/jakecoffman/cp/v2    0.009s

Modernize:

@RikusLategan ➜ /workspaces/cp (modernize) $ go test .
ok      github.com/jakecoffman/cp/v2    0.003s
  • Adding --v to get more verbose tests does not reveal anything interesting.
  • Readability of the code has certainly improved.

@setanarut
Copy link
Collaborator Author

setanarut commented Jul 2, 2025

Also the slices package is faster. fc78afb

@setanarut setanarut enabled auto-merge July 3, 2025 11:36
Copy link
Owner

@jakecoffman jakecoffman left a comment

Choose a reason for hiding this comment

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

LGTM

I'm assuming moving from interface{} to any isn't an API change since they mean the same thing, so I won't cut a new major version for this.

@setanarut setanarut merged commit e8461d0 into jakecoffman:master Jul 10, 2025
1 check passed
@setanarut setanarut deleted the modernize branch July 10, 2025 18:29
@RikusLategan
Copy link

LGTM

I'm assuming moving from interface{} to any isn't an API change since they mean the same thing, so I won't cut a new major version for this.

Yes, it is safe to assume this. any will behave identically to all existing uses of interface{}, it's purely a cosmetic/aesthetic change to improve readability
See golang/go#49884

ponyo877 added a commit to ponyo877/cp that referenced this pull request Oct 25, 2025
Instead of removing the manual i++ increment, revert the for loop to its
original pattern before PR jakecoffman#43. This maintains consistency with the
pre-modernization code structure where loops with conditional continue
statements use manual index management.

The original pattern was:
for i := 0; i < len(space.dynamicBodies); {
    if condition {
        continue  // Skip i++
    }
    i++  // Increment only when not skipping
}
jakecoffman pushed a commit that referenced this pull request Oct 25, 2025
* Fix index out of range panic in ProcessComponents

This fixes a regression introduced in commit f1e35a6 (modernize for loops 2).

When modernizing the for loop from traditional style to range syntax,
the manual i++ increment was not removed, causing a double-increment bug.

The for..range statement automatically increments the index variable,
so the manual i++ at line 606 caused the loop to skip indices and
eventually panic with 'index out of range'.

Fixes the panic that occurs when SleepTimeThreshold != INFINITY.

* Revert to original loop pattern for consistency

Instead of removing the manual i++ increment, revert the for loop to its
original pattern before PR #43. This maintains consistency with the
pre-modernization code structure where loops with conditional continue
statements use manual index management.

The original pattern was:
for i := 0; i < len(space.dynamicBodies); {
    if condition {
        continue  // Skip i++
    }
    i++  // Increment only when not skipping
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants