Live data from Hacker News

C vs GO

crypto.stanford.edu

111–120 of 184 posts

Re: C vs GO

#111

Earlier quoted context omitted.

Go is a fine language, but I do have a nitpick here: you do not "avoid the GC" by using memory pools. The GC must still trace through the pool when it does run. The more correct thing to say is that you can reduce allocations with memory pools, which make the GC run less often and make it do less work. Furthermore, memory pools compromise safety: if you free a pointer to an object in your memory pool and you accident…

I think the GC in Go only runs when allocations have been made. No allocations = no GC.

Yes, but that's only true if you get down to zero allocations. Memory pools reduce allocations, but you cannot get down to zero allocations--even if you somehow managed to convert every allocation site into a memory pool (which basically means not using the standard library), you'd still have to allocate the pool (unless it's stored in static memory, but then your maximum number of allocations is fixed).

The only code I've seen that actually had zero allocations in a GC'd language is actually Emscripten-generated code in JS, which is of course not actually JS but C.

Re: C vs GO

#112
post #74

Earlier quoted context omitted.

What kind of "beginner"? If you mean someone who has never programmed before, Go is much simpler to learn than C and makes a lot more sense. If you mean someone that is a programmer and hasn't used go before, I can tell you I went from "never having seen Go before" to "reasonably proficient" inside of two months. Further, my Go code is easier to read and maintain than anything I've done in other languages. (I came la…

Wow, that is very good. I am total beginner in coding so there is nothing much I could say but I am just saying from a total beginners perspective. What would be your suggestion for me if I am planning to build some social application? Learn C first to gain some fundamental knowledge? And because it is still the most widely used language, if I don't know it I wouldn't be able to find a work in the future?

I think that really depends on your goals. If your goal is to bash out a web application and get a startup off the ground, you ought to learn something that is tailored to doing that. Ruby on Rails and Django(Python) aren't bad choices. I'd avoid PHP, but that is my opinion and you'll find lots of people who disagree. Research your options and learn something that makes sense to you and will enable you to bring other people on later.

If you want to launch a career as a systems programmer, which is a fundamentally different goal, then yes, you should learn C, even if you end up using other things.

Re: C vs GO

#113
post #65
post #43

Earlier quoted context omitted.

>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). Because we learned a lot about writing more robust and maintainable software since the 1970s. Also the original Unix source code was one thing more than anything: small.…

Do you have any resources / books for writing modern C like this or is it all experiential from the trenches?

This link gets posted on HN a lot but I've found it useful:

http://c.learncodethehardway.org/book/

Re: C vs GO

#114

Earlier quoted context omitted.

Wow, that is very good. I am total beginner in coding so there is nothing much I could say but I am just saying from a total beginners perspective. What would be your suggestion for me if I am planning to build some social application? Learn C first to gain some fundamental knowledge? And because it is still the most widely used language, if I don't know it I wouldn't be able to find a work in the future?

I think that really depends on your goals. If your goal is to bash out a web application and get a startup off the ground, you ought to learn something that is tailored to doing that. Ruby on Rails and Django(Python) aren't bad choices. I'd avoid PHP, but that is my opinion and you'll find lots of people who disagree. Research your options and learn something that makes sense to you and will enable you to bring other…

Thanks. Currently, in your opinion, what kind of programmers are high in demand and what skill set does it require?

Re: C vs GO

#115
post #65
post #43

Earlier quoted context omitted.

>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). Because we learned a lot about writing more robust and maintainable software since the 1970s. Also the original Unix source code was one thing more than anything: small.…

Do you have any resources / books for writing modern C like this or is it all experiential from the trenches?

C Interfaces and Implementations: Techniques for Creating Reusable Software is the best thing I've seen on the topic, personally. http://www.amazon.com/Interfaces-Implementations-Techniques-...

Re: C vs GO

#116
post #48

Earlier quoted context omitted.

I think Go's strengths over C really start to shine when you're writing programs longer than 100 lines. Not having an exception mechanism, interfaces, single namespace, no attaching methods to structs etc are fine in a small program, but they make bigger programs harder to digest pretty quickly.

Well, the operating system you used to write that comment was probably written in C, so apparently it does in fact work in large projects. It has weaknesses to be sure, but I don't think lack of OO (I.e., structs with functions) is one of them.

Particularly given that you can write OO code in C, and can decorate structs with functions, it's just messier.

Re: C vs GO

#117

Earlier quoted context omitted.

I think he is referring more to go's "defer" functionality and out-of-band error return values more than panic/recover.

All of these things are just really poor exception mechanisms, in my opinion. It really looks like no one with an up-to-date PLT background was consulted in the design. I agree 100% with Andreas Rossberg (who now, somewhat ironically, works at Google): It is ironic that their motivation is to tame and restrict the use of exceptions, and then they replace them by something even richer and much less structured. I fail…

> It really looks like no one with an up-to-date PLT background was consulted in the design.

"Go is not meant to innovate programming theory. It's meant to innovate programming practice." I really like the out-of-band errors since they make control flow very explicit. With languages that rely on exceptions a lot (python, for example) I feel less in control of my program since 'anything can happen' remotely from my code.

Re: C vs GO

#118
post #107

I gave up reading this very early on. The striving for compactness of the source, in both C and Go, makes it misleading to read. Take if (argc 1) putchar(' '); printf("%s", argv[i]); } putchar('\n'); } A casual skim sees the if followed by an indented block, but that isn't the then-path but the else-path. Now yes, I can read it carefully and follow it, just as if I was debugging someone else's poorly formatted code,…

Your post adds nothing useful to the discussion. There is no point arguing about indenting style in a 7 line program, it's needless pedantry! This is almost exactly the same thing as grammar nazi-ism, and seems to have a similarly negative impact coding related websites.

I think we need to coin a new term - indent-nazi, style-nazi, or something similar - for the purpose of dismissing this kind of post and keeping people on topic.

Re: C vs GO

#119
post #26

Earlier quoted context omitted.

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).

malloc and free are much cheaper than a mark-and-sweep. It is a much easier task to write a bounded-latency malloc suitable for real-time applications - for example, dlmalloc has a NO_SEGMENT_TRAVERSAL flag that assures bounded execution. By contrast, making GC with bounded latency is hard .

Why are you comparing an API (malloc/free) to an implementation (mark and sweep)?

Anyway, take a look at the OCaml GC. It's simple (probably simpler than glibc's malloc) and very performant particularly if you understand how it works and use it intelligently in your app.

Re: C vs GO

#120
post #3

Damn. I can't comment on the Go listings, but could he make his C code any less readable? What's the point of making the code so dense anyway? Without syntax highlighting I gave up pretty quickly.

The C code looks very nice to me. What's the problem?
Post reply on HN