Live data from Hacker News

C vs GO

crypto.stanford.edu

21–30 of 184 posts

Re: C vs GO

#21

I can't do system programming using Go on a platform for which there is no compiler. There is probably a reasonable C compiler for every platform in existence out there.

Probably, but realize that at first this wasn't true. Go needs time to grow, just as C grew to different systems. Looking at other systems such as Haiku shows that porting Go is encouraged, the only issues have to deal with assumptions in the build (in this case, I think /bin/env/bash is included everywhere, there's no global variable to change this definition from different OS types). One day we may see a change in…

> Looking at other systems such as Haiku shows that porting Go is encouraged, the only issues have to deal with assumptions in the build (in this case, I think /bin/env/bash is included everywhere, there's no global variable to change this definition from different OS types).

I think this is not longer a problem with the new build system that is part of Go 1.

Also AFAIK at least the Plan 9 port is almost complete, and is certainly functional.

Re: C vs GO

#22
post #20
post #19

Earlier quoted context omitted.

+ FreeBSD. Also, OpenBSD, NetBSD, and Plan 9 in the works.

OpenBSD and Plan 9 pretty much work already, even if the ports might not be as polished as FreeBSD. Also there is gccgo, which AFAIK also works on Solaris and probably elsewhere.

Yes, it works on IRIX and RTEMS (an embedded OS), and the gc suite was also ported on Ethos.

I'd also like to add that the gc compilers support ARM as well as x86 and amd64 and are very, very easy to port to new platforms.

Re: C vs GO

#23
post #9
post #6

Earlier quoted context omitted.

The big win for go over c is the goroutines - cheap and easy multithreading built right into the language.

I agree entirely - they are great, but in all the Go I've written (which totals about 50kloc so far as a porting project), I haven't actually used them past anything I would have done with zmq in C.

Goroutines are great, but I'm not convinced they are the greatest advantage over C.

Go cleans up and fixes pretty much every issue C had, and improves it in many non-obvious areas, from the syntax to the type system.

And when porting an existing project I'm not surprised if goroutines would come up that often given that they probably don't have any equivalent in the original design.

Re: C vs GO

#24

In my opinion, any new language today should be all beginner friendly, there are large pool of people who are interested and it means a great future of our world.

Go is relatively beginner friendly, is simpler and smaller than most languages around (even for example Python). Go code is concise but without dark magic (is easy to see what code does by just looking at it). And you can even read the whole language spec fairly easily.

Re: C vs GO

#26
post #17
post #13

Earlier quoted context omitted.

Ever heard of Oberon, Modula-2 and Modula-3? These languages also had OS fully implemented on them, just with tiny bits of Assembly to do the very low level stuff, similar to what C would require anyway. The only advantage of C is that its runtime is so small, that in practice the OS is the C's runtime.

It's not the only advantage. Another, more important advantage of C and C++ over Go is a lack of stop-the-world garbage collection (and predictable memory usage under high load).

You can predict the time that malloc(3) and free(3) take to run? You know they are backed by very complex data structures that need to manipulated and iterated over?

The point you mention is only valid when using entirely static memory, which is a very rare case in real C code (only really used in a few small embedded codebases).

Re: C vs GO

#27
I like Go but it's not a replacement or even just competition for C. Garbage collection alone ensures that.

C is for low-level code, where you usually want deterministic, real-time behavior. Go cannot deliver that because of its GC.

You can certainly write web server software in Go (what Go was designed for), but could you write an "AAA" video game in it? Or a mission critical embedded system with real-time requirements?

Also, the author's portrayal of C is misleading. If you have 'naked' malloc() calls all over your code you are doing something wrong. Much C code never calls malloc() or follows the "no allocation after initialization" principle.

If you write C like Python you will run into problems. In C you do not wildly allocate objects on the heap all across the program. E.g. in my current program almost everything comes out of memory pools. E.g.

Object* object = ObjectNew();

..and if I forgot to release it I would know quickly because any "memory leak" would cause the (pre-allocated, fixed size) memory pool to run out of free slots. In C you should manage memory in a systematic fashion.

I think the C standard library should be seen as the very foundation of a program, something you use to build the abstractions which solve the problem, not something you use directly to solve the problem. People often warn about the dangers of strcpy() (an the author uses it). I never use it except at the lowest levels. At the high level robust C code looks more like this:

ObjectSetName(object, newName);

than this

strcpy(object->name, newName);

..the difference is that ObjectSetName() can internally guard against overflow and that the concrete details of the object data structure remain hidden and thus later code changes are easier. It is a very common C idiom to use incomplete types and such functions to achieve a very high level of encapsulation.

Re: C vs GO

#28

In my opinion, any new language today should be all beginner friendly, there are large pool of people who are interested and it means a great future of our world.

"any new language today should be all beginner friendly"

I disagree. I think any new language should be designed to best meet the kind of problem it's being created to deal with. Making it "beginner friendly" (whatever that means - I bet there are lots of different interpretations) is a nice extra, but should not come at the expense of solving the problems.

Re: C vs GO

#29
post #27

I like Go but it's not a replacement or even just competition for C. Garbage collection alone ensures that. C is for low-level code, where you usually want deterministic, real-time behavior. Go cannot deliver that because of its GC. You can certainly write web server software in Go (what Go was designed for), but could you write an "AAA" video game in it? Or a mission critical embedded system with real-time requireme…

Your C code looks very unidiomatic to me, but I guess that is relatively a matter of taste (still I don't understand why would somebody use C if they don't like to write code in the 'classic' C style as seen in the original Unix and Plan 9 source).

That aside, in Go you can also do fixed allocations and manage your own memory pools to avoid the GC.

And I would also question how many C programs require real-time behaviour (even the definition of 'real-time' has issues, most things people call 'real-time' aren't).

Re: C vs GO

#30
post #18
post #13

Earlier quoted context omitted.

Ever heard of Oberon, Modula-2 and Modula-3? These languages also had OS fully implemented on them, just with tiny bits of Assembly to do the very low level stuff, similar to what C would require anyway. The only advantage of C is that its runtime is so small, that in practice the OS is the C's runtime.

Aren't they dead? Seriously. If you write programs at OS level, you need the control over memory, timing, etc. In go you have no control about the runtime at all. Don't get me wrong. Go is fantastic for any kind of gooooogle, cron, at, ... server stuff. At OS or bare level you unfortunately need something other than a sledgehammer.

> Aren't they dead?

Yes, but only because no major OS manufacturer picked them up as the main system language.

The only way a system language can become mainstream is if it is picked up by an OS vendor that makes it the default system language on their OS.

As for the bare level stuff you describe, real systems like Native Oberon proved this is possible. At ETHZ Native Oberon was used for almost everything an OS is used for.

Sadly no major vendor has got interested on the system, even after some industry attempts tried out by ETHZ.

Post reply on HN