3 ms·
Former C++ dev, current Python dev here. Go is somewhere between Python and C. Go has a garbage collector, scheduler, and runtime type information (aka reflect
by weberc2 10y ago
Former C++ dev, current Python dev here.
Go is somewhere between Python and C. Go has a garbage collector, scheduler, and runtime type information (aka reflection, aka introspection). Like C, Go has "value types" whereas everything in Python (or even Java/C#) is a reference (this gives more control over memory layout, generaly less indirection, and generally less work for the garbage collector). In this sense, Go performs similarly to Java for serial tasks.
For parallel and concurrent tasks (e.g., web servers), things get more interesting. Efficient concurrency in C is hard, and efficient parallelism in Python is hard (async IO makes efficient concurrency easier, but it's not widely used as far as I can tell). Go's goroutines solve both of these problems by providing a lightweight threading mechanism that abstracts over both OS threads and async IO (I/O is always async in Go, but there are no callbacks, promises, or async/await). These lightweight threads (goroutines) can be dispatched and moved across thread boundaries, and there is no Global Interpreter Lock (unlike Python) so shared memory parallelism is easy.
Basically, Go is as easy as Python (even easier for nontrivial applications in my opinion), about 20-30 times faster than Python (or about half as fast as C or on par with Java/C#), and much much nicer for concurrent and parallel tasks than all of the above.
- kasey_junk 10y agoNitpick c# has value types
- ngrilly 10y agoIn C#, can you create an array of (x, y, z) tuples, where x, y and z are floats, and the whole array is store contiguously, without any indirection? Last time I checked C# documentation, it wasn't possible, but maybe I missed something. Edit: Ok, I definitely missed something ;-) I checked again C# documentation and kasey_junk is right. The tuple can be implemented as a struct, which is a value type (not a reference type), and arrays items are stored in contiguous memory. This is a big advantage of C# over Java (value types are planned for a future version of Java).
- weberc2 10y agoI know. Java and C# have primitives as well, which are also values and not references. I was speaking broadly. :)