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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 &...
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;
...
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, ...
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 ...
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 ...
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 ...
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 ...
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
+---+--...
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.
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 ...
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 ...
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 ...
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 ...
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 ...
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++, ...
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 ...
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 ...
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 ...
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/...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
go × 145design × 15
programming-languages × 15
concurrency × 14
golang × 13
language-design × 10
design-patterns × 8
architecture × 7
rest × 6
multithreading × 6
data-structures × 5
microservices × 5
compiler × 5
object-oriented × 4
algorithms × 4
python × 4
unit-testing × 4
testing × 4
c × 4
web-applications × 4
interfaces × 4
haskell × 4
type-systems × 4
google × 4
erlang × 4