8000 refactor: replace sequential assignments with explicit variable decla… by wlynxg · Pull Request #1060 · fortio/fortio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor: replace sequential assignments with explicit variable decla… #1060

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

Merged
merged 4 commits into from
Jun 23, 2025

Conversation

wlynxg
Copy link
Contributor
@wlynxg wlynxg commented Jun 10, 2025

During my review of the fortio source code, I initially attempted to trace the assignment and usage relationships of fields in the RunnerResults struct. However, I found it challenging to locate the corresponding assignment logic due to the use of sequential struct assignments, which are not properly indexed by LSP (Language Server Protocol) tools.

After further investigation, I discovered the assignment logic in https://github.com/fortio/fortio/blob/master/periodic/periodic.go, where fields were being initialized using sequential struct literal syntax:

// Original sequential assignment (hard to track with LSP)
results := RunnerResults{
    startTime, // LSP cannot resolve which field this corresponds to
    endTime,
    numThreads,
    // ... other fields
}

This syntax, while concise, makes it difficult for developers to:

  • Quickly identify which struct fields are being initialized
  • Use IDE features like "Find Usages" or "Go to Definition"
  • Maintain the code safely when struct fields are added/removed

To address this, I refactored the assignments to use explicit field names:

// Refactored to explicit field assignments
results := RunnerResults{
    StartTime:    startTime,
    EndTime:      endTime,
    NumThreads:   numThreads,
    // ... other fields with explicit names
}

While this change does not affect runtime behavior, it significantly enhances the developer experience for anyone studying or contributing to fortio's source code.

Copy link
Member
@ldemailly ldemailly left a comment

Choose a reason for hiding this comment

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

Thanks, yeah it was quite bad to just do unnamed - the comment about the other badness should remain though

wlynxg and others added 2 commits June 23, 2025 08:06
Co-authored-by: Laurent Demailly <ldemailly@gmail.com>
Copy link
codecov bot commented Jun 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.2%. Comparing base (6b8dbd3) to head (993afa6).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1060     +/-   ##
========================================
+ Coverage    74.0%   74.2%   +0.1%     
========================================
  Files          26      26             
  Lines        6404    6434     +30     
========================================
+ Hits         4742    4772     +30     
  Misses       1477    1477             
  Partials      185     185             

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member
@ldemailly ldemailly left a comment

Choose a reason for hiding this comment

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

thx! will merge when tests pass

@ldemailly ldemailly merged commit 46081d8 into fortio:master Jun 23, 2025
12 of 15 checks passed
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.

2 participants
0