3 ms·
My guess is that C# will be much better, since it has support for Value types. Wasn't Java supposed to get support for Value types some time ago?
by diffuse_l 4y ago
My guess is that C# will be much better, since it has support for Value types.
Wasn't Java supposed to get support for Value types some time ago?
- olavgg 4y ago[flagged]
- pharmakom 4y agoI downvoted because this is not a constructive comment and it makes sweeping generalisations.
- SideburnsOfDoom 4y agoC# dev here, and I don't bash Java, in fact I don't tend to comment on languages that I'm not an expert on, because well, not an expert. This covers the vast majority of programming languages and toolkits. Nobody know them all. Nobody knows more than a small fraction of them. I'll make one generalisation though: any dev of $langA that spends their time bashing $langB is doing pathetic insecure gatekeeping. And should give it up. This applies to what grandparent comment is talking about, and to grandparent comment itself. It's not cool to hate on an out-group, even if it's a community bonding experience. I refer the grandparent to Scott Hanselman: https://www.youtube.com/watch?v=IzhQIpT7S50 https://www.youtube.com/watch?v=IzhQIpT7S50
- alkonaut 4y agoC# does indeed produce a rather tight assembly https://sharplab.io/#v2:EYLgtghglgdgNAFxBAzmAPgAgLACgACATAMx4DeemVm+xNAjAGyYA2A9jAOaYDKArmAAU7LgH4A2gF1MCABaxOKAJQ5c1TBTXrqI7igGYAvJgAMAbkraqAMzYAnQbASYoR02ZcAeOQpQA6ABkAUy45DygAagilSyt1fTBMCOMfLhRxKEk/AAlUADUIFj4gzFFTTBAZeTSMrIKioIstK3wAdkwEpvUAXzxe3CA=== https://sharplab.io/#v2:EYLgtghglgdgNAFxBAzmAPgAgLACgACATAMx...
- orthoxerox 4y agoThe compiler takes care of this, but the idiomatic way to write the body of the loop in C# is sum += things[i] ?? 0;
- alkonaut 4y agoYou could even argue the most idiomatic C# is things.Sum(x => x ?? 0) and there the real test would be if the compiler/jit would match the speed of the for() loop exactly, i.e. not allocating any enumerators on the heap, not boxing any values and so on.
- evntdrvn 4y agounfortunately LINQ-to-objects doesn't have the greatest reputation for generating great code/perf, due to a number of factors (largely due to historical impl/interface decisions, from what I understand)
- pjmlp 4y agoProject Valhala has the goal to be ABI compatible with existing JARs, hence why it has taken so long, they want to add value types semantics without breaking Maven central.
- SideburnsOfDoom 4y agoC# can be much better, or it can be much the same. It depends on which implementation you use. Standardisation is an issue here, the system library has the "Nullable<T>" struct (1), but not a standard Result<T, E> class (or struct). Popular libraries such as "OneOf" use a class type. The single-valued "OneOf" type is effectively an "Option<T>" (2) Nullable<T> itself is not exactly the same as Option<T> since it does not cover types that already allow nulls. It adds nulls rather then removing them. Many people roll their own Option<T> or Result<T,E> type, since it's easy enough to start, and it's usually a class type. 1) https://learn.microsoft.com/en-us/dotnet/api/system.nullable-1 https://learn.microsoft.com/en-us/dotnet/api/system.nullable... 2) https://github.com/mcintyre321/OneOf/blob/master/OneOf/OneOfBaseT0.generated.cs https://github.com/mcintyre321/OneOf/blob/master/OneOf/OneOf...
- kaba0 4y agoWell, Valhalla is described as “requiring 7 PhD’s knitted together”, doing that while remaining backwards compatible is insanely hard.