133 points · by FairDune · 5y ago · 105 comments
Try Elm as a simple example (can be done in a weekend), it'll probably blow your mind. You don't have to write type annotations at all, but the compiler complains at build time if the same function is called with two different types in two places.
That's also the difference in 'philosophy' between OCaml, F# and Haskell. Haskell has the 'same' global type inference but the community sees them as (often only ;) documentation.
The reasons are simple: it's promoted by a big company. Same reason why C# and Go are popular.
Won't be back to static typing for a while unless I'll need higher precision and higher reliability module.
The funny .. or sad.. part is that the c#9 explicit ~verbose style would have been the only one accepted before. If you wrote implicitely typed variables people would get angry (I think there are many online articles about how java 9 `var` was bad)
It can be both. Type inference isn't a brand-new idea, but it still takes work to diffuse it into mainstream, practical languages, especially retrofitting it onto existing languages that weren't designed for it. That still counts as innovation in my book.
I still remember how ugly and tedious STL iterators were in C++. Now it’s just “auto”. LINQ also wouldn’t work without type inference.
main = do
putStrLn "Who are you?"
name <- readLn
putStrLn ("Hello, " ++ name)
There. Do you really need to know something about monads to understand that example? No.Do you need to know how do syntax and the assignment operator <- works? Sure. But that has nothing to do with category theory. That's just syntax.
I’m doing a take 2 now of getting into Haskell again but ignoring advanced language features (unless forced on me by a library) and ignoring category theory. The goal this time is using Haskell to just build stuff.
Having worked recently in it, I found Java to be relatively (as a language, not for tooling) backwards compared to C#.
Every generation must learn this for themselves though.
* `operator=` and `operator ,`
* `operator new` and `operator delete`
* `operator +=` overloaded differently from `operator +`
* `operator &&` and `operator ||` overloading works differently in C#, so that it preserves the short-circuiting behavior
* `operator ++` only can be overloaded once in C#, with the compiler automatically handling the difference between pre- and post-increment
But more crucially, the C# standard library uses operator overloading only for types like `decimal` and `BigInteger`. C# programmers can go years without ever overloading an operator, while still profiting from it whenever they use `BigInteger`.
It's very different from the C++ culture where * everyone needs to learn about how to overload `operator=` (for memory management)
* the standard library encourage abuses of operator overloading such as shift operators for iostreams
It should be unsurprising novice programmers abuse operator overloading when the C++ language teaches them exactly that.The language kind of put itself into a corner when what C# calls `MoveNext` is called `++` (with two variants of course) and what C# calls `Current` is called `*`. Taking what mathematically worked for iterating an array and taking it piecemeal to define your syntax is the kind of operator overloading that is a bad idea.
We who? From where I stand people are fine with operator overloading where it makes sense and C++ is far from being the only language with this feature.
Problem comes when shitty programmers get orgasmic about some language feature and try to use it everywhere to everyone's detriment.
You’re also likely to discover that while C# the language is amazing, the CLR runtime looks frankly minor league when compared to the JVM.
This is comically backwards from my experience. I often see near-native optimized performance on C#/CLR, where I see similar code (SIMD friendly loops) literally hundreds if not thousands of times slower than it should be in Java.
Oracle engineers did the first implementation for Java 7, more recently it's mostly contributions from Intel, AMD and ARM [1].
[1] https://cr.openjdk.java.net/~vlivanov/talks/2019_CodeOne_MTE...
OpenJDK, GraalVM, Open J9, Aicas, PTC, microEJ, Azul, Amazon,....
Java has higher peak JIT performance though after Rosalyn was introduced C# has made strides at closing that gap on many metrics. GC algorithms are more advanced, namely ZGC and Shenandoah. I would elaborate but I don't want to turn this post into an actual essay. JVM is more configurable. This is a double edged sword, it heavily favors users that have spent the time to really understand the platform but it has created a reputation of the JVM being hard to operate. JVM class loaders and the new(ish) Jigzaw module system are very powerful, especially for shipping customized/cut-down JVM + stdlib when you need to do distribution. JVM has better portability. .NET Core has obviously changed the game but other platforms are still treated second class to Windows in many ways. GraalVM is reviving the guest language ecosystem of the JVM. Clojure, Scala and Kotlin have all remained reasonably strong but there was a dark period there for Jython/JRuby and friends. GraalVM is changing the tide here and I have already been able to leverage this over Nashorn to embed essentially native speed JS code into one of my Java programs.
CLR has better primitive types, JVM's project Vahalla may resolve this. The CLR/.NET tends to introduce features at a quicker pace than the JVM/Java, this I feel is CLR's double edged sword. Async/await being the key example. It's been in the CLR for what feels like forever now vs JVM which is only now just getting close to landing Loom. However I feel like Loom is an infinitely better solution to the problem that leverages the unique advantages of JIT compiled VM languages that rely on relatively little unmanaged code. The experience on the CLR is much more integrated assuming you are on the well trodden path. i.e VS + Windows 10. MSIL is much much more pleasant than JVM bytecode in my experience and the community developed tooling for working with it is great. Optimizing programs on CLR is easier than JVM, it takes comparatively less effort to write allocation free code and get great memory layout using primitive arrays etc for high performance code. CLR interacts better with native code. JNI is poor in comparison. Project Panama could make this better on the JVM side.
This is by no means a complete list of ways the two differ, this is just my experiences having written a decent chunk of code for both.
FWIW I prefer the JVM but if I am forced not to use the JVM the CLR is the very next thing I propose.
https://docs.microsoft.com/en-us/dotnet/csharp/language-refe...
Lambdas can also have attributes now, too.
The F# style is enabled by a set of features - some of which would be really hard to add to C# (such as currying and global type inference) - but even if they were added, the millions(?) of C# developers would be unlikely adopt the functional style just because it was possible. A language is not just a list of features; each language has its own culture and "idiomatic" way of doing things.
https://devblogs.microsoft.com/dotnet/whats-new-in-fsharp-6/
Java had two tech advantages over C#: It officially ran on platforms other than Windows and ran well, and their JVM was far ahead of the MS CLR.
Both of these things went away/are going away.
What really remains is Java's reputation over "Embrace, Extend, Extinguish Microsoft" (tho Oracle has been busy trying to destroy Java's reputation ever since they bought Sun) and the larger eco-system/community/existing code bases and sunk costs.
That's all of no use to me (I don't work on projects like that), but let's not just shove that aside.
I also don't really agree with this:
> look and wait and do a half-assed implementation of a lot of tried-and-true C# language features some years later
Loom looks like a much more interesting approach compared to async/await hell (I've done it enough to know). I like records and upcoming "withers" much more than { get; set; } (which is easy to write but promotes shit code) because of their focus on immutability. (Yes, I am aware of { get; } and recently introduced { get; init; }, it doesn't really help with the thing withers are trying to solve — copying most fields while replacing one or two values, keeping both the old and the new value immutable). LINQ? maybe, I miss expression trees in Java.There weren't other buyers in town, besides IBM, which I probably would have managed it just as Oracle has, given that the trio have been around in Java world since the early days.
I hate they delayed the introduction of Algebraic Data Types again. Maybe they will appear in C# 11.
Using ADT in F# makes it a breeze to do domain modeling.
For example file scoped namespace is a very simple but great change, improvement for lambdas, improvement for structs, all of this make it nicer and simpler to write readable code.
Edit: I would also love to see ADT in C#!
This version brings quality of life changes that make it simpler and nicer to write readable code, which is great to see IMHO.
I do wonder what was limiting them before
Heck, I'd say, by now with local functions most lambdas that previously would have been a local could now just be a local function.