TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Muon, a low-level programming language inspired by C, C# and Go

175 pointsby nickmqbabout 6 years ago

19 comments

tagrunabout 6 years ago
I have a criticism regarding how basic data types are named: <a href="https:&#x2F;&#x2F;github.com&#x2F;nickmqb&#x2F;muon&#x2F;blob&#x2F;master&#x2F;docs&#x2F;muon_by_example.md#core-types" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;nickmqb&#x2F;muon&#x2F;blob&#x2F;master&#x2F;docs&#x2F;muon_by_exa...</a><p>Type names like long, short, char (and the oh-so-dear long long) are ancient cruft which shouldn&#x27;t be used in a new programming language. They are confusing (as in, the answer to question: how many bits are there in your int, long, short depends on both arch and compiler) and since 70s we discovered it the hard way that they&#x27;re non-extensible (multiple times, actually!). Similar for the fate of char in the post-ASCII world. C still keeps them for backward compatibility, but types like uint32_t defined in stdint.h is becoming common practice for new code.<p>The choices are also not compatible with C or Go, adding further to the confusion (Muon&#x27;s int is 32-bit and long is 64-bit on all archs!), so even for C&#x2F;C++ and Go programmers, the nostalgia turns into a pitfall. Having no familiarity with C# (not much of a Windows user since late-90s, and C# virtually doesn&#x27;t exist for Linux&#x2F;macOS people which Muon claims to be targeting), I looked it up, and it seems it&#x27;s based on C#&#x27;s distorted and incompatible adoption of C89&#x27;s data types.<p>Go applies the same custom to float&#x2F;double as float32&#x2F;float64 which makes it uniform. Go also defines int to be the size of the native integer register size on the target arch (which I like because this is what int supposed to mean originally, this was the common understanding when porting between C and assembly, although some may disagree after ~50 years of weird adaptations of it) which unifies uint and size_t, rendering size_t obsolete.<p>Ironically, Muon makes use of explicit number-of-bits suffix for one data type: bool32 (and there&#x27;s no bool16 or bool64). I don&#x27;t even know why one might have it as a basic language type.<p>I really hope he adopts a naming convention that is similar to C99&#x27;s stdint.h or Go (which the author claims to be inspired by), or their shorter cousins u8, u16, ... used in Linux source code.
评论 #19601422 未加载
评论 #19601736 未加载
评论 #19600588 未加载
评论 #19600822 未加载
评论 #19600998 未加载
austincheneyabout 6 years ago
This language looks incredible. I like the code examples and was really sold when I read its point number 2 about functions and no inheritance.<p>The only frustration I immediately notice is strong reliance on white space for syntax.<p>* This makes life harder in a modern world of various operating systems and high distribution. Some means of distribution mutilate white space. XML language design spent enormous effort considering for this.<p>* Line termination differs by OS. Now it’s largely just posix vs Windows, but there used to be even more variance and there could be more in the future.<p>* Parsing around white space is severely misunderstood by people who do not write parsers regularly. Just this weekend I encountered unique white space syntax added into React’s JSX to compensate for this that doesn’t exist anywhere else in either JS or XML.<p>* As somebody who maintains a popular code beautifier I have had to learn the hard way that people really enjoy flexibility around white space. They deliberately use my software instead of, or in addition to, the popular software coming out of Facebook because of the flexibility my software allows. The bottom line for many developers is that code beautification can be fully automated and is better performeded by computers and should never be a factor when authoring code.<p>* code beautification is also highly subjective. Everybody has different opinions on beauty and easy to read. Providing the means to allow developers to exercise those opinions dynamically and automatically makes people happy. So long as it’s just vanity the code stills executed and reads the same way.
评论 #19602927 未加载
评论 #19602993 未加载
评论 #19603932 未加载
jphabout 6 years ago
I like the emphasis on simplicity. I like the functions, the namespaces, the customizability of allocators, and more. Much respect to the author for creating Muon and sharing it.<p>What sets Muon apart from all other languages that I&#x27;ve personally tried is that Muon seems to have chosen a unique indentation approach. First, there is a double-syntax for blocks, because Muon requires block indents with significant whitespace (akin to Python) and simultaneously requires block open&#x2F;close braces (akin to C). Second there is a free choice of tabs or spaces (but not both) and simultaneously a meta-markup line that a developer can put at the top of a file that enables mixing tabs and spaces.<p>IMHO these kind of whitespace choices seem small at first, yet eventually make open source development more difficult when teams make different choices, and when teaching examples make different choices. I&#x27;m a big proponent of `rustfmt`, `gofmt`, and similar tooling that makes it easy to align diverse teams from many groups.
评论 #19599908 未加载
saagarjhaabout 6 years ago
More interesting link, I think: <a href="https:&#x2F;&#x2F;github.com&#x2F;nickmqb&#x2F;muon&#x2F;blob&#x2F;master&#x2F;docs&#x2F;muon_by_example.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;nickmqb&#x2F;muon&#x2F;blob&#x2F;master&#x2F;docs&#x2F;muon_by_exa...</a><p>Uniform call syntax and constructor functions go a long way in making usage more pleasant. I’m curious about “tagged pointers”, though: is the only way to make a “union” by taking the reference of a bunch of things? Seems somewhat inconvenient. Finally, there seem to be a couple of opinionated requirements in the language, namely significant whitespace (made “worse” because you’re already using brackets to define scope) and restricting generic parameters to single-letter names that seem like they’re a bit <i>too</i> restrictive.
评论 #19600056 未加载
ahaferburgabout 6 years ago
Very cool project! Thank you for taking the time to prepare this reveal so well. Examples and roadmap and all. Good job!<p>It looks like you started with writing an interpreter in C#, then wrote the compiler in the language itself. Which is a cool concept, I must say. I can&#x27;t fully wrap my head around the practicalities, though. Do you compile the compiler with an older version of itself during development? Do you plan to update the interpreter as the language evolves?<p><i>Builtin serialization of any type</i> Couldn&#x27;t this be implemented with compile time evaluation in the standard library?<p><i>Variable redeclarations</i> Why?<p>What about a build tool? Is an interface with the compiler going to be part of the compile time evaluation?<p>How long have you been working on this? Is this your first language project?
评论 #19600314 未加载
评论 #19600251 未加载
travisgriggsabout 6 years ago
Zig has had a bit of HN traffic in the past year. Any thoughts on how these two compare with each other?
评论 #19600444 未加载
nymanjonabout 6 years ago
One thing that is missing from Go is computation expressions (in C# 7.0 async&#x2F;await was generalized to a computation expression). Computation expressions are extremely powerful feature in F# which introduced the idea of async&#x2F;await. If it is generalized then you can properly handle code failures better.<p>In the Go community they have found returning the result&#x2F;error tuple is tedious enough that people don&#x27;t properly handle their errors. I would argue this is because of the lack of generics and computation expressions.<p>In F# I can do something like this:<p><pre><code> let result : Task&lt;Result&lt;MyObject, Error&gt; = asyncResult { let! validatedObject = validateObject object let! dbObject = GetSomethingFromTheDatabase object return dbObject } doSideAffectLastCodeAndHandleAnyErrors result </code></pre> This lets you create little DSLs and code that you can handle errors in a central location and in your main code just get the work done without thinking about it. Makes for a really great workflow.<p>See also <a href="https:&#x2F;&#x2F;github.com&#x2F;louthy&#x2F;language-ext" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;louthy&#x2F;language-ext</a>
gizmoabout 6 years ago
This looks promising. We haven&#x27;t seen a lot of new languages lately that could turn into viable alternatives to C. Muon binaries don&#x27;t seem to have a runtime or other dependencies so it looks like a module written in Muon can be statically linked into an existing C&#x2F;C++ project. Pretty cool.
评论 #19599795 未加载
评论 #19599750 未加载
indentitabout 6 years ago
I guess a killer feature would be an integrated &quot;package&quot; manager like .NET&#x27;s NuGet. Being able to easily &quot;import&quot; C dependencies that way, along with other projects written in Muon could make life much easier. I&#x27;m thinking like Rust&#x27;s Cargo, but without the nonsense of having to build all the dependencies oneself which takes time and storage space - just using a pre-built versioned release would make a massive difference to workflows and reduce friction. Is anything like this in the works&#x2F;on the roadmap? (I didn&#x27;t see it but maybe I just missed it, while browsing on mobile ;))
评论 #19604124 未加载
voldacarabout 6 years ago
I haven&#x27;t looked too deep, but this language seems to have a lot of features and goals in common with Zig, are the two projects in any way related?<p>edit: just saw your relevant comment :)
indentitabout 6 years ago
This looks to have been well thought out. I generally shy away from C&#x2F;C++, I prefer the GC approach of C#. (I have also coded a little Rust but find it challenging.) But looking at the docs and examples, I&#x27;m very tempted to try Muon! I like the lack of undefined behavior very much, even if it only transpiles to C atm; I look forward to the LLVM target.
dev_zeroabout 6 years ago
This is a really interesting project and I like where you&#x27;re taking it. I&#x27;ve played with Nim for a number of years, and I really like the no-runtime aspect of Muon and the flexibility and simplicity that you&#x27;ve created with it. Unlike many others in this thread, I like the whitespace decisions you&#x27;ve made, though I go in the opposite direction - have you thought about making braces optional?<p>Your roadmap looks great as well. Have you considered any of the following?:<p>- Lisp-style Macros (e.g. Macros as functions that transform an AST object) -- this would also answer many of the preprocessor questions you had, especially if you can specify compile-time behavior (like in zig)<p>- Github-based decentralized package management system<p>- Owned pointers memory management options
评论 #19610558 未加载
lostmsuabout 6 years ago
What about threading and a corresponding memory model?
评论 #19599828 未加载
babyabout 6 years ago
I feel like there is a lot of lessons that one MUST take into account if they want to create a new PL. Not getting inspiration from Rust or F# should be a mistake.<p>Sadly Rust also didn&#x27;t take inspiration in Go&#x27;s std library.
评论 #19600834 未加载
F-0Xabout 6 years ago
I need to get this gripe off my chest. I want types on the left, and not optional.<p>I read the main function first. I saw that call to countOccurances, without an argument. I was confused how it was going to count occurances if it didn&#x27;t know what it was looking for. Then I noticed the implementation of this method above.<p>Had there have been a type of Map&lt;string, int&gt;, I&#x27;d have reasoned what it does easily.<p>I hate type inference, it does not help.
评论 #19600631 未加载
kovrikabout 6 years ago
In the &#x27;Glimpse of Muon&#x27; example, how does the Map::getOrDefault() function work? Shouldn&#x27;t it accept 2 args: a key and a default value (if the value associated with the given key is not found)?
评论 #19603966 未加载
评论 #19602852 未加载
iamcreasyabout 6 years ago
&gt; &quot;Data oriented. Just functions, structs and enums. NO: classes, inheritance, properties, etc.&quot;<p>Does it mean C is a data orientated language?
评论 #19603620 未加载
Crinusabout 6 years ago
I like it in general, but i have a few comments:<p>1. &quot;Data oriented. Just functions, structs and enums. NO: classes, inheritance, properties, etc.&quot;<p>I think you should allow for struct &quot;inheritance&quot;, at least in an Oberon-style manner. There are many cases where having a common &quot;head&quot; between structs is useful (e.g. widgets for a GUI toolkit, object types for a scripting language, etc).<p>2. &quot;Memory is initialized to zero. Array bounds are checked (can be turned off where needed).&quot;<p>It is not clear from this, but how can both be disabled in a case-by-case basis? For example in D local variables are initialized to zero by default but you can do something like (IIRC): Foo foo = ? (or = nil, i do not remember) which the compiler interprets as &quot;do not zero-initialize this). Similarly can i do something like array[foo] (bound checked) and array{foo} (non-bounds checked, imaginary syntax)?<p>3. &quot;An LLVM backend is in the works which will avoid any undefined behavior.&quot;<p>LLVM inherits most of C&#x27;s undefined behavior, so it will not solve your problem there - you&#x27;ll need to explicitly generate code that works around undefined behavior. This is a problem that the Free Pascal developers also faced (the language has much less undefined behavior than what LLVM assumes).<p>4. I am not fan of the language enforcing code style (e.g. &quot;The name of a type parameter must be a single uppercase character.&quot; and significant whitespace)<p>5. Nitpick, but &quot;List&lt;T&gt; struct #RefType { dataPtr pointer count int capacity int }&quot; is a dynamic array, not a list (also, an example of why significant whitespace isn&#x27;t a great idea :-P)<p>6. &quot;Type inference for function return values and locals&quot;<p>I actually prefer to explicitly see the data types passed around, it helps better understand what exactly the code is doing (not just the algorithms, but also the data types which are important) without needing to have too much &quot;implied code&quot; in my mind (i.e. with explicit data types i don&#x27;t need to &quot;know&quot; that &quot;foo&quot; returns &quot;bar&quot; when looking at its use in a diff (or any other non-syntax highlighted, non-code aware code viewing context), i actually know it because i see it in the code).<p>(FWIW for this reason i also dislike auto in C++ and similar constructs in other languages - you save a bit of short term typing now, for a lot of long term headache later)<p>7. &quot;fgets(s pointer #As(&quot;char <i>&quot;), size int, stream pointer #As(&quot;FILE </i>&quot;)) pointer #Foreign(&quot;fgets&quot;)&quot;<p>I think you need to make your type system good enough to natively express C types, otherwise the string-based pseudotypes will bite you hard later when you want to move away from using C as a backend.<p>8. I do not see any mention of a preprocessor, how is code supposed to IFDEF stuff (like, e.g. a commercial program that needs to have something like IFDEF DEMO, or a source file that needs to behave slightly differently if linked as a static library or dynamic library, or the use of two APIs like e.g. IFDEF LINUX, IFDEF WIN32, IFDEF OPENGL, IFDEF VULKAN, etc) or work around language limitations (like the non-availability of inherited structs mentioned above that C programs often work around by using a macro that defines common elements for structs)?<p>9. &quot;Number literal suffixes&quot;<p>I&#x27;m not fan of the underscore in the suffixes and also i&#x27;d avoid the uppercase L and introduce an i (that is &#x27;nop&#x27; but could be useful for automatically generated code via scripts and&#x2F;or macros).<p>There are other minor nitpicks, but i&#x27;d need to actually check it in practice to write more :-P.
评论 #19604056 未加载
cozzydabout 6 years ago
The last thing I&#x27;d want is a heavier and less stable Electron. Do pointers decay automatically in Muon after 2.2 us?<p>On a more serious note, as a particle physicist, I hope this trend of naming software after fundamental particles ends soon...
评论 #19599701 未加载
评论 #19599885 未加载