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

Skip to content

Rename named return variable in walker closure #21

@flrdv

Description

@flrdv

By default, walker closure has the following signature:

func(i *jscan.Iterator[S]) (err bool)

IDE proposes it every time you're trying to use auto-complete. And I find the named return's name quite inconvenient because of the following reasons:

  1. err variable is pretty common and is usually meant to carry a value of type error. This sometimes leads to name collisions
  2. It doesn't quite respond to its semantics: it is more like some exit or stop

The preferred solution would be to replace bool with the actual error interface, so jscan.Scan would return it instead of error with code ErrorCodeCallback. However, it breaks backward capability, and according to the fact that v2 was released just recently, it definitely won't be implemented just now.

So my current solution is to rename it to some of the already mentioned variants:

  1. exit
  2. stop
  3. break_ (seems ugly tbh)

I'm going to open a PR after the resolution

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions