5 ms·
Not trying to be cheeky, but why not c#? Has pts 2, 3 and 4. For pt 1, what in Rusts type system are you looking for?
by chris_nielsen 3y ago
Not trying to be cheeky, but why not c#? Has pts 2, 3 and 4. For pt 1, what in Rusts type system are you looking for?
- jen20 3y agoSum types, which can only be approximated in C# via records, and no exceptions, which is even a problem for F#.
- tazjin 3y agoI don't know C#, so maybe it has these, but it's unlikely: - absence of null pointers - proper sum types which can be statically checked for exhaustiveness - statically controlled mutability (yes, borrow-checking is still useful if you have a GC!) Also no exceptions, but that's not a type system feature.
- seabrookmx 3y agoC# calls the first one "nullable reference types." When that build option is enabled, all types are non-nullable by default, and you can make them optionally nullable by declaring them like "MyClass? cls = null;" The compiler will ensure you check for null before de-referencing a nullable type.
- tazjin 3y agoHow does this interact with third-party dependencies you use? In my experience, most gradual typing things break down at that boundary.
- seabrookmx 3y agoThis isn't gradual typing? If libraries are not compiled with the compiler option, then all their reference types will be deemed nullable and I need to check for null before dereferencing. I can't do something like "GetItem().Name" if "GetItem()" returns a reference type like I could in Java, GoLang, JS, etc. If that library did use the flag and was provably non-nullable, then I could.
- raincole 3y ago> Not trying to be cheeky, but why not c#? C# is my main language. I consider it a very good all-round language. Rust's type system has some advantages over C# tho, for example Sum Type, Option (C# has ? but it was added later so you need to be careful when interacting with old code, kinda like TypeScript <-> JavaScript to a lesser extent), exhaustive enum, etc. Another thing I don't like about C# is the runtime startup time which prevents me from using it for command line tools (Yes I prefer static typed languages even for "scripting"). I think Go has proven that you can have both GC and extremely fast startup time.
- digibeet 3y agoRuntime startup might be a fixed issue soon for smaller CLI programs. Correct me if I'm wrong, but I believe they are working on (and it is already available with a compiler option) to compile your C# program ahead of time (C# AOT).
- MrBuddyCasino 3y agoTried Kotlin native? - sum types via sealed classes (not great, admittedly) - enum "when" expressions are exhaustive - option type via built-in nullable types (honestly the superior solution)
- neonsunset 3y agoCould you try a few sample scenarios for a CLI tool written in C# with the following publish options? JIT: dotnet publish -c release -o publish -p:PublishSingleFile=true -p:PublishTrimmed=true AOT: dotnet publish -c release -o publish -p:PublishAot=true Either one has really good startup time (below ~100ms and 20-30ms respectively depending on what you do), compact binary size and require no external dependencies. Just like in Go except without all shortcomings of Go :) p.s.: AOT on macOS requires .NET 8 preview (will be released in November)
- raincole 3y agoInteresting, I remembered I've tried something similar to your JIT example but maybe my memory is playing tricks on me. I'll try these again later
- John23832 3y agoThen what about F#?
- madeofpalk 3y agoC#'s type system is nowhere near as expressive. Lack of sum types/discriminated unions and pattern matching/type refinement.