News for hackers. Stuff that matters.
Re:Rewriting TypeScript in Rust? You'D have to be by Tade0 on Wednesday December 14, 2022 @10:01AM (#33984318)
> But there's a problem. Rewriting a library like TypeScript is extremely challenging. First, "absence of [a] specification" for TypeScript's behaviour. Donny's had to infer TypeScript's behaviour mostly test cases alone.

IIRC the TypeScirpt leadership is of the position that the implementation is the specification, which is unfortunate, because it means that the bugs in the implementation are necessarily part of the specification as well.

Re:Rewriting TypeScript in Rust? You'D have to be by miohtama on Wednesday December 14, 2022 @12:27PM (#33986720)
For the sake of being fair for other programming languages, what are the languages with proper specification? C, C++, JavaScript, others?
Re:Rewriting TypeScript in Rust? You'D have to be by randomdata on Wednesday December 14, 2022 @12:53PM (#33987081)
Go is staunch about its specification. To the point that the Go team maintains two independent compiler implementations to ensure that "features"/bugs in one implementation doesn't end up defining the standard.
Re:Rewriting TypeScript in Rust? You'D have to be by tristan957 on Wednesday December 14, 2022 @08:22PM (#33993696)
Is the other compiler you are referring to gcc-go?
Re:Rewriting TypeScript in Rust? You'D have to be by recov on Thursday December 15, 2022 @08:55AM (#33999500)
There's actually 3 now from google afaik

- gc

- gccgo

- gollvm [0]

[0] https://go.googlesource.com/gollvm/

Re:Rewriting TypeScript in Rust? You'D have to be by munificent on Wednesday December 14, 2022 @02:06PM (#33988411)
Dart has a complete specification. It tends to lag somewhat behind the most recent features (which are documented in separate language proposals), but we keep it as current as we can.

Maintaining a language specification is a lot more work than people realize, and a job that few have the skills to do well.

Re:Rewriting TypeScript in Rust? You'D have to be by xchkr1337 on Wednesday December 14, 2022 @02:06PM (#33988419)
In my opinion the presence of undefined behavior in the C/C++ specification makes it no better than the "specification by implementation" approach
Re:Rewriting TypeScript in Rust? You'D have to be by spac on Wednesday December 14, 2022 @04:16PM (#33990710)
without a specification you can never tell with certainty if there's a bug
Re:Rewriting TypeScript in Rust? You'D have to be by yencabulator on Wednesday December 14, 2022 @04:57PM (#33991196)
C/C++ "undefined behavior" means your program is wrong and not within the spec, not that different compiler implementations might differ. There is no scenario in which any code with UB is valid, regardless of what compiler implementation you use. That's very different. (And IMHO a horrible feature of the spec, but it's there for historical reasons.)

C/C++ spec does have some "implementation defined behavior", which is where you can't rely on what will happen unless you know what compiler you're targeting. They are explicitly listed out as such, and not that common.

Re:Rewriting TypeScript in Rust? You'D have to be by Alifatisk on Wednesday December 14, 2022 @02:21PM (#33988665)
Ruby?
Re:Rewriting TypeScript in Rust? You'D have to be by steveklabnik on Wednesday December 14, 2022 @04:39PM (#33990980)
If you're referring to the ISO spec, it's effectively completely irrelevant.

If you're talking about ruby/spec, a comprehensive test suite is really great, but is also not what most people think about when they think of a spec, though it also may count! You could even argue that such a thing is better than a traditional spec.

Re:Rewriting TypeScript in Rust? You'D have to be by Alifatisk on Wednesday December 14, 2022 @04:42PM (#33991013)
Yes, I was thinking about the latter but was unsure if it counted. Yes, looking at the spec has been a helpful strategy for me to understand how something is supposed to work.
Re:Rewriting TypeScript in Rust? You'D have to be by G3rn0ti on Wednesday December 14, 2022 @02:39PM (#33988993)
Raku fka Perl 6.
Re:Rewriting TypeScript in Rust? You'D have to be by wtetzner on Wednesday December 14, 2022 @03:17PM (#33989763)
Standard ML, Scheme, Common Lisp, Java.
Re:Rewriting TypeScript in Rust? You'D have to be by duped on Wednesday December 14, 2022 @03:34PM (#33990096)
I guess you have to define "specification" because there's a spectrum. A full book describing the formal syntax, semantics, type system, and standard library/built ins (and macros, preprocessing, compiler flags, what have you) is fairly rare because of how big it needs to be.

Partial specification like the grammar, the type system, etc are more common (particularly because they're so useful for writing one implementation, let alone multiple!).

Re:Rewriting TypeScript in Rust? You'D have to be by Uvix on Wednesday December 14, 2022 @04:27PM (#33990856)
C# has a spec, although it's a few versions out-of-date. https://github.com/dotnet/csharpstandard/blob/draft-v7/stand...
Re:Rewriting TypeScript in Rust? You'D have to be by ape4 on Wednesday December 14, 2022 @10:33AM (#33984882)
Maybe the first step should be writing down a spec of TypeScript.
Re:Rewriting TypeScript in Rust? You'D have to be by progx on Wednesday December 14, 2022 @11:45AM (#33986105)
Boring! That is the problem, nobody want to do such boring things.
Re:Rewriting TypeScript in Rust? You'D have to be by yencabulator on Wednesday December 14, 2022 @05:03PM (#33991262)
Nobody except Microsoft is able to write a spec for Typescript. Microsoft has already declared that the implementation is it, any spec a random person writes will just be ignored.
Re:Rewriting TypeScript in Rust? You'D have to be by epolanski on Wednesday December 14, 2022 @08:34PM (#33993819)
It's not about boredom, it's simply an implementation derived language as are Haskell or PHP or Python.

Having a spec is really valuable only if you intend to target different environments, that's a non-goal for TS it simply transpiles, rather than compiles, into another programming language.

It's also bound to follow each new JS feature and change.

Re:Rewriting TypeScript in Rust? You'D have to be by randomdata on Thursday December 15, 2022 @02:37AM (#33996405)
The value of a spec is having something that resolves how to deal with quirks discovered in an implementation. Absent of a spec, any quirks become a part of the language.

Which is okay as long as you only ever have one implementation, but when you want to, say, reimplement Typescript in Rust then you have to duplicate all of the quirks that came before, even in cases where nobody has yet realized that the quirk exists. Failure to do so means that your implementation won't be compatible with the canonical implementation.

At the other end of the spectrum, the Go project maintains two independent compiler implementations to ensure that the spec is implementable and to see that a single implementation, with all of its quirks, doesn't end up defining the language. That puts a lot of confidence in the spec to guide additional implementations, but, of course, is a lot of added work.

Tradeoffs, as always.

Re:Rewriting TypeScript in Rust? You'D have to be by Kuinox on Wednesday December 14, 2022 @10:57AM (#33985326)
Specification are not immune to bugs.
Re:Rewriting TypeScript in Rust? You'D have to be by rk06 on Wednesday December 14, 2022 @11:21AM (#33985718)
But you can use them as evidence that tsc is not working as it "should". Then go ahead and fix tsc Or spec or both as needed.

Without the specs, there is no way to tell if tac is behaving as developers intended it

Re:Rewriting TypeScript in Rust? You'D have to be by gfxgirl on Wednesday December 14, 2022 @12:24PM (#33986694)
It's not doing what I expect. Oh? Change the spec

It's not doing what I expect. Oh? Change the code

How is that different from now?

Re:Rewriting TypeScript in Rust? You'D have to be by htkibar on Wednesday December 14, 2022 @12:51PM (#33987037)
Allows competing implementations and saves TS from MSFT
Re:Rewriting TypeScript in Rust? You'D have to be by rk06 on Wednesday December 14, 2022 @01:58PM (#33988257)
Right now:

1.It's not doing what I expect.

2.Is it intentional behavior or a bug?

3. Let's ask on github/reddit etc

With Special:

1. It is not doing what I expect

2. Is this a spec issue or code issue?

3. Let's check spec.

4a. "Working as specified". Shit. Hope spec improves in future versions

4b. It is not working as spec says. Let's file a bug on tsc.

And that is the difference.

Re:Rewriting TypeScript in Rust? You'D have to be by steveklabnik on Wednesday December 14, 2022 @04:40PM (#33990993)
The real rub is in step 4: it is not always easy to determine what the spec means. And then you're basically back to "let's ask on github/reddit etc."
Re:Rewriting TypeScript in Rust? You'D have to be by yencabulator on Wednesday December 14, 2022 @05:06PM (#33991286)
Just because the comprehensiveness of something is on a spectrum is not a reason to just not bother and have none at all.

Also, when done well a spec is a great way to learn & understand the language too. http://golang.org/ref/spec is so much more usable than Typescript's docs.

Re:Rewriting TypeScript in Rust? You'D have to be by steveklabnik on Wednesday December 14, 2022 @05:36PM (#33991693)
I agree that specifications are useful. I also think they're often presented as a panacea. It is important to acknowledge that they're a tool, with pros and cons, like any tool. The existence of a specification does not immediately mean that any and all ambiguities are resolved.
Re:Rewriting TypeScript in Rust? You'D have to be by tshaddox on Wednesday December 14, 2022 @06:45PM (#33992619)
Still doesn’t seem like much a difference. If you run into 4a you still file an issue somewhere.
Re:Rewriting TypeScript in Rust? You'D have to be by randomdata on Thursday December 15, 2022 @03:46AM (#33996847)
If an implementation isn't doing what you expect, is it just an issue with that single implementation? A problem with all implementations? A problem with what you expect? If another implementation does do what you expect is it correct or just lucky?

A spec resolves such discrepancies. Indeed, the spec may be where the problem is, but once the spec is corrected then implementations know what they must do. Absent of a spec, who knows?

Re:Rewriting TypeScript in Rust? You'D have to be by kristiandupont on Wednesday December 14, 2022 @04:46PM (#33991052)
And such a spec can be

1) a reference implementation,

2) written in natural language, or

3) written as formal semantics

#1 is the same as the current situation. With #2, you might get a bit closer but natural language has many ambiguities and idiosyncrasies that can render it useless in various situations.

You can try to define formal semantics, but that is not only hard to create, it's also hard to translate into an implementation, adding significant overhead in both parts of the process. And there can still be bugs, and there can still be edge cases with undefined behavior.

Re:Rewriting TypeScript in Rust? You'D have to be by Kuinox on Wednesday December 14, 2022 @06:57PM (#33992780)
Code, called implementation here, is a specification written in a certain grammar that is executed.

You want 'evidence' tsc is not working as it should, by writting a duplicated less specifying specification that would sometimes conflict with the typescript one.

It make me remember the people that wanted to specify everything and generate implementation from it: that called a programming language.

Re:Rewriting TypeScript in Rust? You'D have to be by rk06 on Wednesday December 14, 2022 @09:03PM (#33994099)
Code is meant for machine.

Specification is meant for compiler author. Writing one of them is easier than otht

Re:Rewriting TypeScript in Rust? You'D have to be by randomdata on Thursday December 15, 2022 @03:08AM (#33996588)
They are not mutually exclusive. Code identifies a class of language. Specification identifies something that is conveyed through language. Specification can be provided in code.

In fact, while poorly named, what we call testing is actually specification. A test suite specifies for software authors what a program is intended to do and how it is intended to be used. Of course, as a nice side bonus, because the specification is delivered in code the documentation can be validated for truthfulness against an implementation by machine.

Re:Rewriting TypeScript in Rust? You'D have to be by remexre on Wednesday December 14, 2022 @11:04AM (#33985451)
But at least formal methods tools can be applied directly to the specification, to show properties like "well, if you carve out this subset of TypeScript, you have something you can safely eval()" or "you can never have type errors with this usage of this construct in this way."
Re:Rewriting TypeScript in Rust? You'D have to be by brundolf on Wednesday December 14, 2022 @01:20PM (#33987482)
> "well, if you carve out this subset of TypeScript, you have something you can safely eval()" or "you can never have type errors with this usage of this construct in this way."

This kind of certainty is very at odds with TypeScript's design philosophy and the way it (necessarily) works. Because it's overlaid on JavaScript, and JavaScript is wildly dynamic (Proxies, prototype modification, etc), almost nothing is known with absolute certainty. To deal with that, TypeScript makes a lot of "optimistic" assumptions, but holds them lightly (i.e. its assumptions may cause type checks to pass when they shouldn't, but it's not going to lean on them for anything that could really blow up if they're wrong)

IMO it strikes a very good balance given the constraints - not criticizing the designers at all - but TypeScript has to be treated differently than other statically typed languages might be, because nearly everything it knows/says is just a "probably"

Re:Rewriting TypeScript in Rust? You'D have to be by zokier on Wednesday December 14, 2022 @11:21AM (#33985720)
> But at least formal methods tools can be applied directly to the specification

What makes you think that? For example for C language it has been significant effort to translate the specification to something analyzable by tools

Re:Rewriting TypeScript in Rust? You'D have to be by namuol on Wednesday December 14, 2022 @04:40PM (#33990995)
Neither are programs, tests, or type definitions, but these are generally still valuable things to have.
Re:Rewriting TypeScript in Rust? You'D have to be by the_gipsy on Wednesday December 14, 2022 @05:22PM (#33991507)
That's one way to keep tight control.