5 ms·
> It is critical that people question “how does this magic actually work?” No. It's critical that people question “why do I have to rely on magic?” in the firs
by catnaroek 10y ago
> It is critical that people question “how does this magic actually work?”
No. It's critical that people question “why do I have to rely on magic?” in the first place. Even in high-level languages, perhaps especially in high-level languages, it's a good idea to write straightforward code.
> there is an appalling lack of candy in the C/C++ ecosystem (...) performance isn’t hidden
C and C++ are very different languages, and there is no shortage of C++ libraries full of incomprehensible magic. When debugging template-heavy C++ code, it can be very hard to determine where expensive and unnecessary object copies are created. Thank you C++, for making copy construction implicit!
> Are you producing too much garbage unnecessarily?
The high-level programmer's best defense against creating too much garbage is programming with values (whose redundant representations in memory can be automatically deduplicated by the runtime system) rather than object identities.
> Are your dictionaries too big to the point of being inefficient?
The problem isn't the dictionary abstraction, but rather the implementor's choice of underlying data structure. If you have a really big dictionary whose keys are strings (a common use case), you want tries, not hashtables.
> string concats can be replaced by string builders in the same amount of lines,
Using string builders is a low-level chore, and defeats the point to using a high-level language. A better alternative is using a persistent list/string data structure that actually supports efficient concatenation.
> Does your program start ad-hoc threads? Use a threadpool with fixed size.
Again, too low-level. A programmer working with a high-level language should be able to spawn as many green threads as she wants to, and let the language's runtime system handle multiplexing those green threads over OS threads.
> Unless you are 100% sure the lines are always of reasonable size, do not use readline.
This is terrible advice. If readline is causing you problems, you are using the wrong string data structure.
---
Okay, I'm done bashing what could be bashed. The last two items in the OP are actually good.
- perfmode 10y ago> Again, too low-level. A programmer working with a high-level language should be able to spawn as many green threads as she wants to, and let the language's runtime system handle multiplexing those green threads over OS threads. Do this in Go and you'll be surprised how quickly you run out of memory.
- catnaroek 10y agoSounds like a reason not to use Go as a high-level concurrent language.
- perfmode 10y agoSounds like infinite threads is wishful thinking.
- catnaroek 10y agoYou understand the difference between “as many green threads as the programmer wants” and “infinitely many threads”, right?
- perfmode 10y agoYes. Not finite. Unbounded. Finite == bounded == pool.
- dllthomas 10y ago> bounded == pool Pool implies pre-allocated.
- catnaroek 10y agoUnbounded isn't the same as infinite. For example, if you have a fair coin, the number of times you have to flip it until you get 5 tails is unbounded but finite. The problem with creating infinitely many threads isn't even space. Even if you had an infinite amount of memory, programs are supposed to complete their tasks in a finite amount of time, so you shouldn't spawn infinitely many threads, because it's an unreasonable thing to want. On the other hand, spawning 100k green threads is a perfectly reasonable thing to want. It's the language runtime's job to multiplex these 100k green threads over 4 or 8 or however many OS threads make sense.