Live data from Hacker News

The Go Programming Language, or: Why all C-like languages except one suck.

syntax-k.de

71–80 of 110 posts

Re: The Go Programming Language, or: Why all C-like languages except one suck.

#71
post #56

Earlier quoted context omitted.

In Go, the accepted way to report errors is to take advantage of multiple returns, such as: result, err := somePotentiallyFailingFunction() if err != nil { // Try to recover here ... // Not recoverable? panic() } And this call to panic works the way you prefer. Note that doing the following: result := somePotentiallyFailingFunction() won't compile since the number of values on the left doesn't match the right, so if…

Ok but exceptions also give you alot of context about the error like exactly where it occured. How is that handled in Go?

The error type is an interface. You can return values that contain contextual information as long as the error value you return has an Error() method returning a string.

    type ParseError struct {
        line int
    }

    func (e ParseError) Error() string {
        return "Parse error at line: " + fmt.Sprint(e.line)
    }
Note: The current release may vary slightly on the details. I'm using a pre-release build. But older versions are similar.

Re: The Go Programming Language, or: Why all C-like languages except one suck.

#72
post #34

No, I have never written exception-handling code like that mocked in this article. There's a strong correlation between uses of 'catch' and the probability that you're using exceptions incorrectly. Go's lack of exceptions is probably what pushes me away from it most strongly.

Go doesn't lack exceptions. It just uses some different names (throw -> panic, catch -> recover) and uses a different way to write the code that catches them.

http://golang.org/doc/go_spec.html#Handling_panics

Edit: Also, here's an interesting pattern to illustrate that Go's panics are a little different.

    func parse(s string, config *Config) (x Thing, err error) {
        defer config.RecoveryPlan(&x, &err)
        x, err = doParse(s)
    }
It's contrived, but you can see that the "RecoveryPlan" can choose to ignore panics or recover from them and it can also affect the return value of the "parse" call by assigning to its parameters and recovering from the panic.

Re: The Go Programming Language, or: Why all C-like languages except one suck.

#73

If C isn't suitable for projects with more than 10K lines, then praytell, what language should my kernel be written in? I've been meaning to try Go for a while (the fast compile times alone intrigued me), but this type of post really just puts me off - if you're telling me that C isn't suitable for large projects, then that tells me you may not know C well enough to make that judgement.

> If C isn't suitable for projects with more than 10K lines, then praytell, what language should my kernel be written in? The Xen hypervisor (which shares a lot of characteristics with an OS kernel) is written in OCaml, which seems to have proven a good choice in practice: http://gazagnaire.org/pub/SSGM10.pdf

Not the hypervisor, just the management tools.

Re: The Go Programming Language, or: Why all C-like languages except one suck.

#74
post #60

Earlier quoted context omitted.

Every language has its pathological corner cases. Modern C++ using the STL is almost as terse as modern dynamic languages but runs 100x faster.

I would argue that C++ is a pathological corner case.

Even Stroustrup has said there's a cleaner, simpler language within C++ struggling to get out. But C++11 is a big step toward that language and C++ is still the go-to language for a large class of applications for good reason.

Re: The Go Programming Language, or: Why all C-like languages except one suck.

#75

Earlier quoted context omitted.

He might not know C, but the creators of Go certainly do, so don't let this post discourage you.

> But the creators of go certainly do. The only person who knows C better than the lead designer of go. (Ken Thompson IIRC.) Is in a casket right now. EDIT: I didn't mean that in a ill-spirited tone. I'm just pointing out that the people working on go are the best alive.

I know who Ken Thompson is, and don't so much disagree. But that is a bold and oft-repeated statement, that seems to not be fully supported by the evidence.

Re: The Go Programming Language, or: Why all C-like languages except one suck.

#76
post #75

Earlier quoted context omitted.

> But the creators of go certainly do. The only person who knows C better than the lead designer of go. (Ken Thompson IIRC.) Is in a casket right now. EDIT: I didn't mean that in a ill-spirited tone. I'm just pointing out that the people working on go are the best alive.

I know who Ken Thompson is, and don't so much disagree. But that is a bold and oft-repeated statement, that seems to not be fully supported by the evidence.

I'll concede that the former project lead for Unix might not be the best C programmer.

But then; who is?

If there's evidence to support that there's someone who knows it better than Ken, I personally would like to see it. (More from curiosity than anything else.)

Re: The Go Programming Language, or: Why all C-like languages except one suck.

#77
post #4

I really like some of the ideas in Go however it still hasen't hit that critical mass that languages need to hit to really make it in the crowded world of programming languages. This is going to be even more difficult for Go then it was for Python or Ruby since they both can serve very well as prototyping language or glue languages. As a systems language Go needs to be able to gain traction from nothing.

It just needs an OS to go with it. I think Rob Pike should port Plan 9 to Go.

Re: The Go Programming Language, or: Why all C-like languages except one suck.

#78
post #18

Earlier quoted context omitted.

My own project (FLINT) is about 120k lines, and we're still going with C. I did spend a lot of time looking for a theoretical higher level language which could take us further when C ran out of puff, but we eventually decided to stick with C for the main project. However, I did eventually spot Julia, which is totally awesome for my own personal higher level needs.

For what it's worth, I've done a lot in Lua, dropping to C (on rare occasions) to offload heavy processing elements where a scripting language would choke. Many game developers do their interface and game scripts in Lua then run the engine in C as well. It keeps the C code light and clean and brings down the number of manhours required to build and maintain a project. I don't know what FLINT is or what Julia is used…

FLINT is a library for number theory: https://en.wikipedia.org/wiki/Fast_Library_for_Number_Theory

Re: The Go Programming Language, or: Why all C-like languages except one suck.

#79
post #18

Earlier quoted context omitted.

My own project (FLINT) is about 120k lines, and we're still going with C. I did spend a lot of time looking for a theoretical higher level language which could take us further when C ran out of puff, but we eventually decided to stick with C for the main project. However, I did eventually spot Julia, which is totally awesome for my own personal higher level needs.

For what it's worth, I've done a lot in Lua, dropping to C (on rare occasions) to offload heavy processing elements where a scripting language would choke. Many game developers do their interface and game scripts in Lua then run the engine in C as well. It keeps the C code light and clean and brings down the number of manhours required to build and maintain a project. I don't know what FLINT is or what Julia is used…

Lua is not suitable from my point of view due to the lack of proper integer types (and many other features).
Post reply on HN