HNHacker News
TopNewBestAskShowJobs

nickmqb

541 karma · joined February 27, 2019

I'm the author of Muon, a modern low-level programming language: https://github.com/nickmqb/muon
submissionscomments
nickmqb··on Building a language server for Muon
To step back a bit, the way I see it, the main goal as a language designer is to ensure that users can be productive in the language. Many factors play a role here. Language features are an obvious one, but there's also (in no particular order): standard library, ease of integration with other code, documentation, community, tooling, etc. That's a lot, so as daxfohl says, picking your battles is key. Not everyone will agree on the relative priorities of these factors, and that's totally fine too. However, I personally think that tooling is (one of the) super important factors. "Fast & snappy tools" is actually one of the explicit design goals for Muon [1] (design principle #12). So releasing a language server so early on in the life of the language underscores that, yes, Muon is a language with a strong tooling focus, and I hope that resonates with people.

[1] https://github.com/nickmqb/muon

nickmqb··on Building a language server for Muon
I didn't look for any resources beyond the LSP spec and VS Code documentation, so I can't offer any recommendations here I'm afraid. That said, looking back I'm pretty happy with the choice of using VS Code as the initial editor to get things up and running. While not perfect (e.g. VS Code will silently ignore your JSON message if you miss a closing brace), the docs are pretty good and it offers a reasonable level of debugging functionality (such as an output window where you can see messages sent to the language server). The Muon VS Code extension [1] is pretty minimal in itself, and it's MIT licensed so feel free fork and use it as a starting point.

[1] https://github.com/nickmqb/vscode-muon

nickmqb··on Building a language server for Muon
Author here. I wrote both the language server and Muon compiler [1] from scratch. The language server reuses the compiler code, for parsing and type checking. I'm not sure which grammar you're referring to? The VS Code extension [2] does contain a grammar, but it's only used for syntax highlighting.

[1] https://github.com/nickmqb/muon/tree/master/compiler [2] https://github.com/nickmqb/vscode-muon

nickmqb··on Lightweight API Design in Swift
> Since each transform needs to perform vastly different image operations, using an enum in this case would’ve forced us to write one massive switch statement to handle each and every one of those operations — which would most likely become somewhat of a nightmare to maintain.

I don't mean to pick on the author, but I've seen this line of reasoning a few times before. It's the same argument that has been used in the past to justify inheritance hierarchies in OOP languages. I used to believe it too. However, I don't think this is actually true. In fact, I'd argue the opposite: switch statements, if used well, are _extremely maintainable_. Even though a switch statement might handle many cases, it does not become more complex [1] by doing so. If we're concerned about the length of the individual cases, we can easily replace each one with a function call. Fundamentally, in the example from the article, we'd like to map a piece of data (the operation with its parameters) to some behavior (actually performing the operation). A switch statement is one of the simplest ways to do that.

[1] https://www.infoq.com/presentations/Simple-Made-Easy/

nickmqb··on Next-Paradigm Programming Languages: What Will They Look Like?
Most languages today come with a runtime. That makes it hard to interoperate with other languages/environments. To avoid this, a new programming language should either have no runtime (or a very minimal one), or be very explicit about which features it expects from its runtime and allow the runtime to be swapped out by something else (we might see something like that in the WASM sphere).

Furthermore, I believe we'll start seeing an increase in tooling around languages, and a focus on reducing iteration latency. Traditionally, REPLs/live editing have been mostly associated with higher level languages, but there's no reason that those things could not be applied to low level languages as well.

Finally, while I think that there will be always be room for both simpler and complex languages, the market for simple languages is somewhat underserved right now, so we'll start seeing more of those in the nearby future.

Disclosure: I'm the author of Muon, which is a new programming language that tries to embody these principles: https://github.com/nickmqb/muon

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Thanks! I don't think we should lose the braces. Braces help avoid mistakes when refactoring/copying/pasting code, and they make the language look more familiar to people coming from C-like languages, which I think are large enough advantages to justify having them.

I'm considering adding some meta-programming/reflection capabilities in some form, if they don't increase the complexity of the language too much. Lisp-style macros would be a possible approach, compiler plugins would be another. The latter approach might be easier to implement though.

A package manager will be out of scope for at least the near future, but long term it would be great to have one!

Re: owned pointers. I'd recommend that people look into more coarse grained memory management strategies first (e.g. arena allocation), and use one of those if possible. However, these strategies definitely have their limitations, which is where alternatives like owned/shared pointers could come in. However, to implement a "proper" owned pointer, e.g. an alternative to std::unique_ptr<T>, we would need destructors (which Muon will never implement) and move semantics (of which there is a chance that Muon _might_ implement it, but probably not anytime soon). With move semantics we can perhaps create a lighter weight owned pointer that is still useful; I'll have to experiment a bit to see how that would work out.

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Done :)

https://github.com/nickmqb/muon/issues/2

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
1. That's true, I didn't mean to imply that transmute is equivalent, there would definitely be benefits to the feature you're suggesting. But it also brings additional complexity of course.

6. Sorry, I totally missed that part of your comment! A language server won't help in that case. At least wrt to return types though, you're always allowed to specify them for clarity. I can imagine building some tooling that automatically infers and adds explicit return type annotations if they are missing. You could run this as a commit hook if you wanted to enforce that as a coding standard.

8. Right, I was referring to the IFDEF DEMO case (assuming it's used to implement straightforward feature flags). I agree that for the other cases that you mentioned we'd need something else. For now, for some situations, you could compile with different files (e.g. gfx_opengl.mu, gfx_directx.mu, etc.), though it's a pretty crude solution, especially if you want to combine conditions (e.g. Linux + OpenGL). Definitely thinking about this.

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Short term, I have some tools planned for automatic generation of foreign function definitions based on .h files (currently you have to do this by hand, which is tedious and also somewhat error prone).

Long term, I agree that a package/dependency manager would be great! There's already so much work to do though, so this will unfortunately be out of scope for the near future.

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Thanks!

1. Right now, you can emulate this with the transmute builtin function. Not yet sure if the additional complexity of this feature would be worth it.

2. Array bounds checks can be avoided by using the unchecked_index builtin. Uninitialized locals are not yet possible, but I think it makes sense to eventually add a construct to allow that, for situations that need every last bit of performance.

3. I've only started to look into LLVM recently, thanks for the heads up.

4. See my comment here: https://news.ycombinator.com/item?id=19599908

5. C# programmers would like to disagree with you ;). Note that the formatting issue is not due to significant whitespace, as you'd have the same issue writing up a Golang snippet.

6. Editor support (specifically, language server) should help a lot here.

7. The string based types are only used for inserting the right cast to make the C compiler happy, so they should not be an obstacle.

8. Compile time evaluation can be used for some cases. Adding a preprocessor comes with its own set of tradeoffs, haven't yet decided what to do there.

9. A lowercase l looks a lot like a 1 in many fonts, hence the uppercase L. Will consider adding an i suffix.

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Sibling comment (granzymes) is correct, also see implementation here: https://github.com/nickmqb/muon/blob/d557c18d2dcd3fc15a7a7a6...

In Muon, you can always add more functions to an existing namespace, so if you wanted to have a function with that behavior you could add it.

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Thanks! See my comment re: whitespace here: https://news.ycombinator.com/item?id=19599908
nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
You're correct that Muon wouldn't catch that bug, but I think one can make a pretty strong case that it's an anti pattern to use unsigned integers for that kind of stuff anyway. It's actually the reason that the Muon standard library defines Array.count and List.count as _signed_ integers. Even though these fields should clearly never be negative, having them be unsigned would invite exactly the kinds of bugs that you demonstrate in your test case.
nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
That's entirely fair game, good luck to us both! ;)
nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
I'm not yet convinced to make it absolutely required, but some kind of warning/linter message would definitely be useful for this.
nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Hey Andrew, I really like your work!

In addition to the Muon compiler I'm still maintaining a C# interpreter which is used for bootstrapping (just so there's always a safe bootstrapping path), so there's some extra work there. The interpreter only supports a subset of the language, which means that I have to selectively avoid a few language features in the compiler. It's not too bad though.

I've been digging into LLVM over the last week, and I'm slowly coming to that conclusion. I'm tempted to add an x86_64 backend, but there's already so much work to do ;). Perhaps WASM would be an interesting target to add. It's new so it doesn't have too much cruft yet, and it may actually work as an intermediate representation (haven't looked at this at all though).

Re: edit. Integer overflow will be defined as 2-s complement wraparound. In your example, Muon would always emit the extra instruction, even in optimized builds. I must admit that I don't have a good intuition yet for how often these cases happen. If it means that Muon is leaving significant performance gains on the table, I'd be willing to consider adding a construct that would allow undefined behavior for very specific sections of a program to enable these optimizations. But by default, there would not be any undefined behavior.

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
I'm not sure that I follow you, just to clarify:

Muon.ssize == Rust.isize == Go.int ('usually', according to https://tour.golang.org/basics/11)

Muon.usize == Rust.usize == Go.uint

Muon.long == Rust.i64 == Go.int64

This is a list of all core types in Muon: https://github.com/nickmqb/muon/blob/master/docs/muon_by_exa...

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
I agree that Rust takes the right approach. Muon follows it, the corresponding types are ssize and usize.
nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
I'm not sure if I understood your question correctly, but lowerCamel vs snake_case is not guaranteed to be different right? E.g. if you have an identifier consisting of a single word.

I'd recommend using UpperCamel for namespaces/types (including structs), and either lowerCamel or snake_case for everything else. I personally like that approach because it makes it possible to distinguish between a regular function call and an instance call, e.g.: SomeNamespace.foo() vs someLocalVar.bar().

That said, the language doesn't enforce any particular naming scheme, so people are free to do what they want. Once the type aliasing feature lands, they can even create alternate names for existing types.

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
The main difference is simplicity. D has a lof of features, like classes, inheritance, exceptions, properties, etc. Muon is a much simpler language that specifically avoids all of those things.
nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
With regards to your last point, that would be fine. The compiler doesn't care about spaces vs tabs after the first non-whitespace character of a line, as that's not relevant to how the code is parsed.
nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Muon always allows you to specify a return type for clarity, though. The key point is that you have the option not to. Not all code is created equal. For library functions that are used by many others it is probably a good idea to add explicit return types, but if you're quickly iterating on a prototype it can be nice to not have to specify them.

I should also add that a language server will really help here. The tooling can just tell you what the return type of a given function is. I can also imagine building some tooling that automatically adds return type annotations if they are missing (which would be quite easy to build). Such a tool could be used as a commit hook to enforce a certain coding standard for teams that would prefer this.

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Yup, the type names for integers (byte, short, int, long, etc.) are borrowed from C#. All primitives in Muon have a well-defined, platform/architecture independent size. Two exceptions: ssize and usize (machine word sized integers), which are mostly used for C interop.

C# programmers should feel right at home, but you're right that there is a very slight learning curve for others.

But, I hear you! I've personally worked a lot with C# which is why I chose the current names, but I realize that there are others that prefer the explicit names (u8, i8, etc.). I'll be adding a type aliasing feature soon, so anyone who wants to define their own alternative type names will be free to do so. At that point it may also make sense to use explicit names as the default.

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Good point, I agree that's a bit of an awkward case. It's something I'm planning to keep an eye on. If this becomes a problem in practice, we can do something about it.
nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
There's quite a bit of overlap with Zig (and maybe even more with V, which recently appeared on HN).

Some differences between Muon and Zig:

- Syntax/ergonomics: Muon has return type inference, Go-like syntax/no semicolons, no "pub fn"s anywhere, reference type notation.

- Memory management philosophy: Muon makes it easy to allocate memory, e.g. via "new" operator and fully customizable thread-local allocators.

- Minimal error handling: Muon provides abandonment (i.e. panic), but no extra error handling features like Zig does.

- Muon is a more minimal language in general: no meta programming (yet, at least), no async, no bit fields.

Zig is a lot more mature though, so I'm trying to catch up as fast as I can ;).

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Thanks for the kind words!

Correct, the initial compiler is built using the C# interpreter; the compiler can then be used to compile the next version of itself. Bugs and backwards incompatible language changes can be a problem though. For that reason, it's a good idea to keep the C# interpreter updated so there's always a safe path to bootstrap from.

Variable redeclarations may be useful in certain scenarios, e.g. redeclaring a variable of type Maybe<T> as T. You're right that serialization may be better implemented as a library using some kind of reflection capability, this needs some more thought. I haven't yet thought about the specifics of build tools, but I very much want to make it easy for people to write tools, and offering the compiler as a library will be part of that.

I started with the initial idea for Muon late 2017/early 2018. Initially, the plan was to create a higher level language (more like C#), but the more I iterated the more I realized that low-level was the way to go. Muon is my first large language project, though I've always been interested in compilers and have written some toy languages in the past.

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Ah, good question. Rust could definitely be in that list as well! It's a more mature language (so that's why I didn't mention it in the list), but conceptually it very much fits.
nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Correct, tagged pointers are just for pointer unions, a value union could be emulated using the transmute builtin function. A more general mechanism for discriminated unions is on the roadmap. It would have been nice to include it for the initial version, but I've been in stealth mode for too long already so really needed to launch ;).

Re: whitespace, see my comment here: https://news.ycombinator.com/item?id=19599908

I'm not worried about single letter generic param names being too restrictive. Having more than 2 or 3 type params usually implies some fairly heavy abstraction, which is not really in the spirit of the language.

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
That's a fair point. It's the reason that I've marked significant whitespace as "experimental" in the documentation. Since the language is in an early stage, I think it's OK to try some slightly more experimental constructs for now. The feature does provide some nice benefits in terms of parsing robustness, which is really noticeable especially when working with live error feedback (i.e. language server, coming soon).

But rest assured, this is very much on my radar! If it turns out to be too much of a pain, I'll remove it (or make it opt in). Fortunately, because of the redundant braces the transition would be seamless: we can just drop the whitespace requirement.

nickmqb··on Show HN: Muon, a low-level programming language inspired by C, C# and Go
Right now, you'd have to use OS-specific threading APIs for that (via foreign function declarations). I'm planning to add threading support to the standard library to make it easier to write cross-platform multi-threaded code. Also on the roadmap are basic concurrency primitives, like channels.

I haven't decided on what I will do in terms of a memory model: likely, I will add acquire/release constructs to the language, which should be enough to implement things like lockfree data structures as libraries.

← PreviousPage 2 of 3Next →