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

build.go: extracts two functions from huge main() #3160

Closed
wants to merge 15 commits into from

Conversation

lkwg82
Copy link
Contributor

@lkwg82 lkwg82 commented May 22, 2016

Purpose

extracts checkArguments and running commands into two separate functions.

Testing

run the build

// which is what you want for maximum error checking during development.
if flag.NArg() == 0 {
var tags []string
if noupgrade {
tags = []string{"noupgrade"}
Copy link
Member

Choose a reason for hiding this comment

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

This gets lost

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems so, but this diff is a bit poor. Look at line 178 (https://github.com/lkwg82/syncthing/blob/github-checks4/build.go#L178) there it is.

@calmh
Copy link
Member

calmh commented May 23, 2016

I don't know... There's something about these refactorings that just strokes me the wrong way. I can't fully put my finger on it, but one thing is that you for example extract into functions the fairly trivial single-switch-clause for printing the arch warning, but not the admittedly somewhat hairy get-the-current target function... I would have expected the opposite. I'm also not super keen on passing strings and empty targets to a runCommand function - it seems sane to me call that function with a user supplied argument, but since it's a switch clause where most of the legs are just one function call each, runCommand("vet", target{}) is just a less type safe way of saying vet("cmd", "lib")?

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 23, 2016

I don't know... There's something about these refactorings that just strokes me the wrong way. I can't fully put my finger on it, but one thing is that you for example extract into functions the fairly trivial single-switch-clause for printing the arch warning, but not the admittedly somewhat hairy get-the-current target function... I would have expected the opposite.

Do you remember that this was part of a bigger refactoring? So this is just what I thought of I can do better to ease reading the flow. I tried to keep it focused (from my perspective). Maybe I can do another PR, else this will get bigger again ;).

I'm also not super keen on passing strings and empty targets to a runCommand function - it seems sane to me call that function with a user supplied argument, but since it's a switch clause where most of the legs are just one function call each, runCommand("vet", target{}) is just a less type safe way of saying vet("cmd", "lib")?

Maybe I can go one step further. I'll have another look into.

@lkwg82
Copy link
Contributor Author

lkwg82 commented May 23, 2016

  1. I dont know to replace the switch-case properly. Maybe a map of target and functions (actually the same).
  2. Else I dont like to inline the vet command call. As it can be run from the default and a specific run. And I like the single command registry approach. We can lookup at a single place, what will be called.
  3. runCommand("vet", target{}) mmhm , it can be hidden with a vararg parameter list. This puts some nasty length check code at the top of the func. I'm not sure if you like this. I dont like it. Maybe you tell how you would do it.
  4. I just tracked down the usage of tagsargument for install()and build(). This can be inlined in a way. But this wides the PR. We agreed to tradeof refactorings toward many small PRs ;)

So?

@lkwg82
Copy link
Contributor Author

lkwg82 commented Jun 4, 2016

How to go further?

@calmh
Copy link
Member

calmh commented Jun 7, 2016

@st-review merge it, it's fine

build: Extract runCommand from main

@st-review
Copy link

👌 Merged as 343dc48. Thanks, @lkwg82!

@st-review st-review closed this Jun 7, 2016
st-review pushed a commit that referenced this pull request Jun 7, 2016
@lkwg82 lkwg82 deleted the github-checks4 branch June 7, 2016 20:39
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Jun 16, 2017
@syncthing syncthing locked and limited conversation to collaborators Jun 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants