News for hackers. Stuff that matters.
Re:Go and Versioning: Minimal Version Selection by sagichmal on Wednesday February 21, 2018 @07:38PM (#16434248)
Definitely not. Nothing here is particularly novel, `vgo` just stakes out a different position on all of the relevant spectrums than most (all) other package managers.
Re:Go and Versioning: Minimal Version Selection by dilap on Wednesday February 21, 2018 @08:26PM (#16434471)
Nah, it's totally novel -- it's a viable packaging system that isn't NP-hard. Is there any precedent for that?

It's also likely, in practical terms, to feel very different to work with than any existing packaging system.

My money is on it becoming quite popular.

It just feels like it's been sprinkled w/ the Go magic -- deceptively simple ideas that end up working really well.

Re:Go and Versioning: Minimal Version Selection by kibwen on Wednesday February 21, 2018 @09:18PM (#16434701)
> it's a viable packaging system that isn't NP-hard. Is there any precedent for that?

Yes, Rust's Cargo: see https://github.com/rust-lang/cargo/blob/0.25.0/src/cargo/cor... For demonstration, on my low-end VPS Cargo takes less than a quarter second to select the versions of the 289 transitive dependencies used by Servo (could be much less, but I don't have a precise measurement; `time cargo update` takes 1.22 seconds but this is dominated by the network calls checking for a new version of the crates.io index and checking for new versions of Servo's custom deps on Github).

The fact that the algorithm in the OP isn't NP-hard isn't anything worth getting excited about. The only advantage I can see is that it gives a measure of reproducibility without the need for lockfiles--though builds will still be less reproducible than they'd be with lockfiles.

Re:Go and Versioning: Minimal Version Selection by bradfitz on Wednesday February 21, 2018 @10:10PM (#16434883)
> > it's a viable packaging system that isn't NP-hard. Is there any precedent for that?

> Yes, Rust's Cargo: https://github.com/rust-lang/cargo/blob/master/src/cargo/cor.... For comparison, on my low-end VPS Cargo takes less than a quarter second to select the versions of the 289 transitive dependencies used by Servo

That's kinda an answer to a different question. The question you replied to was asking about other non-NP-hard systems and you replied with how much time your system took.

Re:Go and Versioning: Minimal Version Selection by kibwen on Wednesday February 21, 2018 @10:31PM (#16434958)
If you take a moment to read the linked comment, you will see that it describes how Cargo's selection algorithm is a simple heuristic that avoids NP-hardness. The subsequent timing example exists to demonstrate that the heuristic actually succeeds at avoiding pathological performance; Servo has more transitive dependencies than any known Rust project, and your development box is certainly more powerful than my $5 VPS.
Re:Go and Versioning: Minimal Version Selection by bradfitz on Tuesday February 27, 2018 @05:30PM (#16478635)
Ah, sorry, I didn't realize you were linking to a comment. I read that was a link to Cargo itself.
Re:Go and Versioning: Minimal Version Selection by dilap on Thursday February 22, 2018 @12:06AM (#16435265)
Sorry, nope. For your link:

> Actually solving a constraint graph is an NP-hard problem. This algorithm is basically a nice heuristic to make sure we get roughly the best answer most of the time.

That's miles away from the simple, linear time algorithm proposed here.

Maybe it doesn't matter (though I suspect we'll discover it does), but that's not what you were arguing.

Re:Go and Versioning: Minimal Version Selection by pcwalton on Thursday February 22, 2018 @12:22AM (#16435315)
Why do you suspect it does? Cargo has gotten tons of use and the speed of the dependency resolution process has, to my knowledge, never been a problem.

Besides, I suspect that if you restrict your Cargo graphs to use only the features that this Go proposal supports (minimal version pinning, in particular), then the algorithm is no longer NP-hard. There's no "Go magic" here: it's that just Go chooses not to implement features that could theoretically be slow (but aren't slow in practice).

Re:Go and Versioning: Minimal Version Selection by dilap on Thursday February 22, 2018 @12:52AM (#16435421)
No good reason, really :-) -- just a gut feeling/bias that when problems move from "tricky" to "easy", people end up creating new/unexpected tooling as a result, just because it's easier.

Might well be totally irrelevant here.

Sadly I don't know Rust (yet!), but Cargo certainly seems widely loved and admired.

Perusing the resolver code was pleasant, and impressive. We've come a long way from when you'd pull back the covers on a C++ std library or (god help you) boost, and run away screaming in terror.

The future is bright!

Re:Go and Versioning: Minimal Version Selection by kibwen on Thursday February 22, 2018 @12:27AM (#16435330)
Your condescension here is amusing. My good friend, please feel free to explain in more detail how the algorithm described in the aforementioned link is miles away from the algorithm in the OP. Feel free to also explain your fascination with linear time algorithms, considering that the nonlinear algorithm in question is demonstrably instantaneous for extreme real-world workloads (Go is supposed to be about pragmatism, I hear?). Lastly, feel free to lecture me further on how a you suspect that an algorithm that has been deployed and used, to overwhelming acclaim, by tens of thousands of programmers over the past three years will be found wanting in comparison to an algorithm that has existed on paper for two days, with no ecosystem or real-world experience to its name. :)
Re:Go and Versioning: Minimal Version Selection by dilap on Thursday February 22, 2018 @01:13AM (#16435524)
The claim under consideration is whether the Go packaging proposal is novel, not any of the other things you've mentioned. :-)
Re:Go and Versioning: Minimal Version Selection by TheDong on Wednesday February 21, 2018 @10:16PM (#16434902)
Please link to a tag of the repository, not master, or else the docs may shift out from under you.

https://github.com/rust-lang/cargo/blob/0.25.0/src/cargo/cor...

Re:Go and Versioning: Minimal Version Selection by kibwen on Wednesday February 21, 2018 @10:33PM (#16434971)
Yes, I always forget to do this. :)
Re:Go and Versioning: Minimal Version Selection by sagichmal on Wednesday February 21, 2018 @09:23PM (#16434713)
The lack of a solver is predicated on the minimal version decision as well as insisting that breaking changes are reflected in dependency identifiers. These decisions are points on their respective spectrums that other package managers have considered and rejected, because they impose (optimistically) novel or (pessimisticly) burdensome requirements on package authors and consumers. Namely, that we bias toward stable (unchanging) builds, even when security or bugfix releases may be safely applied; and that we force authors toward uncommon and arguably awkward naming decisions when making breaking changes, essentially shifting work from computers to humans.

Again, these things aren’t novel; in isolation, they’ve been considered (and rejected) by other package managers. Maybe they compose to something greater than the sum of their parts. At the moment, it’s unclear, and it mostly looks messy.

Re:Go and Versioning: Minimal Version Selection by ngrilly on Thursday February 22, 2018 @06:20AM (#16436816)
What makes you think this design was considered by other package managers (npm, yarn, pip, bundler, cargo, etc.) in the past? Is it documented somewhere?
Re:Go and Versioning: Minimal Version Selection by sagichmal on Thursday February 22, 2018 @08:13PM (#16443309)
I'm basing this on documented albeit informal conversations with other package manager builders and maintainers.
Re:Go and Versioning: Minimal Version Selection by mseepgood on Wednesday February 21, 2018 @07:49PM (#16434294)
The same could be said about 'gofmt' in relation to all the pretty printers that existed before, yet it was revolutionary.
Re:Go and Versioning: Minimal Version Selection by pcwalton on Wednesday February 21, 2018 @08:49PM (#16434566)
gofmt is only revolutionary in that it refuses to solve the hard problems that pretty printers for other languages solve. Specifically, it doesn't wrap long lines--ever--even though making visually pleasing line breaking choices is pretty much the hardest part of pretty printing (look at how clang-format deals with it, for instance). This design decision would be a non-starter for almost all other languages, where long lines occasionally happen.

In other words, gofmt showed that it's easy to write a pretty printer if you ignore line breaking and instead force everyone to accept long lines. This is not a particularly interesting, and certainly not revolutionary, result.

(Not coincidentally, I have similar concerns regarding this Go versioning proposal and lockfiles.)

Re:Go and Versioning: Minimal Version Selection by grey-area on Thursday February 22, 2018 @04:02AM (#16436272)
This is a philosophical difference, not an oversight.

gofmt imposes a single style on the entire go ecosystem, that's unusual as most previous formatters have lots of options, and allow different teams to adopt different styles (e.g. tabs vs spaces). Turns out it doesn't really matter what style you choose as long as everyone uses the same one, and long lines aren't a problem in practice.

Worse is better.

Re:Go and Versioning: Minimal Version Selection by pcwalton on Thursday February 22, 2018 @11:43AM (#16438869)
Long lines are annoying in practice! Maybe not in Go, where the language tends not to encourage long lines, but in lots of other languages, having to scroll horizontally is a huge distraction to understanding code.
Re:Go and Versioning: Minimal Version Selection by littlestymaar on Thursday February 22, 2018 @08:26AM (#16437353)
Everyone in a team should use the same conventions. The idea that everyone eveywhere on the world should use the same style has no practical interest : you don't get any productivity from it.

It's just a philosophical stance, and a rather totalitarian one IMHO.

Re:Go and Versioning: Minimal Version Selection by grey-area on Thursday February 22, 2018 @10:17AM (#16438081)
The idea that everyone eveywhere on the world should use the same style has no practical interest : you don't get any productivity from it.

I disagree on that - it makes it much easier to share code and to use code from other teams, and removes a whole area which people waste a lot of time on (bikeshedding formatting issues).

Re:Go and Versioning: Minimal Version Selection by littlestymaar on Friday February 23, 2018 @03:08AM (#16444917)
> and removes a whole area which people waste a lot of time on (bikeshedding formatting issues).

Interestingly enough, I've never seen people bikeshed about code formating in a project using a style formater even if it is configurable. But everytime Go is talked about here on HN, there are many people complaining about gofmt not being configurable …

Re:Go and Versioning: Minimal Version Selection by pcwalton on Thursday February 22, 2018 @01:52PM (#16440210)
But by not having a maximum line length, everyone gets to bikeshed where to insert line breaks. Thus gofmt isn't doing its job.

(Again, maybe line length doesn't matter much in Go, since lines generally don't get that long in Go, but for lots of other languages gofmt's choice would not be acceptable.)

Re:Go and Versioning: Minimal Version Selection by grey-area on Monday February 26, 2018 @08:02AM (#16464958)
FWIW, I haven't noticed this being a problem in Go code. Perhaps in other languages it's more important.
Re:Go and Versioning: Minimal Version Selection by peterevans on Wednesday February 21, 2018 @11:53PM (#16435229)
A pretty printer, historically—going all the way back to indent—allowed the user to define a bespoke style guide, with a specific indent level, with one way to align braces, etc. You could implement GNU-style C code with indent; you could implement Allman-style C code; you could mix in your own preference for indent level.

As such, I think your complaints are misplaced. gofmt is not a pretty printer. It's designed to implement a single standard format—one which does not define a maximum line width—but nothing more.

Re:Go and Versioning: Minimal Version Selection by pcwalton on Thursday February 22, 2018 @12:30AM (#16435340)
The purpose of a pretty printer is to increase readability of code. (This isn't controversial.) One of the most important aspects of code readability is line length. By not addressing that, gofmt isn't fully solving the problem that pretty printers are designed to solve.

Indent, by the way, allows for a maximum line length.

Re:Go and Versioning: Minimal Version Selection by peterevans on Thursday February 22, 2018 @12:53AM (#16435427)
As I said: gofmt is not a pretty printer.

It may help if you decouple the goal (increased readability of code) and the action (application of a style to code). Pretty printers—and gofmt—apply a style to code. That is their only job; in a traditional pretty printer, you could configure a terrifyingly awful style of code, and it would apply it happily and correctly. The readability of that style is a subjective judgment to others, but this is in no way a concern of the pretty printer.

You may not like the style of code that Go uses. That is a perfectly valid viewpoint, and I encourage you to develop it as you see fit! It is also perfectly valid to criticize the style choice of having an undefined maximum line width.

The problem gofmt solves is not "how do we allow you to style Go code", but more specifically, the problem it solves is "how do we encourage the community to adhere to one style of code for Go?" And it is successful in that. It is obviously unsuccessful in applying a style that you find aesthetically pleasing—alas!

Also, I am afraid that I did not claim indent does not allow for a maximum line width! I said that indent (like other pretty printers) allowed you to define a style "with a specific indent level" and that "you could mix in your own preference for indent level".

Re:Go and Versioning: Minimal Version Selection by pcwalton on Thursday February 22, 2018 @01:53PM (#16440225)
> The problem gofmt solves is not "how do we allow you to style Go code", but more specifically, the problem it solves is "how do we encourage the community to adhere to one style of code for Go?" And it is successful in that. It is obviously unsuccessful in applying a style that you find aesthetically pleasing—alas!

It's not successful if everyone puts line breaks in different places. By punting on that problem, gofmt isn't enforcing one style of code.

Re:Go and Versioning: Minimal Version Selection by ovao on Thursday February 22, 2018 @12:55AM (#16435433)
gofmt did not intend to solve the problem that pretty printers are designed to solve, but rather to unify formatting to remove formatting contention within the ecosystem.

A typical pretty printer has knobs and dials to control its output, for instance — gofmt has none.

Re:Go and Versioning: Minimal Version Selection by ngrilly on Thursday February 22, 2018 @06:23AM (#16436829)
I think you are missing the point of gofmt, which is to establish a one-to-one correspondence between the source and the AST. This way, you can parse the source to an AST, modify the AST, and reconvert the AST to source, and you have a guarantee that the resulting diff only touches the modified parts.
Re:Go and Versioning: Minimal Version Selection by pcwalton on Thursday February 22, 2018 @01:53PM (#16440233)
gofmt doesn't do that. It doesn't touch user-inserted line breaks (not to mention comments!)
Re:Go and Versioning: Minimal Version Selection by ngrilly on Friday February 23, 2018 @07:04AM (#16445802)
I don't get your point.

Let's say I have this program (which was goformatted):

    package main

    import (
        "fmt"
    )

    // commenting...
    // commenting...

    func main() {
        fmt.Println("hello", "world")
        fmt.Println(
            "hello",
            "world",
        )
    }
And I had log.Print("test") at the end of main():

    package main

    import (
        "fmt"
    )

    // commenting...
    // commenting...

    func main() {
        fmt.Println("hello", "world")
        fmt.Println(
            "hello",
            "world",
        )
        log.Print("test")
    }
Then I run goimports to automatically update the import directive (goimports parses the source to build an AST, then modifies the AST, then reconverts it to source code):

    package main

    import (
        "fmt"
        "log"
    )

    // commenting...
    // commenting...

    func main() {
        fmt.Println("hello", "world")
        fmt.Println(
            "hello",
            "world",
        )
        log.Print("test")
    }
Everything is kept exactly as-is, except the added line "log" in the import directive. This round-trip mechanism is the main benefit of gofmt.
Re:Go and Versioning: Minimal Version Selection by dilap on Thursday February 22, 2018 @12:10AM (#16435279)
Personally, I think long lines should never be hard-wrapped; let the editor wrap them.

gofmt was a revolutionary social achievement: it got a huge number of people to basically all format their code the same. That had never been achieved before; prior to Go doing it, I would not have even thought it would be possible.

(Obviously, not revolutionary in any sort of technical sense.)

Re:Go and Versioning: Minimal Version Selection by pcwalton on Thursday February 22, 2018 @12:26AM (#16435327)
It's clearly been done before. Python, for example, has mandatory indentation, so there's huge pressure for everyone to indent the same so that code can be copied around. Going back further, you have languages like Fortran in which column numbers were significant.

Having the editor wrap lines is contrary to standard practice in pretty much every other language. It requires extra editor configuration for no real benefit other than making gofmt a shorter program. Besides, editors don't wrap lines as nicely as a good pretty printer can. Again, look at clang-format: the heuristics it applies in order to apply a maximum line width are very carefully thought out.

Re:Go and Versioning: Minimal Version Selection by dilap on Thursday February 22, 2018 @12:43AM (#16435381)
Python code is not even close to consistently formatted! You see people using 2 space indents, 4 space indents, tabs...

Though, Python does do a better job than many languages of providing style guidance (pep 8 iirc), and I don't really see people do wacky stuff like messing with where to put space around parens. &c.

Can't speak to Fortran.

Thinking about it, maybe languages like J or APL are always consistently formatted by being so dense there's no room for extraneous formatting?

But certainly for C-like languages I've used, just getting people on the same team to all use the same format was a struggle, much less the whole company, much much less the whole world.

So in that way, gofmt definitely feels revolutionary to me.

Re:Go and Versioning: Minimal Version Selection by pcwalton on Thursday February 22, 2018 @12:52AM (#16435425)
> But certainly for C-like languages I've used, just getting people on the same team to all use the same format was a struggle, much less the whole company, much much less the whole world.

clang-format has really changed the game here. It's commonplace in large projects to run it on every commit.

There is a difference between C and C++ formatting and Go formatting, and it's that Go had gofmt from the start and has always had large social pressure to conform to it. Contrary to popular sentiment, I'm not sure that this is an unmitigated good, though. The reason is that clang-format was designed to mimic the existing style that emerges when programmers manually format code for maximum readability. This forced clang-format to consider comment formatting, line length, argument bin packing, etc. It had to be good, or else it wouldn't get use. On the other hand, because gofmt was guaranteed to get lots of use no matter what, there was less pressure for the result to be readable. This shows up in decisions like the lack of a line length limit.

Re:Go and Versioning: Minimal Version Selection by dilap on Thursday February 22, 2018 @01:04AM (#16435466)
(That's cool to hear about clang-format; I've been out the C++ game for a while, except for the occasional nostalgic prog comp.)

Well, again, I personally don't think line limit should be part of the code style -- it's really handy to be able to split or not split emacs buffers and have the code spill out to take up the space, wrapping dynamically. If the code hard-wraps, you're just stuck w/ that single decision. It's annoying.

Regarding Go's style more generally: Yeah, my own personal pref would be much denser that gofmt, but I happily submit for the consistency.

I just don't think style really matters that much (within the realm of reasonable, which gofmt certainly is): the important thing is consistency.

(By the way, a nice side-effect of consistency: you can easily grep for a particular thing w/ confidence w/o having to try to take into account all the possible stylistic variations.)

Re:Go and Versioning: Minimal Version Selection by pjmlp on Thursday February 22, 2018 @01:47AM (#16435706)
> But certainly for C-like languages I've used, just getting people on the same team to all use the same format was a struggle, much less the whole company, much much less the whole world.

We were using indent with CVS pre-commit hooks in 1999, hardly revolutionary.

Re:Go and Versioning: Minimal Version Selection by dilap on Thursday February 22, 2018 @03:02AM (#16436016)
i can't imagine being happy w/ 1999-era indent autoformatting my code...

but yeah, team style was definitely a solvable problem. global style, manifestly was not solved!

Re:Go and Versioning: Minimal Version Selection by pjmlp on Thursday February 22, 2018 @03:32AM (#16436127)
External libraries are binary dependencies, I don't care one second which style they use to write them.
Re:Go and Versioning: Minimal Version Selection by dilap on Thursday February 22, 2018 @09:36AM (#16437775)
Obviously it's not, like, a world-shattering problem, but I think there is a real, if small, overhead, to switching between different styles when looking at code.

I also just happen to really like things neat a tidy.

Final minor nice thing about having a fixed style: you can grep with confidence, without having to try to encode stylistic variations in the regex.

Re:Go and Versioning: Minimal Version Selection by gkya on Thursday February 22, 2018 @09:19AM (#16437661)
I don't get what's wrong with multiple styles.
Re:Go and Versioning: Minimal Version Selection by eikenberry on Wednesday February 21, 2018 @10:02PM (#16434847)
> [...] instead force everyone to accept long lines.

You don't need to accept long lines as gofmt respects your own line wrapping. It's easy to write code that never exceeds the 80 character limit. The main annoyance in go is it's use of tabs, so you have to change tabs in everything to a reasonable amount of space.

Re:Go and Versioning: Minimal Version Selection by pcwalton on Wednesday February 21, 2018 @10:14PM (#16434891)
Fair enough; that's a good point. I'd still argue, though, that gofmt isn't doing what people expect pretty printers to do. Long lines are some of the most common style violations in most projects.
Re:Go and Versioning: Minimal Version Selection by eikenberry on Thursday February 22, 2018 @04:11AM (#16436305)
100% agreed. I'm a strong believer that the 4-6 inch column rule from print media applies equally to text in general and that the 80 character rule is a good approximation for this print rule.
Re:Go and Versioning: Minimal Version Selection by Skinney on Wednesday February 21, 2018 @08:59PM (#16434615)
elm-format doesn't wrap long lines either. I'm not sure it would be a good thing if it did, to be honest.
Re:Go and Versioning: Minimal Version Selection by sagichmal on Wednesday February 21, 2018 @08:05PM (#16434375)
That's a stretch.
Re:Go and Versioning: Minimal Version Selection by xyzzy_plugh on Wednesday February 21, 2018 @07:45PM (#16434275)
I, too, am unfamiliar with prior art here. Are you able enlighten us?
Re:Go and Versioning: Minimal Version Selection by platz on Wednesday February 21, 2018 @08:07PM (#16434384)
Haskell's build tool Cabal also uses a solver that produces a concrete build solution that takes into account dependency bounds. It uses slightly different rules for the solver than what vgo uses.
Re:Go and Versioning: Minimal Version Selection by sagichmal on Wednesday February 21, 2018 @08:05PM (#16434378)
Not in a Hacker News comment, sorry; the space is just too big.