5 ms·
How is Go lower level than C#?
by staticassertion 5y ago
How is Go lower level than C#?
- throwaway34241 5y agoI think C# might be the closest mainstream language, but I’d say explicit pointers, interior pointers, and slices as the default list type might be things that make Go programming a little lower level. There are also other differences that would prevent using C#’s system as is - Go doesn’t have the reference/value type dichotomy or inheritance. I think they also wanted to be able to abstract across float/doubles etc (unless C# added that recently). Anyway I like both languages and I’m not trying claim one is better than the other, just trying to explain the design space Go seems to occupy.
- pjmlp 5y agoNever used unsafe and raw pointers in C#? They exist since version 1.0. Never used ArraySegments in C#? They exist since version 2.0 Abtracting over float/doubles is called generics.
- socialdemocrat 5y agoIt is not the same thing at all if you care to compare the details. C# pointers come with a long list of caveats which does not apply in Go. They feel like a bolted on escape hatch rather than a real part of the language.
- pjmlp 5y agoMoving goal posts, so now instead of not existing, they come with caveats.
- staticassertion 5y agoI'm not sure what the difference is with regards to pointers. They're both garbage collected languages with value types. There are definitely differences in the languages, but I'm not sure that Go really had anything to figure out or invent. I don't buy that argument.
- throwaway34241 5y ago> I'm not sure what the difference is with regards to pointers. In C# most objects are 'class' objects, which are implicitly passed by pointer, although some are 'struct' objects passed by value. In Go rather than making the decision once at the type level, the decision to pass by value or pointer is made explicitly every time an object is used. > I'm not sure that Go really had anything to figure out or invent If you look at the discussions for Go (which started as early as 2009 [1]) [2] [3] [4] [5] generics seems as big or a bigger project as the other improvements made to the language over the last decade. My impression is there being a broad spectrum of potential trade-offs across compile speed, execution speed, convenience, etc. The totality of the prior art here is above my pay grade, but I can quote the Haskell people they roped in [4]: > We believe we are the first to formalise computation of instance sets and determination of whether they are finite. The bookkeeping required to formalise monomorphisation of instances and methods is not trivial ... While the method for monomorphisation described here is specialised to Go, we expect it to be of wider interest, since similar issues arise for other languages and compilers such as C++, .Net, MLton, or Rust I think C# occupies a fairly nice design spot also (and takes advantage of its class/struct system to get fast compiles but also performance when needed). But it's not like the C# design couldn't be improved on. As far as I know you still can't write math code that works across 32 and 64 bit floats. And array covariance is implemented in a way that isn't type-safe and relies on run-time checks and exceptions. [6] [1] https://research.swtch.com/generic https://research.swtch.com/generic [2] https://docs.google.com/document/d/1vrAy9gMpMoS3uaVphB32uVXX4pi-HnNjkMEgyAHX4N4/view https://docs.google.com/document/d/1vrAy9gMpMoS3uaVphB32uVXX... [3] https://go.googlesource.com/proposal/+/master/design/go2draft-contracts.md https://go.googlesource.com/proposal/+/master/design/go2draf... [4] https://arxiv.org/pdf/2005.11710.pdf https://arxiv.org/pdf/2005.11710.pdf [5] https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md https://go.googlesource.com/proposal/+/refs/heads/master/des... [6] https://codeblog.jonskeet.uk/2013/06/22/array-covariance-not-just-ugly-but-slow-too/ https://codeblog.jonskeet.uk/2013/06/22/array-covariance-not...
- MobiusHorizons 5y agoOne major difference that makes Golang lower level is that it compiles to machine code for the target CPU arch/OS instead of bytecode.
- jcelerier 5y agoC# also supports AOT compilation. It's definitely not a low-level / high-level language differentiator. The term generally means the abstraction level you can reach.. I'd be tempted to define it as the distance to simple lambda-calculus in the lambda-cube
- alexklark 5y agoOh, AOT compilation, great memories. How many year of CPU work and downtime it took from exchange servers, when you wait every update to “compile” for hours, just because it is awesome. Or when you getting laptop heating and you know - it is dotnet compiles and optimising something for you, another great update. Yes, C# also supports ahead of time compatibility - it is portable for whole 20 years between windows computers. How cool is that? Another advantage is speed - calculator or photo viewer only takes 1-3 seconds to open on 5 ghz 8 core cpu. Yet another advantage is size - only 3-5 gigabytes of different version libraries in your system and you are golden for a month (next you need to install preview updates, and then just updates and thats all you good, secure and protected by Windows Defender). In all these aspects C# is clearly superior language.
- socialdemocrat 5y agoC# ahead-of-time compilation has for many years come with all sorts of caveats. Early versions requires runtime system because not everything got compiled on parts. Later versions have all sorts restrictions which do no apply for Go. I think when C# and Java people compare with other languages they treat it as a checkbox exercise without caring about how good that feature actually is.
- staticassertion 5y agoOK but Go carries around a runtime too?
- ptsneves 5y agoWe use go in an embedded Linux environment. I do C#for web stuff and it would never cross my mind to do c# in an armv7 Raspberry. Also what about cross compilation? The c# runtime is not easily available to use in embedded devices at least that i know of. With go you just set it to compile statically and set the arch target. I can deploy it as a single binary. Love it after years of maintaining cross tool chains.