10 ms·
Can someone give me a compelling reason to start programming in Go? My default language at the moment is C, or C++.
by _RPM 12y ago
Can someone give me a compelling reason to start programming in Go? My default language at the moment is C, or C++.
- bradfitz 12y agoYou can also add numbers on an abacus. It _works_. Put in a less snarky way, C is often way more low-level and tedious than you need. The great thing about Go is that it lets you blend high-level and low-level programming in the same program, only getting low when you need to. It feels like a great mix of C and Pythonubyerlhphavascript. I've given many talks on this, e.g. http://talks.golang.org/2014/gocon-tokyo.slide#1 http://talks.golang.org/2014/gocon-tokyo.slide#1
- coldtea 12y ago>You can also add numbers on an abacus. It _works_. Well, I wouldn't go there (C is antiquated/under-equiped like an abacus) if I was advocating Go. After all, Go, just like an abacus doesn't have generics, or, besides channels and goroutines, most other facilities modern languages offer for that matter (GC and some basic data structures built-in is so 1980).
- lazyjones 12y ago> Go, just like an abacus doesn't have generics, or, besides channels and goroutines, most other facilities modern languages offer for that matter If you need mainly a large number of features in order to program, Go probably isn't for you. But from the perspective of a C/C++ programmer, this isn't likely to be an important point. Languages with more features than C have been available for 40 years (depends on what you'd count as a feature), so there were plenty of "better" choices in that regard available for said people. For me, the lack of some "features" is a great asset for Go, I probably wouldn't have bothered to learn a new language if it had boasted the complexity of Rust or Haskell.
- jacques_chester 12y ago> The great thing about Go is that it lets you blend high-level and low-level programming in the same program Where are map, reduce, select, filter, fold, zip ...? I don't consider hand-rolling them in for/range as equivalent. Can I wind up with the same result? Yes. But I could do it with gotos too. And I've seen "loops are the same as map/reduce etc" advanced as a serious argument by people who weren't, so far as I could tell, trying to tug on my leg.
- NateDad 12y agoMost of the questions about "how do I do X in Go?" are answered with "just write a loop". Yes, that means map/reduce, filter, fold, zip, etc. If writing simple loops gets your hackles up, Go is not the language for you. For me, I worry about the hard stuff, not easy loops.
- jacques_chester 12y ago> If writing simple loops gets your hackles up, Go is not the language for you. What gets my hackles up is claiming that "it's just the same". The same argument works for any language that satisfies the structured programming theorem, including assembler. "If writing simple BNE $reg gets your hackles up, Assembler is not the language for you."
- NateDad 12y agoFor most people's uses, it's the same. Certainly, there can be performance benefits if your language's implementation uses lazy evaluation and you have a very large list and you only need to evaluate a small portion of the list... but in my experience, that is very rarely the case in real programs.
- jacques_chester 12y ago> For most people's uses, it's the same. I look forward to seeing how I can chain multiple operations on a set into a single line of Go.
- alfiedotwtf 12y agoNot having to use Java on Android. This is a major reason. (it's going to interesting to see battery life of not running an interpreted language on small devices like Android Wear).
- cnbuff410 12y agoFor Go, I don't think what you need is a compelling reason from someone else. One compelling reason to one is not necessarily compelling to others. Instead, since Go is a very simple language with very easy learning curve, I encourage you to spend a weekend to check it out. Pick a side project and do it in Go, then you will know if it's the language for you. I would even argue that the joy of writing Go would be magnified by working as a team and the joy of reading Go would be demonstrated by exploring any Go project from any team. But I would not go that far for a Go novice who just want to check it out
- mholt 12y agoOnce Go is installed, I can make a simple web app from scratch that displays parameters from the URL or request body in just over 95 seconds with Go, using only the standard library. I can cross-compile it for another OS and architecture, then deploy a single binary file without worrying about dependencies, dynamic linking, or segfaults. Try doing that in C/C++. Maybe a better comparison is to more systems-level applications like you might code up in C. The same benefits carry over to those, without a significant performance hit (usually). (And to be fair, sometimes C/C++ is the better tool for the job. But give it a shot; Go is pretty handy when you don't need to drop down to lots of unsafe memory and CPU operations.) By the way, your existing C skills will be very useful in Go. For example, struct fields will still be padded unless you pack them carefully. Your experience with buffers, streams, memory allocation, and data structures will definitely not be wasted in Go.
- howeman 12y agoAnd if you want to use external code, you can download it with and integrate it into your main package in about 90 seconds (go get + go install). In order to learn to use it, godoc is there.
- cheepin 12y ago> Once Go is installed, I can make a simple web app from scratch that displays parameters from the URL or request body in just over 95 seconds with Go, using only the standard library. I can cross-compile it for another OS and architecture, then deploy a single binary file without worrying about dependencies, dynamic linking, or segfaults. Try doing that in C/C++. NodeJS runs on top of C++ :P
- zyang 12y agoA really crisp way to model concurrency. Most real world performance problems stem from the inability to model concurrency correctly. I also found it's faster to read the library code than the docs. A lot of thought has gone into making the language and library clean and easy to understand.
- vowelless 12y agoConcurrency is the most compelling reason. You will miss templates though. Try experimenting with the concurrency and network communication stack in the go standard lib.
- gtani 12y agothere's lots of old HN threads and a blog and a couple books to give you the flavor (and yeah some people are less than enthusiastic); also Oreilly and Manning are coming out soon with "In Action" books, you can read a 8 of 14 chapters draft: https://news.ycombinator.com/item?id=8332835 https://news.ycombinator.com/item?id=8332835 https://news.ycombinator.com/item?id=8356677 https://news.ycombinator.com/item?id=8356677 http://blog.senko.net/learning-go http://blog.senko.net/learning-go _________ Books: http://golangbootcamp.com/ http://golangbootcamp.com/ http://openmymind.net/The-Little-Go-Book/ http://openmymind.net/The-Little-Go-Book/ http://www.manning.com/ketelsen/ http://www.manning.com/ketelsen/
- pentelkuru 12y agoYou should be able to get up and running with Go extremely quickly if your default language is C. If there's a reason you must be using C rather than another language (require manual memory management, require code to be as fast as possible, etc.), then Go might not be applicable. Otherwise, Go feels like an updated C and I don't see a compelling reason not to invest a little time in checking it out for yourself.
- draven 12y ago> require code to be as fast as possible It's also pretty easy to write the performance critical parts of the code in C and call them from Go.
- NateDad 12y agoYes but you really almost never need to do that. The speed difference is usually only a factor of 2ish... It's not like the factor of 10-30x for interpreted languages.
- Jweb_Guru 12y agoThis will likely not have the desired effect if you are calling into the C code from within a tight loop. Go's C FFI is not low overhead.
- wyager 12y agoIf you're doing networking, it's worth looking into. It has a good standard library with good networking features. It has pretty solid concurrency primitives. Beyond that, I would not recommend it. I think a lot of people get caught up in the fact that A) it's hip and new and B) it's managed by Google. Without knowing what you want to do with it, I would recommend any number of languages (Rust, Haskell, Julia, etc.) before learning Go.
- MichaelGG 12y agoIf you're using C/C++ and need the performance, look at Rust. Fairly expressive, good type system (and they figured out generics), and C++ like or better performance. All the power of manual memory control, with none of the downsides.
- chaotic-good 12y agoIt's too complex, we're already have C++.
- Dewie 12y agoI was at a lecture about security in C/++ code a couple of weeks ago. His conclusion was basically: > There are no silver bullets with regards to safety in C/++ code; in order to achieve security, the programmer has to pay the price of being forever vigilant. A lot of the complexity of Rust is for eliminating security pitfalls which are inherent in C/++.
- chaotic-good 12y agoIt is common to use ARC and unsafe shared memory access in Rust. This defeats the purpose of this complexity. You can't isolate unsafe memory access. You rather write only memory safe code or end up with fully unsafe codebase where some nasty things (buffer overruns or segfaults) are possible. If somebody needs memory safety - managed languages with GC is the only real option.
- Dewie 12y ago> It is common to use ARC What is unsafe about using atomic reference counting? > and unsafe shared memory access in Rust. That should be provided with a safe interface, or an unsafe interface if calling that code is not safe. As for it being common: I think they are working on minimizing the need for unsafe code. > This defeats the purpose of this complexity. Like having a VM implemented in C defeats the purpose of the VM for that language being safe. No, not really - that C code has to be really vetted, just like unsafe code in Rust has to be really vetted. I guess we might - eventually - be able to formally verify a language implementation, thus really proving that a language is safe (that goes for those managed languages, too). Maybe that will be feasible in a few decades, if ever. Alternatively, you can use the ATS language, where you can prove that unsafe usage of pointers etc. really is being used in a safe way. > You can't isolate unsafe memory access. Sure you can - owned and borrowed pointers in Rust are represented as raw pointers at runtime. It's a safe abstraction. And if there turns out to be a bug in that interface, and they aren't really safe, then that will have to be fixed promptly - unlike in C/++, where one would be forced to say "Well, that's your fault for not being careful".
- jbergens 12y agoIt would be easier if you explain what type of programs you develop today in C or C++. In general terms Go is probably an easier and more productive language but you might lose some performance.
- rivo 12y agoIt's Go's simplicity that really struck a nerve with me. I've been coding for over 30 years now (Basic, ASM, C/C++, Java, Python, PHP, JS, Clojure) and with Go, I just love how everything is laid out for you: idiomatic Go, formatting, commenting, unit testing, concurrence, standard libraries etc. I don't have to research the basic tools. It keeps me focused on the task at hand. I'm very productive with Go. We have it in production and I'm super happy with it. (Btw, I never missed generics. If you pick a language based on its number of features, Go may not be for you.)
- marianov 12y agoSince you know Python, do you find Gonas expresive an clear as Python? Is there anything like list comprehensions and generators in Go? And anything simple like the Flask web framework? How does it compare to deploying a python app using uwsgi+nginx in terms of performance / reliability?
- NateDad 12y agoThere are no list comprehensions, but they're just trivial loops, anyway. Generators of a sort can be created, but are not commonly used. There are several web frameworks, I don't know flask, so can't answer if any are like that, but even with just the standard library you can trivially put up a web server that has routes and responds appropriately, plus json and html & text templates are in the stdlib too. Deployment is where Go shines. You don't need nginx or a specific runtime, or uwsgi. You just deploy the file and run it. It runs its own web server. The web server is on par with nginx for performance, and is as stable as your code is (which is generally very stable, since Go's error handling is very explicit). And of course Go code in general is approximately 10x as fast as python.
- jksmith 12y agoPreach it! Been using Go for a while now, and I haven't been able to keep this much of the problem domain in my head since my days coding in M2. IMO, that's the point of Go.
- shurcooL 12y agoNo need for header files.
- pjc50 12y agoYou can write a network-facing application and the language will help rather than hinder you in making it secure.
- lmm 12y agoIf garbage collection is acceptable, you'd learn more from trying OCaml - or even Haskell, if you want to really expand your comfort zone. I'm not saying don't learn Go eventually, but for the "second language" you should try something more different from C/C++ so you get more of an idea of the range of stuff out there.
- Dewie 12y agoDoesn't OCaml have bad support for concurrency, though? Concurrency is one of the features that people who look into Go are often after.
- lmm 12y agoTrue concurrency as in concurrent computation yeah, it's a bit awkward. But if you just want async I/O (which covers a lot of cases - if you're rendering a web page based on a database query, being able to handle other requests while you're waiting for the database results is much more important than being able to do the actual HTML rendering in parallel) it's pretty good at that AIUI.
- melling 12y agoOCaml is been around for almost 2 decades. Something must be holding back its adoption. Microsoft's version F# seems to be doing better but developers aren't adopting it en masse.
- lmm 12y agoIt's become a lot more popular in the last few months/years, maybe there's a good reason for that. The English documentation is much better than it used to be, as is the library ecosystem. I work mostly in Scala, but there's a lot of similarity, and I think the main reason we're seeing it take off now (10 years after originally released) is that the kind of problems where it's really useful are becoming a lot more common. If everything's in the cloud, you need a language that's good at distributed problems. If you need to handle huge volumes of data, you need something more flexible and explicit than traditional languages. If you're using too many layers of technology to understand what they all do, you need a language that can help you keep track of them.
- lazyjones 12y ago- garbage collection - safe and easy programming (really!) - no more shooting yourself in the knee with hard to debug problems - lean but quite complete standard library - native strings (proper unicode/utf-8 handling) - very little boilerplate, sane defaults - concurrency primitives (no tacked-on libraries) - high performance - not far behind C/C++ - extremely easy and practical documentation features (via comments)
- bsdetector 12y agoExcept Java and C# are significantly better at all of these points except for boilerplate, which I would even dispute whether that is a bad thing overall. Really, things like concurrency primitives as a point in Go's favor? Running code on several processors at once is where it's good to have a library because there are tons of knobs like priority and scheduling policy for instance; it's been trivial to deadlock or arbitrarily delay an entire Go program just by having GOMAXPROCS busy loops and there's no scheduling control at all last time I checked. Meanwhile shared data locking isn't even in the language despite being at a very fine level where using libraries can be cumbersome. And Go comments as good documentation is another mind-boggling claim. It's a mostly free-format with few machine-readable parts. Most functions don't even explain what types of errors can be returned, just "err Error". It's so bad it isn't even comparable to JavaDoc or C#. How can you have "safe" programming when you have to dig through sources to even find out what the error conditions are? There is a good reason to use Go and that's to feel like a pioneer. But few technical reasons.
- gillianseed 12y ago>Except Java and C# are significantly better at all of these points except for boilerplate, which I would even dispute whether that is a bad thing overall. C# on Mono certainly isn't significantly better performing than Go from my experience, which is substantiated by Go winning all but one of the 'Benchmark Game' benches, typically by quite a wide margin: http://benchmarksgame.alioth.debian.org/u64q/benchmark.php?test=all&lang=go&lang2=csharp&data=u64q http://benchmarksgame.alioth.debian.org/u64q/benchmark.php?t... And Go is not doing that bad against Java either: http://benchmarksgame.alioth.debian.org/u64q/benchmark.php?test=all&lang=go&lang2=java&data=u64q http://benchmarksgame.alioth.debian.org/u64q/benchmark.php?t...
- rjammala 12y agoI would say one compelling reason is the speed of development/deployment. It is really a very well designed language. You have to try it to know it :-)
- kyrra 12y agoIt s really simple language to learn but a bit more to master because you have to solve some common problems in a different way (especially if you have a strong OOP background). To learn the basics, check out the tour[0]. It's really simple to go through and will explain the basics of the language. [0] http://tour.golang.org/ http://tour.golang.org/