Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Okay, protocol buffers are awesome, so as constructive feedback, I think using C++ as the source-generation language is a mistake.

We use Thrift, which uses the same approach, and it's a huge PITA to install the native compiler just to generate some .java files. To the point where, unlike basically everything else, we don't run the thrift compiler locally on dev machines, but instead run it on a Hudson machine with thrift carefully setup and then hope we never have to touch it.

Granted, the runtime library for each language needs to be in that language (or more likely it's C/C++ bindings), but jumping from "the runtime is probably C/C++ under the covers" to "let's use C++ to generate the source code" is a mistake IMO.

Personally, with Thrift, it has kept me from submitting pull requests to help patch/maintain the generated Java bindings (which were pretty bad at one point in time).

Along the same lines, I haven't used it yet, but I'm a wanna-be fan of Scrooge, which uses the Thrift runtime libraries, but does it's own source code generation:

https://github.com/twitter/scrooge

I'm not necessarily saying each language's source code should be generated by a program that is also written in that language, as I understand it's nice to reuse the IDL/spec parsing logic ... but, on the other hand, I think that would maximize the quality of each language's generate source code, since the barrier for it's own users to maintaining/tweaking would be so much lower.

(I understand you live & breathe C/C++, this feedback is just from a "if you want to maximize potential contributions to your project" point of view.)



I absolutely agree, which is why the Cap'n Proto compiler is written in Haskell. :D


Ha, nice! Sorry about that--you caught me skimming the navigation bar and making/projecting assumptions. :-)


Now that does put me off from contributing...

(Not a criticism, just a reference to the GP.)


Aww. Seriously, though, it's pretty easy to write a code generator without understanding Haskell, and most of the work ends up being in the target language.

In the long run I'd like to do something like I did with protoc where you can write plugins in any language, but... more important priorities right now.


What about using Go?


What would be the benefit of Go over Haskell in this case?


If you use Java with Thrift, you should check out Swift:

https://github.com/facebook/swift

Swift is an annotation-based library for creating Thrift types and services. It was created to be an alternative to code generation, which is generally a pain for Java development. Swift generates bytecode at runtime, so you get all the performance advantages of code generation with none of the development disadvantages.

The idea with Swift is that you own the annotated classes and can fully customize them to your liking, independent of the IDL and wire format. For example, you can name the methods whatever you want, add documentation, helper methods, etc. When implementing a client for Thrift service, you only need the methods that you actually call.

You can use swift-generator-cli to generate the initial versions of the classes from existing Thrift IDL, which you then customize and maintain yourself. Alternatively, you can use swift-maven-plugin, which is pure Java (no external C++ binary), to generate code at compile time.

This project is in active development and use at Facebook, so please give it a try and let us know what you think!


I completely disagree. C++ is a great general purpose languageand 99% dev machines will have a compiler installed. I know mine doesn't have Java installed.


But do you have the right version of Boost installed? And does it work with both g++ and clang? Which standard library? Etc.

C or very light use of C++ makes most sense for sad reasons.


But you would likely have Java installed if you were interested in generating Java language bindings.


Very good point, very well made.


Hah, there are tens of millions of professional developers out there. The majority of them use Windows and don't have a C++ compiler installed. Look outside the bubble ;)


> it's a huge PITA to install the native compiler just to generate some .java files

I use Thrift too and haven't felt this pain myself. The compiler is easy to install with APT, MacPorts or the usual `./configure && make install` incantation. This said, I would certainly appreciate an implementation of the compiler running on the JVM.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: