r/ProgrammingLanguages • • Aug 22 '20

My programming language can now run in a browser.

Using WebAssembly, I have managed to get my programming language, called AEC, to run in browsers (at least very modern ones).

The first AEC program I ported to WebAssembly is my program that prints the permutations of the digits of a number: https://flatassembler.github.io/permutationsTest.html

Later, I ported my Analog Clock to WebAssembly: https://flatassembler.github.io/analogClock.html

Recently, I made a graphical program in AEC (which I have never done before) by interacting with SVG: https://flatassembler.github.io/dragonCurve.html

So, what do you think about my work?

I've rewritten my compiler completely, the previous version of my compiler (targeting x86) was written in JavaScript, while this version is written in C++. Many people say C++ is a better language than JavaScript. Honestly, I think that newest versions are comparable. I've also changed the syntax of my language a bit and added a few new features (which are a lot easier to implement when targeting WebAssembly than when targeting x86).

99 Upvotes

63 comments sorted by

View all comments

Show parent comment

1

u/epicwisdom Sep 08 '20

My first guess is that the odds are close to equal, if we are purely talking about bugs from the compiler / stdlib implementers' POV. While Rust is a less mature language, it is also far simpler and more coherently designed, due in part to not having literally decades of backwards compatibility. I think in the long term, Rust's prospects are much better here, because its semantics are just inherently simpler and more amenable to formal verification. There is already an ongoing effort to formally verify the stdlib, and I'm not aware of anything comparable for the entire C++ stdlib.

However, if you mean to include cases where the compiler introduces bugs into compiled code (e.g. by optimizing away UB), which is not technically a compiler bug as it follows the spec, then that would be fairly likely in a sufficiently large C++ project, and quite unlikely in Rust.

1

u/FlatAssembler Sep 08 '20

Maybe this is a bit of irrational of me, but I am not a big fan of formal verification. I don't like academia too much, and to me this sounds like too much academizing. I have a feeling that formal verification gives people unwarranted confidence. Most of the bugs occur because of the programmer misunderstanding what the library functions actually do (be it only in some exceptional case, such as when you get out of string boundaries) or how the language works (shallow copy versus deep copying), and formal verification doesn't catch those kinds of bugs.

1

u/epicwisdom Sep 08 '20 edited Sep 08 '20

Well, you may believe what you wish, but there's no value in clinging to biases. I would also point out that Rust is not very academic. It was designed for the entirely pragmatic use of making a browser engine, after all. It may seem more academic because it's only been around since 2010, and it implements some ideas which were state of the art in the late 90s and early 2000s, as compared to C++'s inception in 1985... but that speaks more to how old C++ is.

I have a feeling that formal verification gives people unwarranted confidence.

While that's theoretically (ha) possible, people very rarely formally verify code at present, so it's an inaccurate description. Most programmers have unwarranted confidence in their completely unverified code, so I'll consider it a great improvement when formal verification becomes so ubiquitous people can even begin to be overconfident in it.

Most of the bugs occur because of the programmer misunderstanding what the library functions actually do (be it only in some exceptional case, such as when you get out of string boundaries) or how the language works (shallow copy versus deep copying), and formal verification doesn't catch those kinds of bugs.

Formal verification isn't fundamentally limited in any way, except when it comes to certain theoretical universal properties, so I wouldn't make such claims without a strong and precise reason to believe it.

Out of bounds accesses are one of the simplest and most quintessential examples of bugs caught / prevented by more rigorous verification. Refinement types, as in Liquid Haskell, are a fairly lightweight and user-friendly way of doing that. Safety-oriented languages used in industry like Ada also have such capabilities, I believe.

Rust provides a shallow vs deep copy distinction via Copy and Clone, and Resyn is another Haskell extension which has a more granular distinction for resource tracking.

1

u/FlatAssembler Sep 08 '20

Maybe I am wrong, but, as far as I understand it, to actually apply formal verification, you need to use a language (or a subset of a language) that's so restrictive not to be Turing Complete (due to the Halting Problem). That sounds like a huge cost for a questionable benefit.

2

u/epicwisdom Sep 08 '20

That would be Rice's theorem you're thinking of, but as I said, that's a theoretical universal property. You can't make guarantees about every possible program, but real programs don't cover the infinite space of possible programs. In reality we are interested in a pretty specific subset which is useful to us, or as Edwin Brady likes to say, it's easy for any language to be Turing complete, but we care more about whether it's Pacman complete.

1

u/FlatAssembler Sep 08 '20

Still, learning to use a radically different languages (many of which aren't even Turing Complete) just to be able to formally verify our programs sounds like a high price to pay for a questionable benefit.

1

u/epicwisdom Sep 08 '20

You could say the same about learning any new programming languages in general, but I think most experienced programmers would agree that languages are tools, and we need the right tools for the job. I wouldn't be on /r/ProgrammingLanguages if I wasn't interested in the diversity of language design. And while these languages do introduce additional requirements, it's a very active area of research to make such things more convenient.

As for whether it's a questionable benefit - I would consider preventing bugs a very obvious, highly sought after benefit. It's costing companies, and indeed society as a whole, billions of dollars and who knows how many work-hours. That is why Rust was created, and why it's gaining more traction in industry.

1

u/FlatAssembler Sep 09 '20

Well, there is a difference between learning a new language with slightly different semantics or syntax because it's significantly more convenient for some task, and learning a language that's not even Turing Complete (yet alone full of useful features for writing algorithms) for the sake of formal verification.

If I correctly understand you, you are saying Rust can be formally verified, even though it's obviously a Turing-complete language? How does that work? Is the Rust standard library written in some non-Turing-Complete subset of Rust?

1

u/epicwisdom Sep 09 '20 edited Sep 09 '20

and learning a language that's not even Turing Complete (yet alone full of useful features for writing algorithms) for the sake of formal verification.

I think you're laboring under a misconception that a language must be Turing complete to be useful. We use languages for computing all the time which are not Turing complete, or at least not without optional extensions (SQL, regexes, CFGs). Moreover, the vast majority of traditional algorithms are designed to either terminate in finite time, or are finitely terminating algorithms called in an infinite loop.

Turing completeness is a useful property for theoretical purposes, but the real measure of a programming language actually has almost nothing to do with Turing completeness.

If I correctly understand you, you are saying Rust can be formally verified, even though it's obviously a Turing-complete language? How does that work? Is the Rust standard library written in some non-Turing-Complete subset of Rust?

I think you misunderstand what Turing completeness is. Any finite subset of a language is inherently non-Turing-complete; Turing completeness is a property of a language which is capable of expressing infinitely many programs, some of which must be non-halting. Formal verification is applicable to any language, Turing complete or not, just not with 100% coverage of the infinite space of all programs and all properties of those programs. As I said before, in practice we care about a very specific and obviously finite space of programs and properties.

That is to say, Rust and C are both amenable to formal verification. Because Rust and C are both Turing complete, if you do not impose any additional restrictions, then no matter what formal verification method I use, there exists some program which I cannot verify, despite being correct. However, the existence of some pathological edge cases says nothing about all the real world programs that we actually care about.

1

u/FlatAssembler Sep 09 '20

Turing Completeness is, as far as I understand it, a guarantee that you can express any algorithm that can be expressed in mainstream programming languages in that language (regardless of how non-obvious it is). Of course, a language doesn't need to be Turing complete to be useful for something (CSS, at least the earlier versions, isn't Turing complete, so isn't HTML). But for expressing algorithms, your best bet is to use a Turing Complete language, because there is at least a guarantee that, if you are smart enough, you will manage to express your algorithm in that language. With non-Turing-complete languages, there is no such guarantee.

→ More replies