
Nim: Scripting Ease in a Compiled Language - charlieflowers
https://www.junglecoder.com/blog/nim-early-report
======
nphard85
One thing I find annoying about Nim is the case insensitivity [0]. There was
no strong reason for this "feature" and literally no mainstream language does
it. Moreover it makes code search a pain.

[0] [https://nim-lang.org/docs/manual.html#lexical-analysis-
ident...](https://nim-lang.org/docs/manual.html#lexical-analysis-identifier-
equality)

~~~
ac29
As an admittedly amateur programmer, I think the reasoning is solid. Its
difficult to read and understand code that does things like myvalue = myValue.
I think they made the right tradeoff, in that value != Value (the case of the
first letter _is_ used), so if you really need to have to values with the same
name, you can still do it.

As an aside, is there some reason that using the same identifier with
different cases is desirable?

~~~
bobbylarrybobby
Nothing unusual in doing e.g. `array = Array()` (although you should probably
give your variables better names than that), which would break in Nim.

~~~
ac29
Right, and that's the point, aside from the fact those 2 are actually
different in nim. I see what you are doing there, but that would have been
very confusing when I started programming.

Question is, should the language enforce you giving your variables a better
name, or should convention? I think there are reasonable arguments for both.

~~~
alpaca128
But does a language with Python-like syntax really have to try to be so
"beginner-friendly" that it enables inconsistent casing?

The language itself can't enforce better variable names, at least not this way
- Nim doesn't stop me from using "abcd" or "a0, a1, ... a100" as variable
names even though it's usually a very bad idea.

No, I think a language should help keeping the code consistent in the long
term - and having this strange case insensitivity doesn't help there in my
opinion.

~~~
nimmer
> I think a language should help keeping the code consistent in the long term
> - and having this strange case insensitivity doesn't help there in my
> opinion.

Not at all. Style insensitivity encourages good variable naming and there are
both formatters and also the simple text completion in editors to guarantee
consistency.

------
Jefro118
Shameless plug - I interviewed Andreas, the creator of Nim, about his
philosophy and design choices here: [https://sourcesort.com/interview/andreas-
rumpf-on-creating-a...](https://sourcesort.com/interview/andreas-rumpf-on-
creating-and-growing-nim)

Might be an interesting read for people who are thinking about using Nim and
wondering how it compares to the C family, Python, Go, etc.

~~~
jstimpfle
> The C-family of languages has quirky syntax, grossly unsafe semantics and
> slow compilers but is overall quite flexible to use. This is mostly thanks
> to its meta-programming features like the preprocessor and, in C++'s case,
> to templates.

> The Pascal family of languages has an unpleasant, overly verbose syntax but
> fast compilers. It also has stronger type systems and extensive runtime
> checks make it far safer to use. However, it lacks most of the
> metaprogramming capabilities that I wanted to see in a language.

While Nim somehow is not appealing to me, this absolutely nails it.

------
jxy
You know the language has potential when the top comments on HN are all about
syntax.

To generate more talking points, somebody ought to write an inverse of
dumpLisp: [https://nim-
lang.org/docs/macros.html#dumpLisp.m%2Cuntyped](https://nim-
lang.org/docs/macros.html#dumpLisp.m%2Cuntyped)

~~~
jimws
I am confused if you this is an honest opinion or if you are saying with a
touch of sarcasm. If it is the latter, a winking smiley or "</sarcasm>" or
"/s" would have been nice to avoid triggering Poe's Law.

In my honest opinion, discussion on syntax is a distraction. One of the
reasons I like Lisp/Clojure is that there is very little syntax. I can just
focus on my problem and writing good code.

~~~
PMunch
I think he meant that if the worst thing people can say about a language is
that it has slightly quirky syntax it must've done a lot of things right.

------
errantspark
I've been considering getting into Nim for a while now as something more
lightweight/terse to write thin CLI utilities in. I'm glad to hear that it's
performing well for this usecase. It's a very attractive alternative to Rust
for it's simplicity and terseness.

I still haven't gotten around to picking it up though, these days I just use
QuickJS for anything that needs to be reasonably portable and thin.

Maybe next side project...

~~~
Phillips126
I would highly recommend it. Setup is incredibly easy (VSCode has great
plugins for it), the language is simple to read/write and compiled Nim is very
fast with small binaries. I also really like nimfmt to keep my code tidy so I
don't need to worry about it. Nim compiles VERY quickly and errors seem to be
easy to comprehend. It's definitely one of my go-to languages for most of my
projects.

------
dglass
Is there anyone using Nim either in side projects or in production that can
comment on how they like it?

I keep hearing about Nim and it sounds interesting, but I'm not sure I have
the mental capacity right now to do a deep dive into the language and build
something with it. I'd like to at some point soon though.

~~~
treeform
I use Nim in production. I been using it for more than 1 year in production.

I like it. For me, it started out as a faster python that prevents typos. But
it has really grown on me. I really like that I can share libs on server
(compiling to c) and client side (compiling to plain javascript).

Basically any C library is also a Nim library with a tiny wrapper. That's a
huge ecosystem! I also like how Nim can integrate with complex C++ libs that
do virtual table call backs. It can also call objective-C functions .. you
know the ones with [foo a:1 b:1] crazy syntax? Python was a glue language for
me, but Nim can just glue more things.

JS too! In Nim you can just compile to plain JS, that other JS can call as
well. Pass plain JS objects around. I basically replaced my JS code file by
file - there was no need for a huge rewrite.

I know docker and kubernetes is "the thing" right now, but I just like that I
can just scp the binary over. It just feels less complex. I feel like docker
solved the distribution problem for python and node... I just don't have a
problem to solve any more. It's just gone.

~~~
jamil7
I have some code duplication between android, iOS and a webapp / PWA. How
realistic is it to look at something like nim for codesharing?

~~~
dom96
Not the parent poster but I'd say it's very realistic. I've written a few
applications that target both JS (web browser) and binary (server) and it
works very well. One example of this is
[https://picheta.me/snake/](https://picheta.me/snake/).

I'm also working on a game that I haven't quite moved to iOS/Android yet, but
that is my plan. So far targeting the desktop with SDL and HTML5/Canvas with
the JS backend works very well.

------
yumaikas
Author of the article here, feel free to ask me anything if you're wanting to
understand something about the article, or about Nim. I am _not_ the author of
Nim.

I also want to point out that Nim does have an IRC channel (#nim) on freenode,
which was helpful for understanding some of these things.

------
lone_haxx0r
Nim's syntax is everything I hate in a language.

It's not bad, objectively speaking, but its design opinions are the polar
opposite of mine.

~~~
andybak
I'm half and half. I adore syntactic whitespace and it makes me sad that it
hasn't become more prevalent.

However the flexible identifier rules bother me no end. But as soon as my
editor of choice handles it transparently then I guess I might come round.

~~~
gtrs
> flexible identifier rule

When / how has this actually impacted you?

~~~
andybak
It hasn't because I've not done more than merely look at Nim.

However it bothers me aesthetically and has put me off trying it.

------
staticassertion
How do data scientists feel about Nim? It feels very pythony, but way faster -
could be a really cool language for them, similar to what Julia is trying to
be.

Curious if anyone in a DS role has tried it out. I'm certainly tempted to try
it out, I'm sure I'm losing lots of performance in parts of my analytics
pipeline due to Python being garbage slow.

~~~
pastage
The options in python to speed up your code are vast without really having to
do much, on a fundamental level. My outdated experience with Nimrod told me
that it was a tad too opinionated E.g. Everything is a string in dbs is
mentioned in the article.

It was an interesting language, for me it felt like a stepping stone to
something better. But the docs were really bad,

~~~
refaqtor
"Nimrod" experience is quite outdated. There have been great improvements in
documentation in the last year.

------
haberman
Is Nim stable? I have vague memories that some parts of its runtime had some
deep issues that weren't yet resolved, like maybe around concurrency? I see
the language is at 1.0 now, does it have a stable, solid, dependable
implementation and runtime?

~~~
refaqtor
I don't have vague memories. I use it everyday on production code on server
and embedded. I find it stable, solid, dependable.

~~~
eaurouge
Can I ask how you got started on embedded and on which MCU? I assume you mean
bare metal.

------
qwerty456127
Looks cool already but is it easy to cross-compile? I can copy a Python script
from my Linux machine and run it on both Mac and Windows PCs. Can Nim build
executables for other platforms nearly as easy?

~~~
creatornator
In addition to compiler switches that allow you to cross compile from the nim
compiler [0], you can compile to c or c++, and then invoke whatever cross-
compilation toolchain to compile to more esoteric platforms.

[0] [https://nim-lang.org/docs/nimc.html#cross-compilation](https://nim-
lang.org/docs/nimc.html#cross-compilation)

------
gonzus
Does nim have any way to write a one-liner that includes nested scopes?
Something like `nim --run="if(...) { while(...) { foo; bar;} }"`? Not knowing
nim, I just made that syntax up... :-)

------
edflsafoiewq
What're compile times like?

~~~
yumaikas
For me, I'm seeing compile times averaging around 5-10 seconds, with outlier
builds taking up to 40 seconds if the files in question aren't cached.

It feels faster than Go, but I think part of that is down to Nim's compile
output being verbose by default.

~~~
nimmer
Nim's compilation is much faster than Go.

~~~
dom96
As someone that compared both a while back (and a biased Nim core developer) I
don't think this claim is true. Go is really fast at compilation, but honestly
Nim is good enough.

