Skip to main content
181 votes

Does it ever make sense to use more concurrent processes than processor cores?

The canonical time when you use far, far more processes than cores is when your processes aren't CPU bound. If your processes are I/O bound (either disk or more likely network), then you can ...
Philip Kendall's user avatar
59 votes

Does it ever make sense to use more concurrent processes than processor cores?

Short answer: Yes. Longer answer: Set your magic number stupid high, benchmark it, set it low, benchmark it again, and keep doing that until you have your answer. The number of moving parts here is ...
Iron Gremlin's user avatar
  • 1,115
45 votes

Why do "checked exceptions", i.e., "value-or-error return values", work well in Rust and Go but not in Java?

From a scientific point of view, checked exceptions can be seen as alternative return values, e.g. Exactly. They can be seen that way, and they should be but they aren't. Using an Error type like is ...
Jörg W Mittag's user avatar
27 votes

Why do "checked exceptions", i.e., "value-or-error return values", work well in Rust and Go but not in Java?

Disclaimer: This will, to a degree, be my own personal take on the problem. I love programming language design, I've thought, read, and discussed a lot of about PL design in general, and the hard ...
Matthieu M.'s user avatar
  • 15.1k
26 votes

Is a common library a good idea?

Libraries and re-use are absolutely a good thing. They have one giant downside, which is that if not carefully managed, they become the equivalent of the drawer in your kitchen that holds all of the ...
Blrfl's user avatar
  • 20.4k
14 votes
Accepted

Making side effects explicit even in non-pure functions

A statement like s = s.IncreaseCount() can have the opposite effect of what you are trying to accomplish: it can give the reader the impression IncreaseCount does not mutate s by itself and ...
Doc Brown's user avatar
  • 212k
12 votes

Does it ever make sense to use more concurrent processes than processor cores?

In A.I. it is common for people to observe super-linear speedups when they write parallel algorithms (that is, > K times speedup with K processes running on K cores). This is because you are often ...
Chris Jefferson's user avatar
12 votes

Why do "checked exceptions", i.e., "value-or-error return values", work well in Rust and Go but not in Java?

Checked exceptions can't be treated as just another part of the expression. They must be handled out of line. With an error return value, you can write a function that converts error values to a ...
user20574's user avatar
  • 4,907
11 votes
Accepted

Type safety - GO vs C pointers

There are a few differences between Go and C that makes the former at least more type safe: Unless you muck about with the unsafe package, you're not going to crash a Go program (in the sense that it ...
walpen's user avatar
  • 3,241
11 votes

Does it ever make sense to use more concurrent processes than processor cores?

You can take the example of compiled Linux distributions (like Gentoo): to optimize the compilation time, it is obviously using parallel compilation using more processes than the number of available &...
Philippe Verdy's user avatar
10 votes

(How) can the circle-ellipse problem be solved by using composition rather than inheritance?

"Composition over inheritance" for the Circle-Ellipse problem means to implement a class Circle by making internally use of an Ellipse object, like this: class Circle { Ellipse e; ...
Doc Brown's user avatar
  • 212k
9 votes

(How) can the circle-ellipse problem be solved by using composition rather than inheritance?

The circle vs ellipse problem (as well as the square vs rectangle) are not an inheritance problem but a problem regarding the contracts and promises made about the initial class. In the first place, ...
Christophe's user avatar
  • 79.9k
8 votes

What is the difference between Haskell's type classes and Go's interfaces?

There are several differences Haskell typeclasses are nominatively typed -- you have to declare that Maybe is a Monad. Go interfaces are structurally typed: if circle declares area() float64 and so ...
walpen's user avatar
  • 3,241
8 votes

Why do "checked exceptions", i.e., "value-or-error return values", work well in Rust and Go but not in Java?

There are three parts to error code: Code that generates the errors. Code that handles the errors. Code that just propagates the errors from part 1 to part 2. Most programmers don't give part 3 much ...
Karl Bielefeldt's user avatar
8 votes

Should I cover code that should not be able to fail with tests?

Yes - tests are there to demonstrate the code behaves the way you expect. There is no such thing as cannot fail in code. You should write tests to demonstrate the code performs the task it is ...
sevensevens's user avatar
7 votes

Is a common library a good idea?

There are three different categories of functions you might consider putting into libraries: Stuff that could be reused by everyone in the world who uses the same technology. Stuff that could only be ...
Philipp's user avatar
  • 23.4k
7 votes
Accepted

What is the difference between Haskell's type classes and Go's interfaces?

The two concepts are very very similar. In normal OOP languages, we attach a vtable (or for interfaces: itable) to each object: | this v +---+---+---+ | V | a | b | the object with fields a, b +---+--...
amon's user avatar
  • 135k
7 votes
Accepted

Is having source code for a Go project outside GOPATH a bad idea

2019 Update You no longer need to store your project under GOPATH. Put it in a directory outside of GOPATH. Then type: go mod init github.com/youruser/yourproject You'll be good to go.
Inanc Gumus's user avatar
7 votes

What is the motivation for Go lang syntax?

Going from Java to Go is strange if you expect it to only be different from Java the way C# is different from Java. That is, not at all. Let Python, Lisp, Closure, or, gasp, PERL break your brain ...
candied_orange's user avatar
7 votes

Why do "checked exceptions", i.e., "value-or-error return values", work well in Rust and Go but not in Java?

There are some good points made in other answers, but I feel each picks out a different aspect, so I'm going to try to bring them together. Checked vs unchecked errors The idea of statically checking ...
IMSoP's user avatar
  • 5,877
7 votes
Accepted

How to structure many complex conditionals on a class

One approach would be to create a bunch of objects (or just functions) each of which takes an Order and only checks for the unique combination that is supposed to trigger a business outcome, put them ...
Filip Milovanović's user avatar
7 votes

Should Golang 'private' methods need unit tests?

This has almost nothing to do with the specific programming language. Thorough testing requires that you exercise all the behaviour that your code might have to perform in production. (This can mean ...
Kilian Foth's user avatar
6 votes

Type safety - GO vs C pointers

The lack of type safety doesn't come from pointers - it comes from void pointers and the ability to perform arbitrary casts between pointer types. There's nothing non-type safe about "pointer to ...
Philip Kendall's user avatar
6 votes

Did GO embrace any language construct introduced in Java?

No, Go does not show any particular influence from Java. Go and Java do share similar goals, but took different paths to achieve these goals. The Go designers are of course aware of Java, C#, C++, ...
amon's user avatar
  • 135k
6 votes

GO - Goroutine and Concurrency

Golang Goroutines are a compiler facility. Conceptually Goroutines and fibers are cooperative multitasking methods with respect to the Environment. Fibers are a OS level concept, whereas goroutine is ...
onkkno's user avatar
  • 289
6 votes
Accepted

Why is Java AOT compilation (using graalvm native-image) so much slower than golang compilation?

There are many different dimensions to this answer, and I can't guarantee that I will hit them all, or even that I will hit the most significant ones. Here are just the ones that come to mind. If you ...
Jörg W Mittag's user avatar
6 votes

How to handle different json response for the same api rest endpoint and different http status

How you handle this depends on what you can do with the response data in the case you get a 401 from the server. REST does not obligate you to parse the response from the server. You won't get any ...
Greg Burghardt's user avatar
5 votes
Accepted

Generic-type operations must by provided by the run-time. Why this is a weakness of Go?

So, the quirkiest part for me is "provided by the run-time," - is that equals to "provided by the language"? Yes. What it means is that Go has a handful of built-in generic types, such as arrays/...
Mason Wheeler's user avatar
5 votes
Accepted

How do programming languages work?

A compiler or interpreter is a program just like any other program. You can write programs in any programming language you want, including Go. Ergo, you can write a compiler in Go. Including a Go ...
Jörg W Mittag's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible