7 ms·
> But, if we made a new statically-typed OO language from scratch in 2021, something in the vein of Java or C#, taking everything we've learned from functional
by wongarsu 6y ago
> But, if we made a new statically-typed OO language from scratch in 2021, something in the vein of Java or C#, taking everything we've learned from functional programming and a decade-plus of scathing OO criticism, could we fix this?
Modern C# is already a statically-typed OO language that takes lots of lessons from functional programming and decades of scathing OO criticism (after all it's basically "Java done right"). And of course there's also Scala and F# if you want something more functional than OO.
I think the author summarizes it best at the end: "I realize there's not much need for a language like this—the space is crowded enough as it is—but it's fun to dream.".
- vips7L 6y agoIMO Java has learned from the mistakes of C# as well. See Task<T> vs Loom's virtual threads. Brian Goetz (the Java language architect) himself even said they're waiting to see how C#'s nullable types plays out before considering them in Java.
- jayd16 6y agoAsync/await and implicit thread scheduling solve different problems. Loom is more about catching up to Go and Kotlin, no?
- anoncake 6y agoNot Kotlin, AFAIK Loom is about the JVM.
- tybit 6y agoThey mostly solve the same problems, albeit in very different ways. Loom is primarily about making threads cheaper, async await is primarily working around threads being too expensive.
- jayd16 6y agoImplicit scheduling like Loom doesn't solve the problem of working with thread based synchronization such as what you often see in UI. You want a paradigm that lets the user easily define what runs on the main/ui thread and what runs else where. Loom's goal is implicit suspension without thinking about threads. Its a different use case. Backend engineers seem unaware of the problems async/await solves.
- thu2111 6y agoUsing coroutines on a UI thread is a recipe for horrible bugs. I've done it, I wouldn't do it again unless I had to (i.e. all JS in the browser is forced to work this way so there it's pointless to resist). The right approach is what JavaFX or Swing do: make it easy to schedule a lambda onto the UI thread from any background thread. Whilst that lambda executes, events are not dispatched. Where things get painful is where you try to make a single chunk of code look blocking whilst it's actually not. The user can insert arbitrary events into the middle of your code the moment you do an 'await' and you have to plan for that. In practice, I've not found the typical UI toolkit paradigm to ever be a problem. If your UI starts to stutter, it's time to move something to a background thread. It forces you to admit that the UI and work are genuinely running in parallel and consider cancellation semantics, work/results handoff, etc. And of course you properly use multi-core systems.
- jayd16 6y agoTo some degree its a style choice but most (all?) of the languages used for UI use some kind of the UI thread paradigm with a way to run code on and off of that thread. Not everything called a coroutine is designed for UI interaction. Kotlin's are better suited than Goroutines. As you admit your self, js and others have settled on this style and one has to assume its for a good reason. Async/await solves the problem of posting execution to another thread, getting a result, and easily and efficiently waiting for that result on exactly the thread you need. It'll be interesting when or if someone uses Loom in the UI space.
- thu2111 6y ago
- lostmsu 6y agoYeah. It's kinda funny. Due to extensive F# -> C# -> Java feature bleed you can consider them beta channels of the same language. Java being LTS, C# - main, and F# - Dev Builds.
- pjmlp 6y agoC# keeps getting features from Java as well, e.g. default interface methods. And you are forgetting the ML -> F# / Scala part.
- tejinderss 6y agoWould you choose java or C# if you have to pick one?
- pjmlp 6y agoC#, because of better support for value types and low level coding. Also despite all its high and lows, the .NET story regarding desktop frameworks is much better than Swing/JavaFX, and whatever Google has butchered Java with. However I have never been a X Developer, I always have used both at my employers since they exist, alongside C++, depending on the project and customer requirements.
- pjmlp 6y agoOne of the best OO languages out there is Eiffel, value types, DbC, MI, generics, lambdas, non-nullable references, a very nice graphical editor, JIT for development and AOT toolchain that pings back into the C and C++ compilers of the host platform. Java and .NET are still catching up to what it offered in 2000. Sadly it never got a big name sponsor to push it.
- le-mark 6y agoOcaml also has a long standing claim to being an oo plus functional language for the future that hasn’t seen a lot of uptake. It would have been heartening and reassuring for the author to explore more candidates than Scala.
- sfRattan 6y agoThe complaints I remember about ocaml the last time I checked it out were related to multithreading. No idea if that's changed. But I do see ocaml very often in use to write a compiler, especially for languages that aren't yet self-compiling, most recently when looking into Haxe.
- cptwunderlich 6y agoNot yet, but it's a work in progress: https://discuss.ocaml.org/t/multicore-ocaml-february-2021/7449/3 https://discuss.ocaml.org/t/multicore-ocaml-february-2021/74...
- yawaramin 6y agoNode.js, Python, and Ruby are single-threaded. They all have ways to achieve concurrency and multi-process usage right now, and so does OCaml. I get it, people really want OCaml multicore–and it's coming–but that by itself is not stopping OCaml from being an industrial-strength, production-ready language right now.
- pjmlp 6y agoFor generations, the only way to use multiple CPUs was multiple process and asynchronous syscalls. So for C it was ok, but for OCaml a reason not to use the language.
- ghosty141 6y agoThe biggest problem for me is the age old „null“. C# with monads would be great.
- jayd16 6y agoYou can set references to default to non-nullable now with compiler flags or some such thing.
- orthoxerox 6y ago<Nullable>enable</Nullable> in your .csproj
- mdpopescu 6y agoSomething which I've used in the past (edited because I spotted some mistakes while re-reading the code [grin]): public readonly struct Option<T> { public static readonly Option<T> NONE = new Option<T>(); // public T Value { get; } public bool HasValue { get; } public Option(T value) { Value = value; HasValue = value is { }; } public Option<TR> Select<TR>(Func<T, TR> selector) => HasValue ? new Option<TR>(selector(Value)) : Option<TR>.NONE; public Option<TR> SelectMany<TR>(Func<T, Option<TR>> selector) => HasValue ? selector(Value) : Option<TR>.NONE; public T OrElse(T defValue = default) => HasValue ? Value : defValue; } You can of course add more utility functions besides these, eventually as extension methods, but it's a starting point.
- ryanjshaw 6y agoYou can also use a library like LanguageExt. In practice I'm torn between how neat and logical it looks, and wasting 30min figuring out I used the wrong match() on a mixed sync/async scenario after a method signature changed and that's why my database context is disposed of randomly in the middle of operations.
- franknine 6y agoHighly recommend Functional Programming in C#: https://www.manning.com/books/functional-programming-in-c-sharp https://www.manning.com/books/functional-programming-in-c-sh... If you want to learn how to do some functional in C#. If you just need some ready-made monads, language-ext is the way to go: https://github.com/louthy/language-ext https://github.com/louthy/language-ext We tried to bring some functional ideas into our Unity3D codebase with help of these resources, it's hard but doable.
- orthoxerox 6y ago> Modern C# is already a statically-typed OO language that takes lots of lessons from functional programming and decades of scathing OO criticism (after all it's basically "Java done right"). C# 1.0 was based on Java 1.3 and modern C# has inherited a lot of its warts and added some of its own, like delegates and events.
- astrange 6y agoAnd Java is based on Objective-C, except without the good ideas like messages and with new bad ideas like checked exceptions.
- erik_seaberg 6y agoThe problem is that way too much of stdlib declared no checked exceptions, which forced any useful code to smuggle them out wrapped, or just give up and stop declaring any. Generic types in particular need exception lists; I should be able to take a Function<T, R, X1, X2, ...> arg and imply that I throw whatever it throws. Though nowadays I think maybe language support for monadic Result<T, X> is the way to go.
- thu2111 6y agoResult/Either types are fashionable but strictly worse than exceptions, in my view. Even checked exceptions should be improved rather than junked. Really, error types are only a small step above what C uses. That approach was tossed in favour of exceptions for good reasons that the industry now seems to be collectively forgetting, often with poorly reasoned arguments. FP languages like Haskell use them as if they were C because of laziness and insistence that everything be modelled as a mathematical function, not because they result in a better developer experience. Exceptions have many usability benefits that I'd be loathe to give up on.
- rualca 6y ago> Result/Either types are fashionable but strictly worse than exceptions, in my view. Why? > Really, error types are only a small step above what C uses. That approach was tossed in favour of exceptions for good reasons that the industry now seems to be collectively forgetting, often with poorly reasoned arguments. Your assertion makes no sense at all. Exceptions were designed with the explicit goal of brushing potentially unrecoverable exceptional errors under the rug. This is by no means the only use for return values. Take, for instance, HTTP requests, and the whole classes of different results that can be returned and how they are completely orthogonal to the data being returned. It would make no sense to handle this usecases with exceptions. Another thing that it seems you're entirely missing is that using a Result monad to express results allows you to explicitly discretize and define the codomain if your function, and through dimensions that help you reason and thus test about the input and output of any function. Using monad semantics to handle return types also provides a convenient way to implement what is often referred to as railway-orientrd programming https://fsharpforfunandprofit.com/posts/recipe-part2/ https://fsharpforfunandprofit.com/posts/recipe-part2/
- thayne 6y agoLet's see how C# compares to the author's wishlist. "obvious, non-negotiable things any new OO language should have": > No nulls C# has null. It looks like after C# 8.0 there is a way to require annotating types are nullable. But it isn't as elegant as a true Option type, and looks like there may still be some gotchas. > No unsafe cast It isn't entirely clear what is meant by "unsafe", but casts in C# can throw an exception if the type doesn't match at runtime, which I suspect fails to meat the criteria here. > Optional named arguments C# has this > Generics C# has generics, and while I don't have a whole lot of experience with it, it seems pretty good. > Immutability by default Fields and variables in C# are mutable by default (but can be marked as immutable with `readonly`). "less obvious choices": > Class based discoverability I think C# has this > Multiple inheritance C# does not have multiple inheritance. However default interface methods give some of the benefits. > Minimal syntax I'm not entirely sure what is meant by this, but from the comparison with scala, I think C# satisfies this. > Higher kinded types AFAICT, C# does not currently have Higher kinded types > No Exceptions C# definitely has exceptions > Unified classes and Typeclasses C# doesn't have an equivalent of typeclasses. In part because of the absence of higher kinded types (see above). > Pattern matching without destructuring C# switch statements do this. So, C# has some of what the author is looking for, but is also missing a lot. Yes, C# did take some inspiration from functional languages. Yes it did learn from some of the mistakes of earlier OO languages (notably Java). But C# is itself over a decade old and constrained by backwards compatibility. If it had been created today, would probably be substantially different. Disclaimer: I haven't used C# very much, so this is mostly from what I remember when I learned C# years ago, and what I was able to find with simple searches online.