18 ms·
The ups and downs of porting 50k lines of C++ to Go (2015)
- PudgePacket 8y ago> Posted on March 7, 2015
- dang 8y agoAdded. Thanks!
- PudgePacket 8y agoNo worries.
- wglb 8y agoArticle from 2015.
- dang 8y agoDiscussed at the time: https://news.ycombinator.com/item?id=9161366 https://news.ycombinator.com/item?id=9161366
- tschellenbach 8y agoSwitched from Python to Go about 2 years ago. If you need to build performant APIs with a small team there is nothing that comes close. You get the productivity of something like Python with the performance of C++. Or at least very close to it in both cases. (https://getstream.io/blog/switched-python-go/ https://getstream.io/blog/switched-python-go/) The lack of generics hasn't bothered me so far. You just find different solutions to the problem. Composition, interfaces, or if all else fails an empty interface{}. It's rare to really not be able to work around it. It does make it near impossible to build reusable and performant data structures in Go though. (say that you want to build your own heap or list, hashtable etc.) So that's annoying, but something that you rarely run into. Bigger issue is that GO modules are still not ready for production since the ecosystem didn't catch up: https://github.com/golang/go/issues/24661 https://github.com/golang/go/issues/24661
- apta 8y ago> If you need to build performant APIs with a small team there is nothing that comes close. The JVM and .NET think otherwise.
- kjksf 8y agoAnd yet Go pretty much ate the lunch of C# and Java when it comes to backends and devops, despite the fact that both had a decade of head start and generics and large dev teams behind them. I like C# and Java, certainly much more than C++, but Go hit that sweet spot of little ceremony (try to write a single file Java or C# program), performance, deployability (again, try to deploy a Java or C# program as an Ubuntu service on a low-end 512 MB Digital Ocean host or provide a Java or C# cmd-line program to a Mac user) and programmer productivity.
- adrianN 8y agoWell yeah, Google uses Go, so clearly it must be the best technology out there! Why would a hip startup use crusty old enterprise technology like Java?
- ilovecaching 8y agoPeople have a lot of valid concerns about using a technology owned by Oracle, and the 2000s ended up leaving a bad taste in people’s mouths from the amount of enterprise shilling that went into Java. Now Java is showing it’s age and cross compiling is no longer the problem it once was.
- geezerjay 8y agoNone of your arguments were objective or technical, and you've missed the fact that the Java is by far the standard in backend development and more importantly is taught in universities. Honestly, the only ads I see for Go developers are for blockchain projects, which suggest buzzword-driven development.
- atomical 8y agoOccasional pauses of 400-500 milliseconds? How would one mitigate that when coding a restful API server?
- fwip 8y agoYou could wait until $current_year, in which GC pauses are about 50 microseconds.
- Rapzid 8y agoThis article is pretty old. If this is from garbage collection, Go has more than addressed this with <100 microsecond stop the world in "typical worse case" scenarios. I believe it also tries to spread out the work to provide consistent latency.
- easytiger 8y agoMy, possibly incorrect understanding, is that it had implemented hard time max pause durations, which will only lead to an infinite amount of garbage under some use patterns. Given the point if gc is you doubt think about it that's bad. Giving go a gc was a total design failure
- majewsky 8y agoGo's GC is the best GC I've seen in practice. It's just silently working in the background without causing visible interruptions. And contrary to what you imply, I've never seen the GC cause memory leaks.
- visviva 8y agoFour years old and the typo in the title still hasn't been fixed?
- chewxy 8y ago> Readability. I always found the Go code I encountered quite easy to read and understand, both our code and external code. Some of the C++ I encountered, in contrast, took hours to fully comprehend. Go also forced me to write readable code: the language makes it impossible to think something like “hey, the >8=3 operator in this obscure paper on ouroboromorphic sapphotriplets could save me 10 lines of code, I’d better include it. My coworkers won’t have trouble understanding it as the meaning is clearly expressed in the type signature: (PrimMonad W, PoshFunctor Y, ReichsLens S) => W Y S ((I -> W) -> Y) -> G -> Bool”. This sentence is gold J
- millstone 8y agoI don't get the "Go is easy to read" notion. Here's the recommended way to work with slices: [1]: Delete from a slice: `a = append(a[:i], a[i+1:]...)` Copy a slice: `b = append([]T(nil), a...)` Pop from a slice: `x, a = a[len(a)-1], a[:len(a)-1]` And some of these are discouraged because they leave you vulnerable to memory leaks (?) These are fundamental building blocks and they're really quite bad. I mean when you're using `append` to delete... 1: https://github.com/golang/go/wiki/SliceTricks https://github.com/golang/go/wiki/SliceTricks
- nemo1618 8y agoDeleting from a slice is ugly and awkward because it's slow. Go, like C, confronts you with the real cost of what you want to achieve. A builtin like 'delete(a, i)' looks like an O(1) operation, when in reality it's O(n).
- janekm 8y agoA more developer-friendly language like Swift would give you an ArraySlice type with performant views on arrays, and developer-friendly syntax.
- edflsafoiewq 8y agoIn what way does delete(a, i) look like an O(1) operation? It looks like a function call. You can never just look at a function call and see its complexity. You make it sound like deleting an element being ugly is a design choice, but it can't be a choice since there is no alternative. Swap-and-pop is O(1), but it's ugly too.
- RhodesianHunter 8y agoComing from JVM languages, it drives me nuts that I can't .map/.filter/.foreach/.reduce etc. my collections, especially with something like streams/sequences. That's where you really notice the lack of generics if you're used to this sort of programming.
- chewxy 8y agofunny thing I wrote this on the morning commute to work - https://twitter.com/chewxy/status/1105962162021756928 https://twitter.com/chewxy/status/1105962162021756928 Not that I'm saying that Go should not have functional features - it does, but it also forces you to think more deeply on things.
- nemo1618 8y agoCheck out my experiment with adding map/filter/reduce to Go: https://github.com/lukechampine/ply https://github.com/lukechampine/ply Ultimately I concluded that map/filter/reduce really need to be paired with a concise lambda syntax in order to be ergonomic. Writing out a full func() literal doesn't feel much cleaner than just writing a traditional for loop. However, adding a new lambda syntax would be a much larger undertaking than I can manage right now. The other thing I concluded is that you can highly optimize map/filter/reduce chains if they're first-class citizens of the language, rather than living in a userspace library. I was able to compile such chains into for loops that are more efficient than what a novice might write, and no worse than what an expert would write. The only way to improve would be to inline more aggressively, i.e. inline "x += 2" instead of calling out to "addTwo()" on each iteration of the loop. I think there's an unfilled niche in programming languages that's basically "Go plus some FP niceties." I love Go's simplicity, tooling, and performance, but writing endless for loops and error-handling blocks gets tiring and can obscure the operation you're actually trying to achieve. At the same time, jumping to full-blown generics, macros, etc. like Rust introduces too much "magic," hurts readability, and bloats compile times.
- jonahx 8y ago> I think there's an unfilled niche in programming languages that's basically "Go plus some FP niceties." Nim?
- agentofoblivion 8y agoI wonder how Dlang would have compared.
- zerr 8y agoD is superior in every aspect except the BigCo support.
- agentofoblivion 8y agoWhy do you think that is (the lack of BigCo support)?
- zerr 8y agoBecause Walter Bright is/was not working at Google, Oracle or Microsoft? :)
- arthurcolle 8y agoUps and downs?
- nayuki 8y agoThis HN item links to the blog's front page. The actual article is at https://togototo.wordpress.com/2015/03/07/fulfilling-a-pikedream-the-ups-of-downs-of-porting-50k-lines-of-c-to-go/ https://togototo.wordpress.com/2015/03/07/fulfilling-a-piked...
- jondubois 8y ago>> The worse the abstraction that you and your colleagues are likely to use, the better a language is Go I feel the same way about most statically typed languages. They're designed for developers who aren't good at coming up with abstractions. Basically, they're great for junior developers. For senior developers, they just give you more work and slow down progress. On my last project (statically typed language), we had to do a refactoring of a decent portion of the code just because it allowed us to use one interface/type instead of two related interfaces/types (one inheriting from the other). It didn't fix any bugs, make it more maintainable or even change the external behaviour at all.
- networkimprov 8y agoAnother gent who asserts that languages he likes to use are better for "senior developers" while those he doesn't are better for "junior people". Don't hire anyone who makes such insulting remarks.
- jondubois 8y agoWhy is it insulting? I didn't say that using the language means that you're a junior. I just said that it was designed for juniors. Just like there are adults who wear diapers, it doesn't mean that they're juniors. In fact, most of them are very senior. They just like to be on the safe side.
- PointersAreFun 8y agoOh, you need dynamic typing? Why? Can’t you do without types? You need a language to hold your hands for you? I program in B, I don’t need a language, compiler or runtime to hold my hands. The CPU word is all you need, and if you can’t do with that, then you are a toddler who wears a diaper.
- GenericsMotors 8y agoGents, this ^ is what "full retard" looks like.
- herf 8y ago> he expected the language to be adopted by C++ programmers, a prediction that hasn’t been realised I respect go (and its runtime) a lot, but one little thing keeps me from using it: the reverse "argument type" ordering (backwards from C++) makes me avoid it. If this were the only language I used, it would be easy, but when switching back and forth, does anyone else find it hard to do?
- abvdasker 8y agoMy job requires switching between Go and Java occasionally. While I think Go is slightly more natural, it definitely adds cognitive overhead when going back to Java. But that additional overhead is nothing compared to the rampant and indecipherable stringing together of Guava futures in my company's Java codebases.
- fiddlerwoaroof 8y agoThe newer jvm languages (particularly thinking of Kotlin and Scala) though, generally are type-second languages.
- creatornator 8y agoThis is one of the easier things to get used to-- I don't find "code switching" between syntaxes to be difficult at all, especially if you are already looking at a codebase and can visually copy what's already there. It even makes some sense, if you read it as "variable foo is a bar".
- nicoburns 8y agoMost newer languages are like this: Go, TypeScript, Rust, Swift, Kotlin, Scala, Nim, etc. Admittedly most of these languages use a colon like `name: type` rather than plain `name type`, which helps readability a lot IMO. But you would unlock a lot of languages if you are able to get used to this style. Personally I find the `type name` style confusing. It's ok for variables, but it's super-confusing for function definitions where most language use a dedicated keyword (`function`, `fun`, `fn`, `def`, etc).
- deleted 8y ago[deleted]
- networkimprov 8y agoFor anyone bothered by Go's simplistic error handling, a menu of Requirements to Consider for Go 2 Error Handling: https://gist.github.com/networkimprov/961c9caa2631ad3b95413f7d44a2c98a https://gist.github.com/networkimprov/961c9caa2631ad3b95413f... See also the Go 2 Draft Design feedback wiki: https://github.com/golang/go/wiki/Go2ErrorHandlingFeedback https://github.com/golang/go/wiki/Go2ErrorHandlingFeedback
- deleted 8y ago[deleted]
- alfalfasprout 8y agoWow, I'm surprised to see the typical "Well, why didn't you just use Rust" comment hasn't been posted. At the end of the day, it sounds like they just had some clunky C++ code that was due for a rewrite anyways (and the author admits as much). If you don't need it to be ultra low latency, some nice abstraction and modularity can already do wonders. I've found Go to be an excellent Java replacement when all is said and done. Great for the vast majority of services you might write. But if you need to do anything lower level or that involves complex type logic you always end up with a clunky solution (and I'm not going to sing any praises for C++ having an elegant solution either). That said, modern C++ (especially 17) can be made to look decently clean and without weird behavior in most cases. Yes, there's always the person that shows up and points out weird edge cases that you can run into but the situation is far, far better than it was years ago. With some good engineering practices in encapsulating low level optimized code you can largely limit the "danger surface" of your codebase.
- pjmlp 8y agoWhen Go gets around supporting Java generics, dynamic loading, JDBC, PDF generation libraries, Office/LibreOffice manipulation libraries, Akka, CMS platforms, BluRay/SIM CPUs, a phone OS, a GUI library comparable to AWT (lowering the level as Swing/JavaFX/Android aren't even around), JMX instrumentation, hot code replacement.... then maybe just maybe, it is an excelent replacement for Java.
- laumars 8y agoI can't tell if it's intentional but your post borders on fanboyism given about 80% of what you listed there is either already available for / possible in Go or is a Java specific term so naturally Go would have it's own mature libraries out there under a different name. For example * JDBC, Akka, etc There as all Java specific technologies but that doesn't mean that Go (nor any other language) doesn't have their own libraries to do the same. I mean you're not going to call Go's database libraries "Java Database Connectivity" are you * PDF generation libraries, Office/LibreOffice manipulation libraries, CMS platforms, Go already has all that * a phone OS, There isn't any phone OS's written in Java either. There are phone OS's that use Java as their preferred application runtime environment - such as Android - and many of them can and do support running Go binaries as well. There is in fact a lot of documentation online regarding running Go on Android. --- I'll grant you that Go doesn't have hot code replacement nor generics but the former is a pretty niche case for Java development that wouldn't really improve Go's current workflow anyway - and the latter is such an tired old argument that you're not going to win any debates by pointing it out. Disclaimer: I've programmed in both Java and Go (as well as more than a dozen other languages too). So I'm about as agnostic as they come when it comes to evaluating programming languages.
- kristianp 8y ago"one of my reasons for getting into programming was the opportunity to get paid to use Emacs". Not a reason for getting into programming that many have, I expect!
- ilovecaching 8y agoI personally love Rust and think Rust is the future for C and C++, and use it professionally. But Go is simple, fun, fast, and easy to read and frankly more approachable by the people many companies can afford to hire. I view language choice as a line. If I need to build big, or build niche, or build fast, I use Rust. But if it’s general purpose I use Go. I can write Go faster than I can write Python because the type system gives me a fast feedback loop and the language is simple and builds in the common case building blocks. I can get better performance and understand my app better than with the JVM because it’s compiled ahead of time and I already know the ins and outs of Linux. There is no black box JVM that consumes resources while idling. Go has advanced the state of formatting, documentation, and revitalized the Unix philosophy of building small, focused pieces without getting caught in the clouds over abstracting. If you are currently using a Python, Java, C#, or JavaScript, Go is better. Just don’t post angrily to your blog until you’ve written Go while also embracing its philisophy and taking the time to understand the authors intentions.
- therein 8y agoAgreed. It is probably also the perfect introductory language to introduce someone to programming with while also being extremely useful even for complex programs. I think an intro to CS course would be a lot more fun for everyone involved if it were taught in Go rather than Java like it did in back in my college just half a decade ago.
- winterismute 8y agoDo you/anybody know of any solid project that aims at porting/re-developing in Go at least some of the statistical learning tools that we have in python? I did not find much when I looked last time, but it might have been more than a year ago.
- blub 8y agoGo is at this point used for tools and containers. Maybe back-ends. Trying to use it for data science is a waste of ones time, the language is particularly poor at expressiveness. Any of the allegedly worse languages above (C#, Java, Python) are better at this.
- rienbdj 8y agoAfter switching to ML languages for most development tasks, I don’t think I could face using a language with so few features. Is most of the hype from a dev ops perspective? Go looks tiresome to program in.
- coldtea 8y agoWell, there's some blub paradox (PG) at play. As Go team found out, it's not like people go from C++, OcamL or other full featured languages to Go. For Python/Ruby etc programmings coming to Go, the lack of features feels exciting, because it makes them think they're programming closer to the metal (what with types, and static compilation, and contiguous arrays, and pointers).
- blub 8y agoGo does have some benefits. In my case, cross-compiling into one binary means it could be the easiest way to build and deploy on an embedded platform where I normally use a quite complex to set up C++ toolchain. At the same time Go's a typical "sidekick" language, because it's really good only at a few things, unlike C++ or Java which are useable for almost everything.
- laumars 8y agoI've written stuff in C++ as well as Python. The simplicity of Go appeals to me because it means the code is generally more readable (eg people aren't abusing advanced features quite so much). Anecdotally I've found reading other peoples Go code far easy than I've found reading other peoples code in pretty much any other language. YMMV though
- adgasf 8y agoThat can happen. However, when you do not have the proper language features (e.g. pipe operator) then code can become much less readable because it is more verbose and the control flow is unclear. I think that simple languages only lead to more readable code when the problem domain is also simple.
- stesch 8y agoLink to the article instead of the blog: https://togototo.wordpress.com/2015/03/07/fulfilling-a-pikedream-the-ups-of-downs-of-porting-50k-lines-of-c-to-go/ https://togototo.wordpress.com/2015/03/07/fulfilling-a-piked...
- johnvega 8y agoI'm a C++ programmer for over 10 years and looking forward to becoming a Go programmer, professionally.