Readit News logoReadit News
grumpyprole commented on The history of C# and TypeScript with Anders Hejlsberg [video]   youtube.com/watch?v=uMqx8... · Posted by u/doppp
sfn42 · 11 days ago
C# has anonymous types which is pretty much the same thing. Though I prefer to declare actual types for most usecases, I'll only use anonymous types for intermediate results and such.
grumpyprole · 11 days ago
I certainly don't mean to knock nominal types. But I think structural types are more fundamental. A language would only need a single "newtype" or "nominal" keyword to create nominal types from structural types.
grumpyprole commented on The history of C# and TypeScript with Anders Hejlsberg [video]   youtube.com/watch?v=uMqx8... · Posted by u/doppp
sfn42 · 11 days ago
Lots of languages can infer types. And your last example with the colors is just a dictionary.
grumpyprole · 11 days ago
Most languages have poor support for structural types though. If you try and join two records together (like a SQL join), what will your favourite language infer then?
grumpyprole commented on The history of C# and TypeScript with Anders Hejlsberg [video]   youtube.com/watch?v=uMqx8... · Posted by u/doppp
socalgal2 · 11 days ago
I don't know that many languages but, having been writing lots of typescript in the last 3 years there are so many things I love about it.

It infers types. If I do

    const data = [
      { name: 'bob', age: 35, state: 'CA' },
      { name: 'jill', age: 37, state: 'MA' },
      { name: 'sam', age: 23, state: 'NY' },
    ];
Typescript knows data is an array of { name: string, age: number, state: string }. I don't have to tell it.

Further, if I use any field, example

    const avg = data.reduce((acc, { age }) => acc + age, 0) / data.length;
It knows that `age` is a number. If I go change data and add an age that is not a number it will complain immediately. I didn't have to first define a type for data, it inferred it in a helpful way.

Further, if I add `as const` at the end of data, then it will know 'state' can only be one of `CA`, `MA`, `NY` and complain if I try to check it against any other value. Maybe in this case 'state' was a bad choice of example but there are plenty of cases where this has been super useful both for type safety and for code completion.

There's insane levels of depth you can build with this.

Another simple example

    const kColors = {
      red: '#FF0000',
      green: '#00FF00',
      blue: '#0000FF',
    } as const;

    function keysOf<T extends string>(obj: { [k in T]?: unknown }): readonly T[] {
      return Object.keys(obj) as unknown[] as T[];
    }

    type Color = keyof typeof kColors;
    const kAllColors = keysOf(kColors);
Above, Color is effectively an enum of only 'red', 'green', 'blue'. I can use it in any function and it will complain if I don't pass something provably 'red', 'green', or 'blue'. kAllColors is something I can iterate over all colors. And I can safely index `kColors` only by a Color

In most other languages I've used I'd have to first declare a separate enum for the type, then associate each of the "keys" with a value. Then separately make an array of enum values by hand for iteration, easy to get out of sync with the enum declaration.

grumpyprole · 11 days ago
What you are describing is structural types. It is indeed a mystery that these are so under used, especially as they are a cornerstone of type theory. Structural types are so useful that they creep into most languages in some way. Even in Java, the Kingdom of the Nouns, where the rulers refused to merge a pair class, functions essentially take tuple arguments and these tuples don't have to be named and defined. You can't return a tuple though, so there is an unfortunate asymmetry. In Haskell and OCaml, we like to describe functions in a structural way, so com.google.android.Predicate would be just "a -> Bool". You wouldn't have to convert your com.google.guava.Predicate. But even these languages lack structural records and variants and suffer for it.
grumpyprole commented on Odin: Moving Towards a New "core:OS"   odin-lang.org/news/moving... · Posted by u/ksec
jchw · a month ago
I wonder if some day we'll look back differently on the "billion-dollar mistake" thing. The key problem with null references is that it forces you to either check any given reference to see if it's null if you don't already know, or you would have to have a contract that it can't be null. Not having null references really does solve that problem, but still in every day programs you often wind up with situations where you actually can know from the outside that some function will return a non-empty value, but the function itself is unable to make that guarantee in a way that the compiler can enforce it; in those cases, you have no choice but to face the same dilemma. In Rust this situation plays out with `unwrap()`, which in practice most reasonably-sized codebases will end up with some. You could always forbid it, but this is only somewhat of an improvement because in a lot of cases there also isn't anything logical to do once that invariant hasn't held. (Though for critical production workloads, it is probably a good idea to try to find something else to do other than let the program entirely crash in this event, even if it's still potentially an emergency.)

In other words: after all this time, I feel that Tony Hoare framing null references as the billion-dollar mistake may be overselling it at least a little. Making references not nullable by default is an improvement, but the same problem still plays out so as long as you ever have a situation where the type system is insufficient to be able to guarantee the presence of a value you "know" must be there. (And even with formal specifications/proofs, I am not sure we'll ever get to the point where is always feasible to prove.) The only real question is how much of the problem is solved by not having null references, and I think it's less than people acknowledge.

(edit: Of course, it might actually be possible to quantify this, but I wasn't able to find publicly-available data. If any organization were positioned to be able to, I reckon it would probably be Uber, since they've developed and deployed both NullAway (Java) and NilAway (Go). But sadly, I don't think they've actually published any information on the number of NPEs/panics before and after. My guess is that it's split: it probably did help some services significantly reduce production issues, but I bet it's even better at preventing the kinds of bugs that are likely to get caught pre-production even earlier.)

grumpyprole · a month ago
It's overblown until it isn't. Hoare didn't pluck that number from thin air. This is now a solved problem in modern programming languages. If Odin doesn't have this and other essential memory safety features, it's certainly not worth the massive retooling effort.
grumpyprole commented on Odin: Moving Towards a New "core:OS"   odin-lang.org/news/moving... · Posted by u/ksec
leecommamichael · a month ago
Isn't it possible for there to be downsides to doing things even when they're easy?
grumpyprole · a month ago
Yes it's the burden of proof. That's why writing Rust is harder than C++. Or why Python is easier than anything else. As a user and customer, I'd rather pay more for reliable software though.
grumpyprole commented on What .NET 10 GC changes mean for developers   roxeem.com/2025/09/30/wha... · Posted by u/roxeem
ZenoArrow · 4 months ago
> F# was pitched by Microsoft to be used in areas where Python dominates

Haha, no. Microsoft barely talks about F# at all, and has largely left the evolution of the language up to the open source community that supports it. Furthermore, you shouldn't take your cues about what a language is best suited for from marketing types, you should evaluate it based on its strengths as a language and broader ecosystem. If you seriously doubt that C# is a better comparison to F# than Python, then I suspect you haven't used either C# or F# and you're basing your views on marketing fluff.

grumpyprole · 4 months ago
Less of the personal attacks please, you know nothing about me. I actually think it is you that is missing context here. Don Syme personally visited and presented at a variety of investment banks. He was the creator not a marketing type. I was present at one of his pitches and met him. One bank, Credit Suisse ended up adopting it. Any comparisons he made to C# where based around readability and time to market (C# is very verbose and boilerplate heavy compared to both Python and F#). This was all on the 2010-2015 timeframe. Python ended up winning in these markets. My point has always been that this now puts it in a difficult position, it's simply not radical enough to disrupt but still carries the perceived "functional programming" barrier to entry.
grumpyprole commented on What .NET 10 GC changes mean for developers   roxeem.com/2025/09/30/wha... · Posted by u/roxeem
ZenoArrow · 4 months ago
Python is the world's most used scripting language, but for application programming languages there are other languages that are widely used and better to compare to F#. For example, C# and Java.
grumpyprole · 4 months ago
F# was pitched by Microsoft to be used in areas where Python dominates, especially for scripting in the finance domain and "rapid application development". So it doesn't make sense at all that C# and Java are a "better comparison".
grumpyprole commented on What .NET 10 GC changes mean for developers   roxeem.com/2025/09/30/wha... · Posted by u/roxeem
maleldil · 4 months ago
What is an example of a real functional language for you?
grumpyprole · 4 months ago
Haskell. But there are other examples of "pure functional programming". And the state of the art is dependently typed languages, which are essentially theorem provers but can be used to extract working code.
grumpyprole commented on What .NET 10 GC changes mean for developers   roxeem.com/2025/09/30/wha... · Posted by u/roxeem
ZenoArrow · 4 months ago
If Python is the only language you have to compare other languages to, all other programming languages are going to look like "Python with X and Y differences". It makes no sense to compare Python to F# when OCaml exists and is a far closer relative. F# isn't quite "OCaml on .NET" but it's pretty close.
grumpyprole · 4 months ago
It absolutely does make sense to compare it to the worlds most popular programming language, especially when dismissed as "functional programming". Who benefits from an OCaml comparison? You think F# should be marketed to OCaml users who might want to try dotnet? That's a pretty small market.
grumpyprole commented on What .NET 10 GC changes mean for developers   roxeem.com/2025/09/30/wha... · Posted by u/roxeem
maleldil · 4 months ago
If purity is a requirement for "real" functional programming, then OCaml or Clojure aren't functional. Regarding totality, even Haskell has partial functions and exceptions.
grumpyprole · 4 months ago
Both OCaml and Clojure are principled and well designed languages, but they are mostly evolutions of Lisp and ML from the 70s. That's not where functional programming is today. Both encourage a functional style, which is good. And maybe that's your definition of a "functional language". But I think that definition will get increasingly less useful over time.

u/grumpyprole

KarmaCake day4484June 30, 2015View Original