7 ms·
Show HN: A new programming language inspired by Go, no LLVM
- hualaka 1y agoI am the author of the nature programming language. You can find code examples and a playground to try it out on the official website at https://nature-lang.org https://nature-lang.org I would appreciate your feedback.
- gonzus 1y agoThere are some misspellings in the README, such as "natrue". Just FYI.
- hualaka 1y agothanks, I'll fix it
- je42 1y agoLooking at the co routine example. Does the function type implicitly change when using co.sleep in the function body?
- Simpliplant 1y agoAny chance you missed “go” that turned the function into the future?
- WhereIsTheTruth 1y agoDo you have plans to support WebAssembly target?
- hualaka 1y agoPlan to add wasm backend
- nextn 1y agoCongratulations on finishing this. If you were to do this again, how would you organize the source code differently?
- hualaka 1y agoI am more in favor of flat code organization, but I probably won't use C to implement a compiler again, as it involved a lot of unnecessary work. Zig or Rust would be better choices.
- gonzus 1y agoNice work. Some questions / observations: Can you add methods to any type? There is an example of adding a method to a builtin type (string) -- can you add also add a method to a union type? Any plans to add some sort of enum type? If yes, will it be possible to add methods to enums? How do you support (or intend to support) Unicode? It says "Strings use ASCII encoding" -- why not UTF8? The example with a timeout channel does not show how / when the timeout will be triggered. Is this a special kind of channel? It says "Packages will be synchronized to the $HOME/.nature/package directory" -- will this respect the XDG standard directory structure, which defaults to $HOME/{.cache,.local,.config}?
- hualaka 1y ago1. nature can add methods to built-in types, example fn int.to_string() { } I haven't considered whether union types can add methods, so I tested it, and it seems to be possible, but this may cause some unexpected behavior, so maybe I should disable this possibility for now. type test_t = int|null fn test_t.hello() { println('hello world') } 2. Enum support is planned. I plan to use type declarations. Why hasn't enum been added yet? Nature has adopted a conservative syntax design, and I hope to hear more opinions and avoid affecting existing functionality as much as possible when adding syntax features. type weekly = enum {} So methods can be added to enums. fn weekly.found() { } 3. UTF-8 should be solvable via a library. I haven't thought much about UTF-8 yet, but if it can enhance nature's usability, I'll implement it as soon as possible. Usability is a key focus for nature moving forward. 4. Select{} timeout handling does require a special timer channel, which will be addressed in the standard library. Currently, it can only be handled via ch.try_recv() and ch.try_send(), which do not block the channel. 5. Actually, this is the first time I've heard of the XDG standard. I will study and understand the specification. --- I am not an experienced programming language designer, so thank you for your questions. I will carefully consider them.
- gautamcgoel 1y agoCool work! Just out of curiosity, what made you pick the name nature?
- hualaka 1y ago“Tao follows nature” (道法自然) is a phrase from classical Chinese philosophy, and it is the design philosophy behind the nature programming language. It can be understood as being natural and intuitive. I hope that nature can build upon Go's ‘less is more’ philosophy and achieve ‘Tao follows nature.’ Unfortunately, nature is not SEO-friendly, so the name has received a lot of criticism. Therefore, I am considering changing it to a name that starts with ”na”
- gautamcgoel 1y ago"Tao" might be more search-engine friendly than "nature".
- fithisux 1y agoDo you use Go Assembly for code generation?
- arthurcolle 1y agothe name of the programming language should be in the title, I'm sorry but come on
- hualaka 1y agoYou're right, but nature doesn't seem to be a good name, it gets a lot of criticism because its not search engine friendly. Maybe I should change the name before nature becomes popular.
- mrbluecoat 1y agoGreat job! An impressive set of functionality for an initial release. The syntax is also quite intuitive in general but these were a bit odd to me: (int,bool,bool) t = (1, true, false) // v: Define a tuple. Access elements using t[0], t[1], t[2] string? s = null
- RadiozRadioz 1y agoCan you explain what is odd about this? I think it seems perfectly logical. The tuple type definition _looks_ like how the tuple will look. The nullable indicator is a symbol with a delightfully appropriate semantic meaning.
- hualaka 1y ago? Commonly used for nullable types. The tup is an interesting question. I often think about tup(int, bool, string) vs (int, bool, string). I convince myself that there might be a better choice. `var t = (1 as i8, true, false)` Use automatic inference to replace active type declarations. t.0 vs t[0] is equally difficult to choose, but t[0] is the more commonly used syntax. Using t[n] consistently across map/vec/set/tup might be the more correct decision.
- nlitened 1y agoImpressive work, but how is it better/different from Go or other programming languages? What would be one’s motivation to switch to this language?
- thayne 1y agoIt looks like it addresses some of go, including: - a better type system, that includes union types, and makes types non-nullable by default - pattern matching - designed with generics from the beginning - try/catch error handling. This is controversial, and some people like checking every return value for errors, but it is a common complaint about go - it looks like it is meant to have better c interop than go
- ksec 1y agoFeels to me like it is Go++. Or may be Go+ / BetterGo. And in a very good sense.
- hualaka 1y agovlang is a Golang-like programming language. I will use vlang as an example, v has the same syntax as golang and is derived from it. But otherwise, v is moving closer to rust, with immutability, bounds checking, and so on. Here's a discussion of vlang's implementation of coroutine https://github.com/vlang/v/discussions/11582 https://github.com/vlang/v/discussions/11582 Until recently, vlang has not supported coroutines very well The syntax of nature is different from golang. But everything else is the same as golang, including goroutine, GC, channel, cross-compilation and deployment, and even free programming ideas, less is more, and so on. I think these features are the best thing about golang, even in front of all programming languages. That's why I'm trying to see if I can create a better golang. In the early stages of availability, I would not advise others to switch to nature, as this would be irresponsible. When nature is sufficiently advanced, the situation will be different.
- mountainriver 1y agoThose design decisions by Go are what caused the need to trampoline to C right? How does nature fix that? Does it work well with GPUs?
- pjmlp 1y agoLove the effort, and brownie points for proper imports instead of directly referring to SCM urls.
- avestura 1y agoMaybe I have a too strict definition of systems programming languages, but I would never call a GC language a systems programming language. Who would use an operating system that suddenly stops the entire world because some random language's runtime wants to collect its memory garbage? That said, well done for making this.
- WhereIsTheTruth 1y agoFrom the website: "Nature is... A general-purpose open-source programming language and compiler designed to provide developers with an elegant and concise development experience, enabling them to build secure and reliable cross-platform software simply and efficiently."
- avestura 1y agoThat's true. However the website also promotes it as a systems programming language here and there. For example in the same homepage it says "Perfect for Systems Programming: Operating systems and IoT" and some other places like here: https://nature-lang.org/docs/get-started https://nature-lang.org/docs/get-started
- hualaka 1y agoI use Go for IoT devices in my work, such as routers and TV boxes, which run on RISC-V/MIPS/ARM32/ARM64, etc. I appreciate its portability; even on devices with only 512 MB of memory, I don't have to worry about memory overflow issues. I believe nature is equally suitable.
- js8 1y agoSomewhat agree, but it depends. I agree that core of the operating system (kernel) should be responsive, but there are many tasks in the operating system that don't require immediate response and can be run in batch. Usually these are higher-level decisions, such as any housekeeping tasks like file backup and indexing, workload reprioritization and optimization, system update and reconfiguration, and the like.
- WhereIsTheTruth 1y agoNice, the kind of project everyone should support, a language with a fully working backend for both X86/ARM Clean source code too, impressive project
- lambertsimnel 1y agoPrevious discussion: https://news.ycombinator.com/item?id=37869445 https://news.ycombinator.com/item?id=37869445
- hualaka 1y agoThank you for finding the discussion from two years ago. The usable version took me another two years to complete. Focusing on implementation caused me to neglect collaboration and promotion, and I fell into many misconceptions.
- intalentive 1y agoWhy should I care whether LLVM is used? What’s the advantage?
- szszrk 1y ago[flagged]
- theLiminator 1y agoHe said LLVM, not LLM. Maybe it's the same reason as Go, to be able to guarantee that codegen runs really fast.
- eapriv 1y agoWhat does it have to do with using LLVM?
- kissiel 1y agoLLVM != LLM https://en.wikipedia.org/wiki/LLVM https://en.wikipedia.org/wiki/LLVM
- szszrk 1y agoMisread. Acronym fever.
- IshKebab 1y agoLLVM is very big, takes ages to compile and compiles code relatively slowly. Also because it was designed to compile C there are occasionally C-isms that make it suboptimal for other languages with different properties. (Although a hobby project is never going to beat its performance even accounting for that.)
- zer0zzz 1y agoThat’s what mlir is for
- mbel 1y ago
- CyMonk 1y agoWhy does it have a Millennium Falcon as a logo? ;)
- hualaka 1y agoThis is the Natural Selection interstellar spacecraft from the Three-Body Problem novel. In fact, the disc-shaped part is the head. I tried to draw this logo myself, but my drawing turned out rather ugly. The lines of the Millennium Falcon closely match my imagination of the Natural Selection spacecraft's appearance, so I borrowed its lines. However, this is not permanent. In fact, the name “Nature” may be modified because it is not SEO-friendly.
- thayne 1y agoI like a lot of things about this, and it addresses some of my complaints about go. But I'm confused on why strings use ascii encoding instead of utf-8. What if you need non-ascii characters?
- ivanjermakov 1y agoZig solved this by not having a string type at all and not shipping full Unicode support in std: https://github.com/ziglang/zig/issues/234#issuecomment-276302555 https://github.com/ziglang/zig/issues/234#issuecomment-27630....
- MangoToupe 1y agoThat attitude as described feels like chucking a large portion of the benefit you get from leaving C out the window. But... > But at that point, why does it need to be part of the language? Would not a standard library module suffice? This indicates zig is desired to ship with unicode support—just not part of the core language runtime. Now this I can support—unicode doesn't require core runtime support. Most programs don't have a need for unicode text normalization, for instance, so why would you need this without linking in a standard library? But the idea of not shipping unicode in your standard library rightfully died decades ago. Notably, this doesn't imply: * source code being ascii * string literals being ascii * unicode string processing not being immediately available in the standard environment So I'm not sure which behavior is being described here, but I certainly consider utf8 support to be table-stakes for language design in 2025. Without this a language is a toy. I'm not going back to using ICU and will fight anyone who encourages me to.
- hualaka 1y agoI will consider the issue.
- alain_gilbert 1y agoI haven't seen anything about public/private properties/functions. So everything is public ?
- hualaka 1y agoYes, public, I won't add pub syntax. But maybe there will be a label provided for the editor to recognize, but this won't be the main route. #local fn test() { }
- hwj 1y agoI'm surprised ".n" was not already a used file extension: https://en.wikipedia.org/wiki/List_of_filename_extensions_(M%E2%80%93R) https://en.wikipedia.org/wiki/List_of_filename_extensions_(M...
- xigoi 1y agoConsidering that it’s supposed to be a “better Go”, there are some things it does worse than Go, such as type-before-name or using less-than and greater-than signs for type parameters.
- hualaka 1y agoI really enjoy thinking about such issues. I actually spend a lot of time considering whether to use type prefixes or suffixes, [] or <>, and ultimately settled on “<>”. In my opinion, the change from `<>` to `[]` is a minor adjustment. `<>` is already widely adopted, and I don't want to break with convention for such a small benefit. The position of the type is similarly considered. Postfixing the type has some advantages over prefixing it, but those advantages aren't sufficient for me to break with convention.
- alexpadula 1y agoReally cool to see! Keep it up :) I wish you the best on Nature
- potato-peeler 1y ago> No dependency on llvm and VM, compiles directly to target platform machine code and supports cross-compilation Hey, can you comment on how this was achieved?
- hualaka 1y agoIn my view, a compiler is a text transformation tool that converts high-level descriptive text languages into the format required by the target machine. Target machines typically have two specifications: operating system specifications and CPU specifications. As long as the final generated binary encoding satisfies both, it can run on the target machine. For example, Linux systems have ELF program loading specifications, while ARM64 manufacturers have CPU instruction specifications. As long as the CPU can recognize the binary encoding, it can command the CPU to perform the required computations. In concrete implementation, it is usually necessary to convert high-level text languages into an Abstract Syntax Tree (AST), perform necessary detection and optimization based on the AST, and then convert it again into a lower-level Linear Intermediate Representation (LIR). After performing necessary detection and optimization on the LIR, the LIR can be converted into readable assembly instructions required by the target CPU. Further implementing an assembly instruction conversion tool converts the readable assembly instructions into binary encoding that the CPU can recognize. Next, this set of binary encodings is wrapped into an executable file according to the operating system's requirements, ultimately obtaining a file that can run on the target device. Since a compiler is a text transformation tool, it can run this tool on any device - this is the essence of cross-compilation.
- potato-peeler 1y agoI was not expecting this answer. Go uses a flavour of plan9 asm and then do transformations for each platform to achieve cross compilation. I wanted to know how this Lang achieved it, is it using qbe or a custom backend?
- hualaka 1y agocustom backend
- codeptualize 1y agoLove this, definitely rooting for this to get big! I think the goal is great. My dream language is something "in between Go and Rust", Go but with more expressive types, Rust-light, something along those lines. This seems like it is hitting that sweet spot. Imo Go gets a lot right when it comes to productivity, but the type system always annoys me a bit. I understand the choice for simplicity, but my preference is different. Rust is quite enjoyable, especially when it comes to the type system. But, kinda the opposite of go, it's a lot, maybe too much for me, and I frequently don't know what I'm doing haha. I also don't really need Rust level performance, most things I do will run totally fine with GC. So Go with some extra types, same easy concurrency, compilation and portability sounds like a winner to me.
- fithisux 1y agoWhat I would personally like to see is a low level language between C and assembly. There is Golang assembly, but it depends on a GC.