96 comments

[ 1123 ms ] story [ 2598 ms ] thread
Nim is the language I have always thought was a brilliant idea that I never get to use. It's a shame.

Nim is to C/C++ as CoffeeScript is to JavaScript. A highly extensible template language atop a portable language with libraries for practically everything.

So why haven't I hopped on the bandwagon? Outside of C++, C, and Fortran - the only way I have ever learned a new language is through using a REPL. How much of Python's and MATLAB's (and maybe even Julia's) success is due to having a brilliant REPL?

I am not complaining, and I do not have any free time to fix it. But man... if Nim just had a killer REPL that allowed me to slowly learn the language properly while not being blocked from my daily work... it would be just killer!

When I first started using Nim I felt the same way. While I still would love a REPL in Nim, I think you can get pretty close to one by just getting an IDE that can compile snippets of source code for you quickly and easily.
Which IDE?
A text editor[1] I wrote a while ago has a feature that allows you to compile and run any tab by pressing F5, even when that tab is not saved anywhere it will save it to /tmp and compile it for you.

It's a very simple feature that I'm sure can be implemented as a plugin in any IDE/Text editor. The Nim VS Code plugin sort of supports it, but the feature could be improved. (Nowadays, I wouldn't recommend using Aporia for various reasons).

1 - Aporia - https://github.com/nim-lang/Aporia

> Nowadays, I wouldn't recommend using Aporia for various reasons

On https://nim-lang.org/faq.html under "What about editor support?", Aporia is mentioned as the first option. Should it be moved lower in the list?

Anyways I use nim-mode in emacs, and it works great!

I've had success with vscode: I have it setup to build+run on save which has so far netted me very quick turnaround times for trying things out.

Admittedly I'm still doing super basic stuff at the moment.

Same here. It is a good combination and creating a build task for nim is super simple.
(comment deleted)
Emacs.

I have the nim-mode and smart-compile packages installed, and I have bound F9 to compile the nim code in the current buffer, and run it in the emacs-inbuilt eshell.

I have configured so that the point and buffer switching 'does the right thing'.

- If the compilation fails, show the compilation buffer in the other window, and do not execute the binary, and keep the point in the code window.

- If the compilation passes, execute the binary in the other window.

- Now if the binary execution ends with showing the eshell prompt, move the point back to the other window (code window).

- If not, that is, if the eshell prompt does not show up, keep the point in the eshell buffer, because that most likely means that some user input is expected.

---

So my nim learning process goes as: type a code snippet, F9, type more, probably cause error, F9, fix that, F9, etc.

Config: [1] [2]

[1]: https://github.com/kaushalmodi/.emacs.d/blob/master/setup-fi...

[2]: https://github.com/kaushalmodi/.emacs.d/blob/master/setup-fi...

Hey, fancy meeting you here. :) Thanks for sharing that, I'll have to give it a try.
When I can't have a working REPL I use inotify or entr (entrproject.org) to compile and run the program I'm editing when saving.

It's not the same thing but it spares a few key strokes...

I felt the same way. I am still learning it, but not as fast as I could with a REPL. Transpiling to C to get the optimizations in GCC is awesome.
What makes a REPL brilliant instead of average?
That the repl is in your editor, and you can hit ctrl-c ctrl-e to evaluate anything on the fly.
I love the REPL in the Julia programming language. What makes me love it is combination of many small things which makes it practical: (1) remember past written statements (2) completes both functions/types/variables and previously written statements (3) Whenever you write strings you get directory and file name completions. This is amazingly handy when doing some kind of scripting job. (4) The ability to jump into shell mode and help mode by just writing a single character. (5) The integration between the Julia REPL and Unix shell. When in shell mode my Julia variables are accessible as normal shell variables. It is really the combination of all these things which makes it feel very productive to work with.
+1 to the usefulness of a REPL. Anyone know of a good one for the vanilla Java language?
I don't, but I'll point out you can do a lot of exploration in the Clojure repl, and with leiningen it's really easy to set up anything in maven.
I must have a really low I.Q. Or something because maven is all but broken in intellij for me. The Apache quickstart template defaults to jdk 5?!? And the pom file seems like it could get out of control fast.
Sorry, by "in maven" I meant "in a maven repository". Using Maven itself is a nightmare, I know, but if what you need is to download some jars and stick them on the classpath, leiningen is perfect (it even compiles regular Java and has control over JDK versions if you want that)

And it generates the pom files so you don't have to...

I guess I just need to read up on how to actually use maven the right way. Thanks.
I wouldn't use Maven, but there are multiple tools that can use Maven repositories that aren't Maven, and I'd recommend one of those. :)
I was only trying to learn it because a take home coding assignment for an interview asked to use maven for its build process. I found the whole experience (using maven) disheartening while I was able to code up the assignment using maven and my inexperience with it cost me going to the second round. I have only myself to blame though.
That sucks :(. But I can tell you there are plenty of organisations (e.g. Thoughtworks) where Maven is regarded as a bad tool that should be avoided. That doesn't help you much if it's part of a job you want, though. :(
There is an official one coming out in Java 9 soon.
If you don't mind something online, I hear repl.it is pretty good.
If you could do Clojure-style repl-driven development and hot code reloading with the libraries of C++ and the syntax of Python I would be using Nim for everything already
I recently had to learn a language whose REPL I didn't like and initially felt the same way, but then I did the following: I began writing 'unit tests' for each feature of the language I studied, and I had a Makefile to recompile and run my tests whenever I saved. This setup gives you instant feedback just like a REPL with the added convenience of being able to go back to previous examples without having to separately store your history. Depending on the testing library, you also get a detailed explanation of what's wrong. Now, when using the language, I still return to my 'tests' every once in a while for reference.

In the Makefile itself I use entr: http://entrproject.org/

Nim seems like a great language -- certainly people who use it seem to extoll its virtues -- but I see this getting submitted and making it to the front page essentially every month. Unless there's some news about Nim that's pertinent, perhaps we could give it a rest?
The reason that it was submitted this time is because of a new website that we just released. I hope you can agree that this is a valid reason for the submission.
Thanks, I wouldn't have even clicked through if you hadn't written. New website looks nice!
This feels like one of the exceptions where you should be allowed to change the page title. Perhaps if you prefix the title with "Show HN: " it would be ok to not use the default title. Something like "Show HN: Nim revamped its website" might be worth a try.
I like that. I was originally with venantius where it should be something new. That was by looking at the title alone, though. Yours would be much better.
Uber gets submitted. Go. Erlang. Machine learning libraries. Stratups advice. A lot of things get submitted over and over. If people want to give it a rest they won't upvote and it won't show up on the front page. It's pretty simple. But there is interest so it shows up. Don't see it as a big deal, seems to work as designed.
I think GP's point might be that the Nim homepage gets submitted fairly often. For the other examples you mentioned, there's usually more variety in the content being submitted.

However, as noted in another comment, Nim has a new website up hence the post this time.

Whenever I see a new project my first question is always "why?".

From the FAQ:

  Why yet another programming language?

  Nim is one of the very few programmable statically typed languages, and one of the even fewer that produces native binaries that require no runtime or interpreter.


That's it? That doesn't answer the question at all. In fact, it makes it even less clear. All it says it that there are other programming languages that have similar features. Who cares?
Well, if you look at the front page, you'll also see:

  High-performance garbage-collected language
  Compiles to C, C++ or JavaScript
  Produces dependency-free binaries
  Runs on Windows, macOS, Linux, and more
And of course, the "Features" button right under the text leads to https://nim-lang.org/features.html
Nim looks great, but I have to admit after looking through the website it's unclear to me why I would use this over similar alternatives.

In particular, why Nim over Go (or why Go over Nim)?

Is the Python's established presence and resource base (not trivial at all) the only reason one would prefer it over Nim?

Go doesn't support as many platforms as Nim, for one.

And Go doesn't give you access to as many system libraries, for a second. There's cgo, of course, but that has its own can of worms.

I hear the type systems are fairly different as well, which is important to some.

Nim is programmable with macros and templates and very flexible. Go is not at all.
How does it accomplish tracing GC without a runtime?
It doesn't have a tracing GC (or at least, the primary portion isn't tracing). The garbage collector is outlined at https://nim-lang.org/docs/gc.html
It says it has to scan the entire threadlocal heap with mark and sweep. What am I missing?

Anyways I'm sorta being pedantic that it obviously has some sort of runtime. Maybe they meant to say not a runtime like a full VM ala Java?

The whole language compiles to C, C++, or Javascript. It presumably uses whatever runtime the compiled-to language provides.
Well C doesn't ship with the GC described, so it must include some additional runtime beyond the C library.
(comment deleted)
> The GC is only triggered in a memory allocation operation. It is not triggered by some timer and does not run in a background thread.

I think this is what D does as well. This means you have to be mindful of what you're doing and if you want few pauses then you need to perform all your allocations ahead of time or disable it entirely in certain sections.

  programmable statically typed languages
programmable refers to nim's metaprogramming capabilities.
Aw, what could be more appropriate for a site named "Hacker News" than a link to a new programming language?
As someone who does a lot of Python programming, I really love the idea of Nim, and I've started learning it, I just need to find some more time to get back to learning it. Given there's a pandas style + out-of-core support I'm interested in trying to use it for a lot of data extraction + cleaning + prep sort of tasks given how speedy it can be, being built on top of C...
Nim is a great little language - it is enjoyable to work in and small enough to learn easily. It's neat for little utility programs that are "too big for bash" and "too small for java/C". Sometimes I think of it as an alternative to python.
Like the new design, old site looked very dated, which unfortunately matters a lot when attracting mindshare. Kudos to the team that rolled this out, nim looks much more modern and loved at first glance now.
I dig the changes in the landing pages, but I wished the documentation pages got the same treatment. At present, the documentation is not readable easily on mobile browsers.

Are you considering converting the documentation pages to responsive design too?

Also the black and yellow theme looks great on the home page, but that theme loses its continuity on all the other pages. It's as if the home page was designed by a different person, the feature and other landing pages by someone else, and the documentation pages by someone else altogether.

> Are you considering converting the documentation pages to responsive design too?

Unless someone volunteers to do this it likely won't happen any time soon.

As for the continuity. Not all pages can have the same "section" style, the documentation page for example is just composed of a list of links and descriptions. Of course, if you have ideas on how to improve the continuity then I'm all ears :)

> Not all pages can have the same "section" style,

But they can have the same CSS styling (colors, fonts, responsiveness, etc) that ties the whole site together.

A good example that's at the top of my mind is this: https://hugodocs.info

It works great on desktop as well as phone, and a common theme is seen all across the site.

> the documentation page for example is just composed of a list of links and descriptions.

By the documentation page, I meant a page like this: https://nim-lang.org/docs/manual.html

That's a lot of good info but is not accessible in a good way on phone.

For sort of an equivalent reference, see https://hugodocs.info/templates/base/

It has a similar collection of help pages and the design is responsive too.

> > Not all pages can have the same "section" style,

> But they can have the same CSS styling (colors, fonts, responsiveness, etc) that ties the whole site together.

> A good example that's at the top of my mind is this: https://hugodocs.info

> It works great on desktop as well as phone, and a common theme is seen all across the site.

I might be missing something but the website you linked has only two pages and I would consider them to lack continuity even more than the current Nim website. The layout for the "docs" page is completely different to the home page.

> By the documentation page, I meant a page like this: https://nim-lang.org/docs/manual.html

Oh I understand where you're coming from a bit more now. Everything under the `docs/` is sort of separate, it's part of Nim's doc gen generator and thus has a different style associated with it. But I can see why you think it loses continuity.

I've just submitted a tiny PR¹ that makes docs a bit mobile-friendlier. It turns out that the docs template already uses media queries to rebuild the layout for smaller screens, it's just that these queries are not triggered on mobile.

[1] https://github.com/nim-lang/Nim/pull/5737

If anyone was interested, the markup theme is Dracula[1], which subjectively feels like the most readable highlighting theme I've ever used.

[1]: https://draculatheme.com/

The bright color hurts my eyes :(.
I've applied to Terminal.app now. Works like a charm. The only thing is that by cloning the git repo using "git clone https://github.com/dracula/terminal.app.git" it gets put into a folder called terminal.app, which is not readable when trying to import it from Terminal since it thinks it's an app. The solution is to move the Dracula.terminal file to another location before importing.
Easy enough to solve, just change the destination directory:

    git clone https://github.com/dracula/terminal.app.git terminal-theme
i didn't like it in emacs but in iTerm it is really great. thank you :)
For some reason it reminds me of the various 8 bit computers colour schemes.
When trying out a new language, one of the first things I look for is a Getting Started/Quick Start guide that'll get me up and running with executing some code on my computer.

Is there something like that on the Nim website? There's a code example on the home page but after doing a `brew install nim` I don't actually know how to run it. In the Documentation section there are guides about the standard library and so on but I can't find a 'quick start' that'll get my hands just a little dirty without feeling overwhelmed with too much information.

(comment deleted)
One thing I have always hated about languages that tout easy C interop is the fact that you have to declare the C function first. A lot of C libraries e.g. Guile uses all sorts of Makefile hacks that makes it impossible, not to mention extremely time consuming to write a function declaration. Things would be so much easier if languages can implement something like Julia's ccall or a similar mechanism to allow direct calling of C libraries without any for of headers or wrapping.
Aren't you still writing the equivalent of a function declaration, but at the call site? What makes Julia's approach easier to use with Guile?
Huge update on the website. Dope!
Very nice dark main page, but the others have a different brighter (ouch!) theme, and the Examples one renders badly here (small netbook, Palemoon 27.2.1 on Debian amd64) due to high pitched fonts. Examples code blocks also do not use the same font size so I believe it's just a matter of fixing the theme. Other pages look nice despite the small screen size I'm using right now.
Happy to see that nim is evolving. Any big player out there who uses nim for an important project?
I can see some interesting applications once we can target WASM, libraries that are client/server agnostic with clients that can join in the cloud workload comes to mind.
We already can target WASM[1] :). Nim's JS backend is already very useful though, you can see a game I've created using it in the features page.

1 - https://forum.nim-lang.org/t/2838

i'd love to see something that compiles into two parts, one for the browser and one for the server from a single source and also maybe distributes trusted computations among the user base.
I am stuck working on a C++ code base using Qt. Could I in theory use Nim to accelerate my development, or would it produce incomprehensible or ugly C++ code?

Alternatively are there other alternatives to C++ for people who have to submit C++ code into the repository?

I use other languages than C++ on a regular basis and I find it annoying to tedious the language is. So much boilerplate and repetitions.

Some years ago I had the idea to create something similar to CoffeeScript for C++: https://bixense.com/coffeepp/ Never got through to finish it though :/
Looks pretty cool, I'd love to have something like that. Preferably something which you could tweak to output C++ code matching company code style guidelines.
I am not sure how incomprehensible it is, but I can say that the c2nim wrapper tool is pretty darn good. Andreas (author of Nim) quickly wrapped all of Urho3d in Nim almost fully automated. So IMHO Nim is a great companion to C++ libraries.
Perhaps I misunderstand, but you are speaking of going from C++ to Nim, while I have to be able to go from Nim to C++ as co-workers are not going to want to look at Nim code. Nim would have to be a personal tool for me to write C++ faster.
(comment deleted)
(comment deleted)