News for hackers. Stuff that matters.
Re:Go generate: A proposal for a Go preprocessor by cageface on Saturday September 27, 2014 @06:13AM (#8376616)

  Motivating examples include:

  macros: generating customized implementations given
  generalized packages, such as sort.Ints from ints
If this is seriously their proposed solution to the lack of generics then my estimation of Go just dropped even further.
Re:Go generate: A proposal for a Go preprocessor by MichaelSalib on Saturday September 27, 2014 @06:28AM (#8376639)
It is a bit astonishing what lengths the go community is willing to, er, go, in order to avoid compile-time code execution (the basis of lisp macros) or generics. I understand that neither of these ideas were invented at Bell Labs during the 1970s, but at some point, can't we just put aside the not invented here syndrome?

Could we all just agree to pretend that Bell Labs folks invented those ideas? Would that work?

Re:Go generate: A proposal for a Go preprocessor by personZ on Saturday September 27, 2014 @08:43AM (#8376864)
The Go community are out building solutions productively and fruitfully, often finding the lack of generics an edge nuisance, but something that is by no means a showstopper.

The people who have no knowledge or skill in Go, on the other hand, fill the message boards, railing rabidly about how absolutely critical generics are, and don't these people (who almost universally have extensive experience across a number of languages) know what they're missing?

Re:Go generate: A proposal for a Go preprocessor by frowaway001 on Saturday September 27, 2014 @01:23PM (#8377585)
The point you are missing is that people who don't want to live in the 1970ies avoid Go in the first place, so the Go community by definition consists only of people who think Java-1.0 style programming is perfectly fine in 2014.

Yes, there are reasons why the intended audience of Go just didn't care and Go is mostly used PHP, JavaScript, Python, Ruby etc, developers today.

Re:Go generate: A proposal for a Go preprocessor by vorg on Saturday September 27, 2014 @06:08PM (#8378350)
> Go is mostly used PHP, JavaScript, Python, Ruby etc, developers today

Could be dynamic typing has had its day, just like visual programming from the 1990's. Or maybe users of those languages wanted to use one with a large corp backing it, like Java and C# have. The most common glib response I get when I say I'm trying out Go to write something is "You're using Go? So you wanna work for Google, do you?" Perhaps that shows the real motivation of why a programmer learns Ruby or Python or Go.

Re:Go generate: A proposal for a Go preprocessor by shurcooL on Saturday September 27, 2014 @06:23PM (#8378378)
There are people who want their language to be as complicated and feature-rich as possible. They have lots of choices available, including C++1*, Java, Ruby, etc.

Those languages probably don't have anything that has only one idiomatic solution. Even writing a for loop will have multiple different but viable alternatives.

Then there are people who want their language to be as simple as possible, yet still powerful enough to allow you to create all the things you can with Go.

There are very few such languages. In fact, there are a few things/special rules I'd like to see simplified in Go because they have less benefit than cost.

Having a simple language allows for some cool benefits, and if Go starts to compete with C++ for number of features, it will lose its main distinctive property.

Re:Go generate: A proposal for a Go preprocessor by frowaway001 on Saturday September 27, 2014 @07:11PM (#8378457)
That's a false dichotomy.

The desire for a simple language doesn't mean you have to accept all the mistakes Go made. Go is just not a very good language. It would be completely irrelevant without the Google name behind it.

Re:Go generate: A proposal for a Go preprocessor by shurcooL on Saturday September 27, 2014 @11:27PM (#8378838)
> Go is just not a very good language.

It certainly could be better (this is true of everything that's not perfect), but it is being improved (and it's open source, so you and I can help make it better). I already prefer it over many other languages.

> It would be completely irrelevant without the Google name behind it.

You mean... It would be irrelevant if Google and other people who work on it (being open source, many contributors aren't Google employees) did not make it what it is?

That's like saying... <any product> would be irrelevant if <those who made it> didn't make it as good as it is. It is a true statement, but how is it useful?

Re:Go generate: A proposal for a Go preprocessor by frowaway001 on Sunday September 28, 2014 @10:47AM (#8379853)
> but it is being improved

The things I care about can't be fixed, because they are fundamentally wrong in Go, they are not just some little oversight.

> I already prefer it over many other languages.

If I would start aiming low enough, I could also certainly find languages which are even worse than Go.

Honestly, I don't care. I prefer languages which do things better than X, not languages which are less worse than X.

> You mean... [...]

Eh no? I meant what I said. If the people who created Go wouldn't have been able to leverage the Google name (either by working at a company or by Google saying "don't use our brand for your toy projects") nobody would have cared.

But people said "OMG, Google invented online search!!! Then–by definition–they have to be language design experts, too!!!" and the tragedy unfolded.

Re:Go generate: A proposal for a Go preprocessor by shurcooL on Sunday September 28, 2014 @02:09PM (#8380440)
Fair enough, it sounds like your needs are very different from what Go satisfies.

Just out of curiosity, what language(s) do you prefer to use over Go?

> Eh no? I meant what I said. If the people who created Go wouldn't have been able to leverage the Google name (either by working at a company or by Google saying "don't use our brand for your toy projects") nobody would have cared.

I have a very good counter-example for you. Google also made Dart. I have no interest in Dart and I don't think it's anywhere near as good as Go from what I can tell about it.

Re:Go generate: A proposal for a Go preprocessor by frowaway001 on Monday September 29, 2014 @10:52AM (#8383098)
> counter-example

That's not a counter-example (necessary vs. sufficient).

Re:Go generate: A proposal for a Go preprocessor by burntsushi on Saturday September 27, 2014 @07:29PM (#8378479)
> so the Go community by definition consists only of people who think Java-1.0 style programming is perfectly fine in 2014.

This is a false analogy because there are significant differences between "Java-1.0 style programming" and Go.

> Yes, there are reasons why the intended audience of Go just didn't care and Go is mostly used PHP, JavaScript, Python, Ruby etc, developers today.

Why do you feel the need to bin people? I'm a Haskell programmer and yet I love Go. In your world view, this is an impossibility. But maybe I've given you too much credit.

Re:Go generate: A proposal for a Go preprocessor by personZ on Sunday September 28, 2014 @08:46AM (#8379590)
Go is mostly used PHP, JavaScript, Python, Ruby etc, developers today.

Go is absolutely preferred by people building real solutions to real problems. Pure, idealized languages like Haskell seem to be preferred by people who don't actually do anything with it, but instead talk about it. It is the "big brother" language.

I don't mean this dismissively, though it invariably sounds that way, but there is a huge divide between things that actually get things done, and things that you can debate the intricacies of for weeks on end while you foment that grand plan that you'll never actually pursue.

Though I will add that your nonsensical, ignorant simplification and mischaracterization of Go merely belies the fact that you have virtually no real knowledge of it at all, beyond probably some rubbed off "knowledge" from advocacy boards.

Re:Go generate: A proposal for a Go preprocessor by codygman on Sunday September 28, 2014 @03:07PM (#8380622)
> Pure, idealized languages like Haskell seem to be preferred by people who don't actually do anything with it, but instead talk about it.

Please stop, you're making yourself look stupid. Plenty of people create real solutions to real problems in Haskell every single day.

Re:Go generate: A proposal for a Go preprocessor by personZ on Sunday September 28, 2014 @07:06PM (#8381143)
Unsurprisingly, you and frowaway both average less than 2 on your comments.
Re:Go generate: A proposal for a Go preprocessor by frowaway001 on Sunday September 28, 2014 @07:55PM (#8381232)
You understand the difference between being right and being popular?

Because you like fancy numbers, let's assume you probably rate a 7 on being butthurt.

Re:Go generate: A proposal for a Go preprocessor by personZ on Sunday September 28, 2014 @08:08PM (#8381258)
FWIW, that is the argument that people living in bubbles of ignorance use to justify their positions. Everyone else is just wrong.

Be sure to log into your alt now. I have a feeling you go through accounts to evade hellbannings.

Re:Go generate: A proposal for a Go preprocessor by frowaway001 on Sunday September 28, 2014 @08:18PM (#8381275)
I guess 7 is way too low. :-)
Re:Go generate: A proposal for a Go preprocessor by blablabla123 on Saturday September 27, 2014 @08:48AM (#8376877)
There have been many lengthy disucssions about generics on the Go mailing list. Haven't checked them in a while but the essence used to be that generics are difficult. C++ has really powerful generics but unfortunately C++ templates are in many respects a nightmare. Java templates on the other hand are not really powerful. The idea was to wait until someone would come up with a powerful generics concept that is nice for the developer.
Re:Go generate: A proposal for a Go preprocessor by pjmlp on Saturday September 27, 2014 @09:34AM (#8376968)
Generics exist in multiple forms since CLU (1974).

To reduce them to what C++ and Java implementations offer, is just being ignorant from history of programming languages.

Re:Go generate: A proposal for a Go preprocessor by frowaway001 on Saturday September 27, 2014 @01:23PM (#8377588)
> being ignorant from history of programming languages

Isn't that Go's design principle?

Re:Go generate: A proposal for a Go preprocessor by NateDad on Saturday September 27, 2014 @02:14PM (#8377736)
People in the 70's knew a lot more about programming than you seem to think.
Re:Go generate: A proposal for a Go preprocessor by frowaway001 on Saturday September 27, 2014 @02:42PM (#8377804)
Yes, but they weren't so self absorbed to dismiss the 40 years of experience in front of them.
Re:Go generate: A proposal for a Go preprocessor by NateDad on Saturday September 27, 2014 @02:56PM (#8377850)
Not all languages need to have all the features of Haskell or Rust. Just as not All languages need to be dynamically typed. Just because a language is missing your favorite feature(s), doesn't mean it's a bad language. And maybe you have tried writing programs in go and didn't like it. That's fine. But there's no need to insult everyone who uses language. Every language has its niche, even perpetual punching bags like vb and php.
Re:Go generate: A proposal for a Go preprocessor by frowaway001 on Saturday September 27, 2014 @05:33PM (#8378274)
That's a nice strawman you are beating there.

> But there's no need to insult everyone who uses language.

Is that from Go's social media handbook? I have never ever seen users of a language complain about perceived insults as consistently as Go. It seems like it's the only argument they are able to make if they disagree with other people.

Re:Go generate: A proposal for a Go preprocessor by NateDad on Saturday September 27, 2014 @07:11PM (#8378459)
So you weren't trying to be insulting when you said people that like go want to live the 70's and are happy with java 1.0? Was that a compliment?
Re:Go generate: A proposal for a Go preprocessor by frowaway001 on Saturday September 27, 2014 @07:53PM (#8378513)
It's a frank assessment of reality.
Re:Go generate: A proposal for a Go preprocessor by NateDad on Sunday September 28, 2014 @08:26AM (#8379560)
From a throw away account? That's cute.
Re:Go generate: A proposal for a Go preprocessor by frowaway001 on Sunday September 28, 2014 @10:39AM (#8379838)
The only thing cute is the way you are desperately trying to come up with ways to turn "I don't like what you say" into "it's wrong what you say" in your head. :-)
Re:Go generate: A proposal for a Go preprocessor by zuzun on Saturday September 27, 2014 @08:14AM (#8376807)
So how many programming languages besides LISP are powerful enough to support turning Protocol Buffers into code during compilation? And is this the ultimate must have?
Re:Go generate: A proposal for a Go preprocessor by logicchains on Saturday September 27, 2014 @09:09AM (#8376915)
It could be done in OCaml or Haskell, considering they both have compile-time AST generation/manipulation, but I'm not sure if anyone's written an actual implementation of this. Nimrod too, as that has AST macros. As does Elixir.
Re:Go generate: A proposal for a Go preprocessor by pjmlp on Saturday September 27, 2014 @09:36AM (#8376971)
D, Rust, Nim(rod), Template Haskell, OCaml, C++...
Re:Go generate: A proposal for a Go preprocessor by mseepgood on Saturday September 27, 2014 @09:43AM (#8376996)
I don't think these can open and read .proto files during compilation.
Re:Go generate: A proposal for a Go preprocessor by pjmlp on Saturday September 27, 2014 @10:05AM (#8377043)
D has meta-programming and compile-time evaluation, including reading files.

I bet C++ can do it with some clear use of template metatprogramming, compile time evaluation and processor macros.

Nim has meta-programming capabilities, including reading files.

Not sure about Template Haskell, though.

Re:Go generate: A proposal for a Go preprocessor by thesz on Saturday September 27, 2014 @01:47PM (#8377662)
Template Haskell code can runIO I/O actions, including reading files.
Re:Go generate: A proposal for a Go preprocessor by pcwalton on Saturday September 27, 2014 @09:44AM (#8377005)
Rust can.
Re:Go generate: A proposal for a Go preprocessor by tuxychandru on Saturday September 27, 2014 @01:28PM (#8377606)
Are you referring to compiler plugins like the one providing regex! macro or is it something else?
Re:Go generate: A proposal for a Go preprocessor by wycats on Saturday September 27, 2014 @02:48PM (#8377825)
Yes, compiler plugins. For a relevant example, check out the Rust docopt crate[1].

An identical technique could be used for yacc or protobufs.

[1]: https://github.com/docopt/docopt.rs

Re:Go generate: A proposal for a Go preprocessor by jeremyjh on Saturday September 27, 2014 @10:28AM (#8377095)
Haskell can, but there is not an implementation that does this.
Re:Go generate: A proposal for a Go preprocessor by hawkice on Saturday September 27, 2014 @01:28PM (#8377605)
To be clear for the Haskell newbies, he's talking about an implementation of the protobuf library, not Haskell. You can fairly easily lift from Template Haskell types into IO in GHC (not sure about TH in other compilers).
Re:Go generate: A proposal for a Go preprocessor by ben0x539 on Saturday September 27, 2014 @11:36AM (#8377276)
F# type providers sound like they're for this sort of thing. I expect Scala has a similar macro facility. Nemerle can probably do it too.
Re:Go generate: A proposal for a Go preprocessor by NateDad on Saturday September 27, 2014 @01:20PM (#8377576)
I don't want my language to be that complicated. "Powerful" has nothing to do with it.
Re:Go generate: A proposal for a Go preprocessor by tptacek on Saturday September 27, 2014 @09:19AM (#8376940)
It sounds like this is just a clean way to run yacc and protobufs. And: using yacc from Golang programs is in fact ugly right now; it's actually a little worse than it is in C. I think you should just take this document --- whatever it's provenance --- at face value.
Re:Go generate: A proposal for a Go preprocessor by 4ad on Saturday September 27, 2014 @09:43AM (#8377000)
> using yacc from Golang programs is in fact ugly right now

Why do you say that, and how does this mechanism affect the use case you have in mind? You run go generate instead of make. The advantage is that you don't have to have make; e.g. Windows and Plan 9 don't have make. Arguably, the advantage is pretty minor, but I don't see how it changes anything in your workflow.

Remember that go generate does not run at build time. You still have to run it manually when you want it (just like before, with make) and commit the generated files into your repository.

Re:Go generate: A proposal for a Go preprocessor by tptacek on Saturday September 27, 2014 @09:44AM (#8377002)
It's possible that I am just missing a trick that everyone else who uses Golang knows, but I never use "make" with go.

(That's what makes yacc so much simpler with C; it's just another Makefile production.)

Re:Go generate: A proposal for a Go preprocessor by marcus_holmes on Saturday September 27, 2014 @11:42AM (#8377291)
I had to choose: Make or Grunt, I chose Grunt

Grunt support for Go is patchy, the one package I found is no longer supported, but as I'm writing web stuff the real thing I needed was to do with js compression and obfuscation - I want to deal with nice easy-to-read js files in dev but I don't want to waste my customers' bandwidth delivering comments to their browser.

I understand the argument for go generate as a resolution for some of the problems with no generics (and yes, Go's type system is a bitch. I love the language but rewriting everything for each individual structure gets old fast). I can see how generating boilerplate ORM-a-like code would be great.

So the argument that go generate is somehow a replacement for make leaves me a bit puzzled. I mean, yes, you could do that, but why?

Re:Go generate: A proposal for a Go preprocessor by tptacek on Saturday September 27, 2014 @12:51PM (#8377500)
Am I missing how to make this process work with the idiomatic Golang build system? Can I use "make" or "grunt" to create a package that someone else can "go get" and build without using a third tool?
Re:Go generate: A proposal for a Go preprocessor by NateDad on Saturday September 27, 2014 @01:08PM (#8377537)
Go generate is for package authors, at which point you check the results into your repo. Then anyone else can go get your package as a dependency and not need to regenerate that code. So, yes.
Re:Go generate: A proposal for a Go preprocessor by 4ad on Saturday September 27, 2014 @09:56AM (#8377023)
It's not uncommon in Go programs to have makefiles (or shell scripts) that make some transformation to the code. This imposes no burden to the user since the generated files are checked into the repository, but it does put some burden on the developer (who has to run make), or to the prospective contributor, who not only has to have make, but potentially has to have all other tools invoked by make or learn the varying non-standard mechanism by which code is generated (e.g for the Go project itself, a new developer has to learn how to use the various shell and perl scripts that generate the code in the syscall package).

Go generate does not eliminate this burder for the developer. Someone still has to write the yacc invocation and remember to run it; it won't know how to run itself, but it has the advantage that now there is a standard canonical way to generate code. Anyone can just type go generate instead of learning about makefiles or shell scripts or whatever the project is using. Code generation is normalized under the go generate umbrella.

Re:Go generate: A proposal for a Go preprocessor by jasode on Saturday September 27, 2014 @10:54AM (#8377160)
>If this is seriously their proposed solution to the lack of generics then my estimation of Go just dropped even further.

On a related note, in one of the videos with Rob Pike (audience q&a I think but can't remember if it was GopherCon2014 or other event), he specifically mentions external "code generators" as a workaround for lack of generics.

If anyone (not saying you specifically) is saying that the Go team is proposing code generators as the solution instead of a workaround to lack of generics, that would be an inaccurate reading of their position.

Re:Go generate: A proposal for a Go preprocessor by weitzj on Saturday September 27, 2014 @11:37AM (#8377279)
I heard something similar from a talk about Youtube Vitesse at Fossdem 2014. They are suggesting gofmt for rewriting.
Re:Go generate: A proposal for a Go preprocessor by NateDad on Saturday September 27, 2014 @11:09AM (#8377191)
It's not about generics. It's just a helpful part of the tooling to do some stuff before you compile. Like many projects already do, this just standardizes it.