News for hackers. Stuff that matters.
Re:Why I love Rust for tokenising and parsing by pjmlp on Friday November 08, 2024 @07:15AM (#42086261)
It is worse than that, as Go initially lacked generics (introduced by CLU and ML in 1976), still doesn't do even basic Pascal enumerations (1970) rather the iota/const dance, let alone the 1990's programming language design surface.

I only advocate for it on the scenarios where a garbage collected C is more than enough, regardless of the anti-GC naysayers, e.g. see TamaGo Unikernel.

Re:Why I love Rust for tokenising and parsing by Thaxll on Friday November 08, 2024 @08:19AM (#42086631)
So every language have to implement every features released in the last 50 years?
Re:Why I love Rust for tokenising and parsing by pjmlp on Friday November 08, 2024 @08:55AM (#42086848)
Not necessarly, but designing for stone age computers isn't ideal either, even C, Fortran and COBOL have progressed during those 50 years.
Re:Why I love Rust for tokenising and parsing by treyd on Friday November 08, 2024 @08:26AM (#42086674)
I expect it to implement features that have become ubiquitous in every other mainstream language from the last 30 years, yes.
Re:Why I love Rust for tokenising and parsing by Thaxll on Friday November 08, 2024 @08:52AM (#42086827)
That's how you end up with C++ and soon C#.
Re:Why I love Rust for tokenising and parsing by biorach on Friday November 08, 2024 @10:10AM (#42087419)
No, the person you were replying to was advocating for the intersection of ubiquitous features. C++ seems to be aiming for the union.
Re:Why I love Rust for tokenising and parsing by pjmlp on Friday November 08, 2024 @08:56AM (#42086867)
We also end up with C23, Fortran 2023, COBOL 2023, Scheme R7RS,... even those oldies embrace modern ideas.
Re:Why I love Rust for tokenising and parsing by miohtama on Friday November 08, 2024 @09:47AM (#42087229)
When we can call it Go++
Re:Why I love Rust for tokenising and parsing by umanwizard on Friday November 08, 2024 @02:00PM (#42089523)
It’s really not. The strawman that if we add a few features that have stood the test of time in every other language we’ll end up with C++ is just not true. Nobody is proposing adding SFINAE-based conditional compilation, rvalue references, multiple inheritance, or any of the million other Byzantine features that make C++ virtually impossible to use correctly. Adding sum types and a match statement does not necessarily start you down that path.
Re:Why I love Rust for tokenising and parsing by randomdata on Friday November 08, 2024 @02:35PM (#42089795)
But then what purpose would it serve? The last 30 years has brought no lack of new languages, not to mention evolution of older languages. Just use one of them.

The purpose of creating yet another language with Go was to break from what everyone else was doing, to see if a "simple" language would stop developers from playing with fun language toys all day to instead focus on actual engineering.

Arguably it was successful in that.

Re:Why I love Rust for tokenising and parsing by pjmlp on Saturday November 09, 2024 @01:54AM (#42092931)
The purpose was to get rid of C++ compile times and replace C++ with Go, failing that, they decided to pivot the story.

https://commandcenter.blogspot.com/2012/06/less-is-exponenti...

They also got lucky with Docker and Kubernetes, pivoting from Python and Java respectively into Go.

Re:Why I love Rust for tokenising and parsing by randomdata on Saturday November 09, 2024 @08:55AM (#42094438)
Numerous languages already got rid of C++ compile times. That didn't necessitate another one. Certainly Go wouldn't want C++ compile times any more than any other language, but as far as justifying its creation that would not be sufficient justification alone.

Legend has it that Go was conceived while waiting for a C++ program to compile, if that's what you are thinking of?

Re:Why I love Rust for tokenising and parsing by randomdata on Friday November 08, 2024 @11:07AM (#42087880)
> still doesn't do even basic Pascal enumerations

The term you are looking for is sum types (albeit in a gimped form in the case of Pascal). Enumerations refer to the value applied to the type, quite literally, and is identical in Pascal as every other language with enumerations, including Go. There is only so much you can do with what is little more than a counter.

Re:Why I love Rust for tokenising and parsing by samatman on Friday November 08, 2024 @12:35PM (#42088711)
I'm fairly sure he's referring to enumerations actually.

Pascal doesn't require case matching of enumerations to be exhaustive, but this can be turned on as a compiler warning in modern Pascal environments, FreePascal / Lazarus and such.

Go only has enums by convention, hence the "iota dance" referred to. I've argued before that this does qualify as "having enums" but just barely.

It wouldn't have been difficult to do a much better job of it, is the thing.

Re:Why I love Rust for tokenising and parsing by randomdata on Friday November 08, 2024 @01:00PM (#42088950)
> Pascal doesn't require case matching of enumerations to be exhaustive

Normally in Pascal you would not match on the enumeration at all, but rather on the sum types.

    type
       Foo = (Bar, Baz)

    case foo:
       Bar: ...  // Matches type Bar
       Baz: ...  // Matches type Baz
The only reason for enumerations in Pascal (and other languages with similar constructs) is because under the hood the computer needs a binary representation to identify the type, and an incrementing number (an enum) is a convenient source for an identifier. In a theoretical world where the machine is magic you could have the sum types without enums, but in this reality...

Thus, yes, in practice it is possible to go around the type system and get the enumerated value out with Ord(foo), but at that point its just an integer and your chance at exhaustive matching is out the window. It is the type system that allows more flexibility in what the compiler can tell you, not the values generated by the enumeration.

> Go only has enums by convention

"Enums by convention" would be manually typing 1, 2, 3, 4, etc. into the code. Indeed, that too is an enumeration, but not as provided by the language. Go actually has enums as a first-class feature of the language[1]. You even say so yourself later on, so this statement is rather curious. I expect you are confusing enums with sum types again.

[1] Arguably Pascal doesn't even have that, only using enums as an implementation detail to support its sum types. Granted, the difference is inconsequential in practice.

Re:Why I love Rust for tokenising and parsing by samatman on Friday November 08, 2024 @03:54PM (#42090389)
Pascal enums are not sum types, because they are not the sum of multiple types. They are an enumeration of discrete values, which is why they're called enums.

Sum types in Pascal are called variant records:

  type
    FooKind = (Foo, Bar, Baz); (* An enum *)

    FooOrBaz = record (* This is the sum type *)
      case foo: FooKind of
        Foo: (quux: Double);
        Bar: (zot, zap: Double);
        Baz: (xyzzy: String);
      end
Rust conflates the 'enum' keyword with sum types. Pascal does not do this. One of us is confused about what a sum type is. It isn't me.

As for Go, my full opinion on that subject may be found here. If you're... curious. Let's say.

https://news.ycombinator.com/item?id=40224485

Re:Why I love Rust for tokenising and parsing by randomdata on Friday November 08, 2024 @04:04PM (#42090469)
> This is the sum type

This is the exact same thing, except in addition to the tag there is also a data component. Yes, this is the more traditional representation of sum types, but having an "undefined" data component is still identifiable as a sum type. It’s the tag in the union that makes it a sum type.

In Typescript terms, which I think illustrates this well, it is the difference between:

   { kind: 0 } | { kind: 1 }
and

   { kind: 0, data: T } | { kind: 1, data: U }
Which is to say that there is no difference with respect to the discussion here.

> They are an enumeration of discrete values

Yes, the "tag" is populated with an enumerator. There is an enumerator involved, but is outside of the type system. It's just an integer. The additional information you can gain from it, like exhaustive matching, comes at the type level.

Re:Why I love Rust for tokenising and parsing by samatman on Friday November 08, 2024 @07:40PM (#42091653)
There's absolutely a difference between an enumeration and a sum type.
Re:Why I love Rust for tokenising and parsing by randomdata on Saturday November 09, 2024 @08:52AM (#42094420)
Exactly. One describes a type, the other a numberer. Very different concepts, even if the latter is often used in the implementation of the former (e.g. in Pascal and Rust). Glad to see you are past your earlier confusion.
Re:Why I love Rust for tokenising and parsing by samatman on Saturday November 09, 2024 @11:30AM (#42095259)
You do not understand what a sum type is. At all.

There are innumerable ways you can rectify this lack of understanding if you want to.

Re:Why I love Rust for tokenising and parsing by randomdata on Sunday November 10, 2024 @10:04AM (#42100598)
There may be innumerable (ironic) ways for someone else to explain what it means, but we are here to understand what you mean. The only logical way to achieve that is for you to tell us.

1. If you have a pet sum type definition, let it be known. But traditionally, a sum type is better known as a discriminated or tagged union. So far, this is what we understand Pascal offers: A union type that discriminates its subtypes by an enumerated value.

2. The tag that discriminates the type within the union (or whatever your explanation above ends ups calling it) is, in implementation, generated by a process that assigns a number to each entity; something also true of Rust. This is undeniable, as proven by the use of Ord and mem::discriminant. If you have another name for that numberer, if not an enumerator, let it be known.

Re:Why I love Rust for tokenising and parsing by mattpallissard on Friday November 08, 2024 @09:41PM (#42092180)
> Go initially lacked generics

And even though it has them now, the generics syntax is pretty clunky IMO.