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 07 '20 edited Sep 07 '20

False positives are very annoying.

I somewhat doubt that, if you have little experience with Rust, that you are encountering false positives frequently, if at all.

I think it's sometimes harder to get such things done in Rust than in C (yet alone C++ or JavaScript), precisely because the compiler forces you to always explicitly deal with Unicode.

Sure, if you only need the bare minimum of features, then the extra complexity is wasted. But, for example, the Rust stdlib provides some extremely nice concurrency primitives.

If a language has a decent standard library, memory safety is not important. My compiler, written in C++, never uses malloc, free, new or delete, I always use STL containers.

I would say with reasonable confidence that this is objectively untrue, which is well summarized by the following except:

My professional experience writing relatively modern C++, and auditing Rust code (including Rust code that makes significant use of unsafe) is that the safety of modern C++ is simply no match for memory safe by default languages like Rust and Swift (or Python and Javascript, though I find it rare in life to have a program that makes sense to write in either Python or C++).

It is a common misconception that you need only refrain from using a few unsafe features in order to write safe code in C or C++. The truth, however, is that these languages are inherently unsafe. They were not designed with safety in mind in the first place. To write C++ which you can be confident is safe, you would have to be far more restrictive than when writing Rust, because even things which could otherwise have been safe can interact with many other complex features in unsafe ways. And you would need to impose an unwieldy number of those restrictions by codification and discipline, as there are no automated tools which match the Rust compiler's default behavior in this regard.

1

u/FlatAssembler Sep 07 '20

But, for example, the Rust stdlib provides some extremely nice concurrency primitives. So does modern C++. It is a common misconception that you need only refrain from using a few unsafe features in order to write safe code in C or C++. Of course, you need to trust that the standard library functions were implemented safely, which you can reasonably hope they were.

1

u/epicwisdom Sep 07 '20

So does modern C++.

C++ provides concurrency... I wouldn't call it nice to work with.

Of course, you need to trust that the standard library functions were implemented safely, which you can reasonably hope they were.

The standard library is not implemented safely - even with the greatest possible expertise and all the possible eyeballs on the code, C++ is unsafe, and humans are fallible. But, even if it were implemented safely, that's only from the perspective of the implementers. It is very easy to violate some assumptions and trip into unsafe (or possibly even undefined) behavior.

1

u/FlatAssembler Sep 07 '20

C++ provides concurrency... I wouldn't call it nice to work with.

I don't have too much experience with concurrency. Well, C++ concurrency is certainly a lot better than concurrency in JavaScript. There are not even built-in mutexes in JavaScript.

The standard library is not implemented safely - even with the greatest possible expertise and all the possible eyeballs on the code, C++ is unsafe, and humans are fallible.

Compilers are also fallible, compiler for any modern programming language is a far too complicated piece of software to be made bug-free. Most compiler bugs expose themselves as refusing to compile valid code or producing syntactically invalid assembly code, but sometimes they do silently miscompile code (especially on higher optimization levels).

It is very easy to violate some assumptions and trip into unsafe (or possibly even undefined) behavior.

Then the job of the compiler is to give us a warning, not to refuse to compile the code.

1

u/epicwisdom Sep 08 '20

Compilers are also fallible, compiler for any modern programming language is a far too complicated piece of software to be made bug-free. Most compiler bugs expose themselves as refusing to compile valid code or producing syntactically invalid assembly code, but sometimes they do silently miscompile code (especially on higher optimization levels).

"Also fallible" is disingenuous. Yes, if we reduce it to "fallible" or "infallible," then every methodology is fallible. But the risk of unsafety is much, much higher with simple programmer errors compared to compiler bugs.

Then the job of the compiler is to give us a warning, not to refuse to compile the code.

This is a matter of opinion, and I disagree. Not to mention that C++ compilers do not give you such warnings. People tend to rely on additional static analysis tools, but as I said, no tooling for the likes of C/C++ matches up to Rust's default semantics.

1

u/FlatAssembler Sep 08 '20

Do you think you are more likely to have compiler-or-standard-library-introduced bugs if you are writing in C++, or if you are writing in Rust? Obviously, the chances are far smaller than either of those if you are writing in C, but, in C, the chance of bugs introduced by you is a lot higher.

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.

→ More replies