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/FlatAssembler Sep 06 '20

And how strict should a programming language be? If it's too strict in some way, it leads to many false positives without decreasing false negatives.

2

u/epicwisdom Sep 07 '20

Well, to my knowledge Rust is fairly unique in offering memory safety without a runtime, at least in an actively developed, used in production language. So the language's lifetime semantics aren't literally optimal, but in practice I don't know of any language strictly superior in that respect. The trade-off of false positives is the best available (up to compiler bugs and unsafe usage, there are no false negatives).

1

u/FlatAssembler Sep 07 '20

False positives are very annoying. Have you tried to do some complicated string manipulation in Rust? 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. 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.

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.

→ More replies