Nim 2.0.0 RC2
nim-lang.org
nim-lang.org
The library situation is a bit better now. But without a big company contributing in terms of libraries, the language usage will just be very low.
This one I still can't wrap my head around. F# basically was the source of almost all innovation in C# and C# still is missing some features and was not designed in the same way as F# so a lot of the features they "stole" feel tacked on.
Microsoft should have just made F# the C# successor.
I was traditionally trained like you under OOP and procedural methodologies.
After encounter FP I fully bought in and developed two mental models. The fp model lives side by side with the the oop/imperative model.
With equal knowledge in both one can make a more unbiased judgement. The fp model is actually superior imo.
I largely have the opposite strategy now when programming. My mental model is largely fp, and I occasionally cheat and sprinkle in procedural or oop syntax here and there as syntactic sugar.
The basic realization here should be that mutating shared state should be avoided and segregated as much as possible.
To be fair, all languages are syntactic sugar over asm which is s-s over CPU machine code. A mental model is just that: a model for something physical that's in your head. FP or OOP are both mental models for programming in nearly any language. Some languages have first-class FP or OOP features, and some don't, but you can tack-on either of these, and others, to nearly any language you want to. It's really dumb to look down on others choice of mental model if it works for them. I have seen successful projects that were designed around both OOP and FP models.
You underestimate the importance of compatibility and familiarity for existing developers. You can show C# code to any C++, Java or even JS programmer and expect them to grasp the idea of what's going on very quickly. This is a big deal and should not be discarded lightly
I think the reason it sometimes seems like it is that easy is that, as we gain experience with tools, we tend to forget the difficulties we had learning them.
Learning F# it instantly clicked.
OOP learning issues IMHO are intrinsic to the style, because it's just so seldom helpful in making programming easier.
Design patterns are just a symptom of this issue. That OOP is just a misunderstanding another.
"Real" OOP as practiced in Erlang/Elixir is quite useful.
their target audience does not want this
JS aside, I think there's probably some survivorship bias going on here. I don't think there are a lot of 15 year old, relatively unpopular languages that are still under active development. Maybe it's not that languages that don't become popular in 10 years never will, but rather that languages that don't become popular in 10 years tend to be abandoned by their developers, thus sealing their fate.
> I don't think there are a lot of 15 year old, relatively unpopular languages that are still under active development.
There are quite a few. If you look in virtually any language ranking, places 10-40 have many 10 year-old and even 15 year-old language. Here are some continuously developed >=15yo languages that are less-than-middling-popular and have always been so: Common Lisp, Racket, Clojure, OCaml, SML/NJ, F#, TCL, Haskell, Idris, Groovy, Squeak, Erlang, D, Ada, Nim. There are more of these than there are super-popular languages. (I didn't include any language that was, at one time, at least somewhat popular but is no longer, such as Visual Basic, Delphi, and Perl 5).
There might still be survivorship bias, but I am not saying all that is fate, just a clear historical observation.
> Languages that get adopted faster than 7 years are unusual, and it indicates that they came out at highly opportune times to address specific needs.
Not only is it not unusual, over hundreds of languages I think there has really been one exception (for 10 years; maybe not 7). At age 10 how well a language does is more or less how well it's ever going to do. I am not saying this is a prediction, but it has been the case historically with almost no exceptions. Any language has the chance to buck this trend, but it has been the trend.
As background, style insensitivity was introduced so that codebases can use a consistent camelCase or snake_case regardless of the style used by upstream libraries.
Hearing again I cannot chuckle when Araq says: Nim v1 is good at everything, Nim v2 is supposed to be better at everything.
Back then it was supposed to come out in 2022 and indeed a RC1 came out in Dec. In the blogpost for RC1 you find the desciption of all new features: https://nim-lang.org/blog/2022/12/21/version-20-rc.html
This longer time is because extra care is being taken into having a smooth transitions (for example important libraries have been tested to work on nim v2, e.g. we made sure nimib was working with v2 in early Feb: https://github.com/pietroppeter/nimib/releases/tag/v0.3.6)
One of the part of the project (feed collector) I tried to write in many languages to compare. One day I downloaded Nim - did not expect anything at all - just wanted to try async and ... in about 2 hours (on new language for me) I had the same functionality I spent 2 weeks in Rust. More interesting - it was about 30% faster than Rust solution.
After it, I can just show the picture: https://user-images.githubusercontent.com/4949069/229308266-...
I rewrote full (2 years+) project in Nim in 3 weeks. I understand that I knew good architecture for the second implementation, but 3 weeks is good anyway.
Did a lot of pet-projects, I use it for small prod tools or research if it is possible.
For example I wanted to extend atop functionality, and I wrote my own ttop: https://github.com/inv2004/ttop
For new Nim's user I would describe it like python with speed of C-lang. But later you will find that it is not another python, it is its own language with a lot of powerful things like templates, macros, very good interop with C (that is why libraries are not a problem most of the time) and etc.
One awesome project is https://github.com/jmgomez/NimForUE
EDIT: I think I found it - looks like it actually isn't new: https://forum.nim-lang.org/t/1278. Sounds like the answer is: Links via GCCGO to their channel implementation. Compatible GC was written in Nim to go with it.
Let me suggest a new one: a language which is top-dog in it's language interoperability. Imagine a language that can do nearly nothing except glue together code from other languages. Maybe you want to call some Java code from some Go code from some Nim code from some Python code from your C program: this language would do that for you somehow.
Another idea for that would be GraalVM’s Truffle. It’s not a language, more of a universal VM, but it can actually already just eval some python code, use the resulting code from Java and pass it on to JS. It also has support for any LLVM language, so C can be invoked from/be invoked from any of the aforementioned languages. And it can even optimize across language boundaries, pretty incredible.
However it takes a long time to accrue enough good wrappers and bindings.
I guess business just ignored the prototyping part.
If you enforce a code style or, if you don't but you would convene that someFunction and some_function should mean the same thing in your codebase. Then nim's approach should be transparent to you.
So don't bring up nimgrep like it's a necessity when it's more of a last resort tool nowadays. You will be just attracting flaming.
Such a mistakes is easy for a linter to pick up on so that the code would never be merged in the first place.
> It's so external dependencies don't have to infect your codebase. So you can actually apply a consistent code style within your project.
Say an external dependency has a declaration called 'getFileSystem', and in my Nim codebase I refer to it as 'get_file_system', but last year someone accidentally committed 'get_filesystem'. In this case neither usage matches the declaration. Does the linter flag both spellings because they don't match 'getFileSystem'?
EDIT: And what about reflection? If someone wrote `newCall("get_filesystem")`, will the linter fix that too?
I suspect, in practice, almost everyone follows the sane approach of enforcing a code style in your codebase. I think what usually gets lost when this is brought up is that the point of this code style insensitivity is not to encourage you go to crazy and mix and match it in your projects. It's so external dependencies don't have to infect your codebase. So you can actually apply a consistent code style within your project.
test.nim(2, 8) Hint: 'myvar' should be: 'myVar' [var declared in test.nim(1, 7)] [Name]
edit --styleCheck:error perhaps?
- hand tvättas (wash your hands) != handtvättas (wash by hand)
- sjuk gymnast (sick gymnast) != sjukgymnast (physical therapist)
- sjuk sköterska (sick nurse) != sjuksköterska (hospital nurse)
- lång hårig (tall and hairy) != långhårig (long-haired)
- sjö nära tomt (lake near a house) != sjönära tomt (house near a lake)
Here's one illustration: https://github.com/nim-lang/RFCs/issues/456#issuecomment-111...
We have partial case-insensitivity in PHP. Can't say I'm very fond of it, but I'm ambivalent as long as it's not abused.
And "C names are usually very cryptic" is plain false, unless you talk about APIs coming from the ages and compilers where all identifiers had to be 8 characters or fewer in length.
This is literally idiomatic Python style! Classes are TitleCase and everything else is snake_case.
I have also used a mix of camelCase and snake_case for different purposes, eg in Haskell where conventions are mixed (and I am far from an expert), I've written names like "fooBar_prev"
And Nim does distinguish between those.
> I've written names like "fooBar_prev"
That's disgusting.
Also, John Carmack: https://mobile.twitter.com/id_aa_carmack/status/159256093820...
E.g. The Python Selenium library used to be in CamelCase, while almost all code in Python is snake_case. By using Selenium you ended up with code like:
my_button = browser.getElementById("Button")
They rewrote the whole library to be in snake_case, a change that forced a lot of code rewrite downstream. Even the Python builtin library has case inconsistencies (logging module is camelCase, sys has both alllowercase and snake_case) that weren't fixed even in 2to3.Nim would have handle this efortlessly, allowing you to use get_element_by_id or getElementById in the old library, and avoiding you the effort to rewrite your code if the Selenium mantainers decided for a case change. You can refactor your case without fear of making life worse for your users.
The downside is that for each library you want to do this to, _once_ you have to spend a few minutes writing the renamings.
The upside is that if you now want to find everything that uses the external function getElementById, you can search for _that_, and you will find the "rename getElementById as get_element_by_id"[1] declaration, and then you know to search your project for get_element_by_id to find all the places where it's used.
[1] I am not suggesting that particular syntax; I just picked something at random.
The other upside is that if you want to find uses of the getFoobar function that's defined in your project, you just have to search for getFoobar rather than doing a case-insensitive regex search for "_*g_*e_*t_*f_*o_*o_*b_*a_*r_*". (Or, if your answer to that is to use language-specific tooling, that you aren't forced to use language-specific tooling when it might be more convenient to do searches on the GitHub website, or in the text editor / IDE that everyone else on your team uses, or in the text editor / IDE that you'd been using for years before starting to use Nim.)
To me, this seems like an obviously better design. I don't want people who have spent years becoming productive in Emacs, or Vim, or Visual Studio, or whatever, to have to choose between using some different set of tools they aren't used to and having the searching operations they're used to using silently do the wrong thing.
Am I missing something? Because, rightly or wrongly, this one weird design decision is enough to keep Nim off my list of languages that are worth the time to investigate: not because this single thing makes that much difference on its own (though it does feel as if it would make my life substantially worse, if I were writing a lot of code in Nim) but because I feel like the language is designed by someone who makes weirdly terrible design decisions sometimes, and if that's what I want then I already have C++ and Javascript :-).
Are you seriously expecting that someone will put an underscore in the middle of a word?
I don't have a plausible example of #2 in mind. Maybe there aren't any. (There are definitely lots of things that break into words in multiple ways, of course, but maybe there aren't any that make plausible identifier names more than one way. Though for what it's worth I bet there are.) And in any given case you can check, given a few seconds' thought, that there aren't other possibilities. But that little extra cognitive load is a bigger deal than it sounds like -- it's a distraction from other things -- and if you don't do the check then you'll never know whether your search operation actually found everything it should have.
So you can check by eye every time. Or you can write the ugly regexp every time. Or you can just accept that what ought to be a perfectly simple operation isn't quite right and might invisibly go wrong some time.
That's not a set of options I like.
As far as renaming external libraries goes, if the original name is get_foobar, and the project uses snakeCase, I would be very surprised if it's renamed to anything other than getFoobar. There are slightly more tricky stuff like get_ID, but even then there are only a couple of reasonable forms to search for. And it's rare to be searching for things you haven't seen used, and if you saw it used you know how it's spelled in that library.
I've been programming for years in Nim and never had any problem grepping or searching for things because the style insensitivity.
I don't think it's reasonable to force every developer to spend a few minutes writing renamings if virtually all of them are obvious mechanical transformations, just because a paranoia not substantiated by experience.
Third party Nim libraries? Because if the all used the same style this would never be needed in the first place.
Rust never has this issue because everyone uses the same style.
I see it as a mandated style checker built into the language.
The issues are:
1. Difficult to search code. Even just case insensitivity makes this worse because often you do have names that only differ in case (but in an acceptable way, e.g. they're different kinds of thing, or namespaces). But ignoring underscores makes it much much harder - now every search needs to be a regex.
You can say "use an IDE!" and you absolutely should but you still sometimes need to search with dumb grep style tools.
2. Case insensitive rules are always more complex and difficult to remember. Where do they apply? All identifiers or just variables? What about keywords. Nim's rule is especially complex. It adds cognitive load.
3. Extra bike shedding. I imagine they added it to avoid bike shedding? But it will have the opposite effect. They should have just made a language wide convention like Rust. Nobody debates case style in Rust or indentation style in Go because the tooling and community pretty much force one style.
I fully anticipate a Nim linter that bans style variation from the canonical one. If that doesn't exist already.
I don't know about Rust, but Python has a language-wide convention – and programs still violate it, including the standard library.
import logging
import sys
sys.breakpointhook()
sys.exc_info()
logging.getLogger(__name__)
And both `sys` and `logging` are not obscure builtins, they are used everywhere. And just for that, case is not fixable.2 - Negligible cognitive load in my experience. You can just ignore that part of the language and treat it as case sensitive and everything will work. Inside projects it's effectively case sensitive too. And the rules just make sense, they are just there to allow you to be consistent in your casing, nothing less nothing more. It applies everywhere they are need for that, and nowhere else.
3. Gofmt wasn't a thing when Nim(rod) started and now is too late to force all projects to a single style. But projects are internally consistent, and you can always use your preferred style, so I consider Nim's a superior solution.
> I fully anticipate a Nim linter that bans style variation from the canonical one. If that doesn't exist already.
The compiler already warns you by default if you are not consistent on the spelling of identifiers inside your code, and you can make that an error too. See `--styleCheck:usages` and `--styleCheck:off|hint|error`. There is a nim linter that can make your code conform to NEP-1, but last time I saw it was a bit too buggy in that style transformation, so people don't usually use it.
I've been programming for years in Nim and never had any problem grepping or searching for things because the style insensitivity. In pratice it's a non-problem.
I think I remember reading early remarks from the Nim team that you can opt-in to the symbol sensitivity but it's a marker comment per-file, or some kind of DIY preprocessor which does the same. I'd be happy if it was a CLI switch.
All that said, and in practice, clearly a lot of people are fine with this and even like it. I'd much rather Nim exist with this (IMO) oddity than not at all.
If I'm looking for some example code that uses my_testfunction(), I can't just search for "my_testfunction nim". Instead I have to add MyTestFunction, my_test_function, MYTESTFUNCTION, etc. The case-insensitivity isn't really a big deal, but the underscore-insensitivity is.
If I'm honest, I think this is a big problem for adoption of the language. It's incompatible with a lot of search-engines, and weird to anybody coming from any other programming language. Nim should take advantage of the 2.0 release to do a compatibility break in this area, maybe with a compiler flag to enable the legacy behavior.
Can confirm, it single-handedly kept me away from the language.
> Nim should take advantage of the 2.0 release to do a compatibility break in this area, maybe with a compiler flag to enable the legacy behavior.
No thanks, I don't want inconsistent naming conventions in my code.
Style insensitivity lets you automate your local code (and/or through CI) to consistency for easy searching, even when external libraries YOLO their own style.
> It's incompatible with a lot of search-engines
Google and search engines are case insensitive, and mostly ignore underscores too. Let's be honest, how often would you just search for 'testfunction libraryname' on the web and get the signature you need?
My experience from using the language in production for years is that case insensitive searches will find what I want in Nim code specifically because no one can use case/underscores to make things make unique. Instead, the language uses overloading through the type system to distinguish things. This is a far more succinct, safe, and expressive way of writing code from my perspective.
It's worth noting that the first letter of an identifier is case sensitive, with the convention for types to start with a capital letter. So, you can write 'type Test = object' and 'proc test(t: Test)', then use them with 'var test: Test; test(test)' without any ambiguity, and with code completion/jump to source in VSCode (and others).
If you then add 'proc test()' with no arguments, it's still unambiguous because the functions have different signatures, so you can then write 'test()' and your second function is called.
If something is ambiguous, it's a compile time error. If you want, you can prefix modules like Python, but there's never any need. If you have two libraries with the API, same types, and function signatures (such as using two async libraries in the same program), you can just slap a generic '[T]' so it's lazily instantiated at the call site and move on.
IMHO relying on casing/underscore to distinguish identifiers is objectively worse than using the type system to statically and unambiguously prove your intent, and normalising names removes a class of identifier confusion bugs to boot. Even style guides in case sensitive languages beg us not to use case and underscores to disambiguate symbols for the confusing code it creates, and to be honest, I've yet to see a compelling argument in favour of case sensitivity beyond simply being what people are used to.
Nim developers are as smart as any other, and they like and write clean codebases adhering to the convention in NEP1. The ability to mix cases is used to fix libraries without having to disrupt their users.
I've seen this kind of complains over and over: a new language emerges (e.g. Python 20-30 years ago), and what people finds the absolute showstopper is the indents instead or braces, a minimal part of the language that should not bother a competent programmer at all. The same people that were writting old PHP or old Perl, go figure, complainig that Python whitespace is ugly.
The functions in the blog post have void return type because between `)` and `=` there is no `: [type]`.
[1] Well, not really a competitor, Virgil is never going to hit it big, heh. I'm mostly scratching my own itch and doing research.
Edit: thanks for all your works btw, it means a lot.
If Nim had a super robust web framework, usage/adoption would skyrocket.
It has all the ergonomic benefits of a language like Python but the perf/memory of C.
Even if the speed wouldn’t do it for many people over, say, FastAPI, the static typing and less insane package and dependency management than Python, and lower friction/boilerplate than Go might.
But if they had perf/memory of C they wouldn't need to run on high powered servers!
If a language allows you to be productive and can deliver high performance that can reduce your ops complexity and your hosting bill, what's not to like?
Since it has first-class support for compiling to JavaScript, it could offer fullstack type safety web development in a single language.
It's also very easy to grok by being Python-like.
https://github.com/ringabout/awesome-nim
packages.json has many more - over 2000.https://forum.nim-lang.org/t/9132
https://gist.github.com/j-james/08cd36b7475d461d6291416381ce...
I have strongly suspected for a while now that the language is kind of irrelevant, but the supporting infrastructure like package managers, IDEs, other utils, platform support, libraries, etc are far more important when picking a language to use. Who cares if java programs are 2x as long? Trying to fix your $obscure_language$ tooling will take 10x as long.
And after that, the language might become popular because some big companies use it/develop it, or someone makes a killer library. Most reasons are just not relevant to the language itself.
https://news.ycombinator.com/item?id=34669902
basically Nim has several features which on their own seem great, but don't compose with each other properly. also it's been many months since I used Nim so some of the details may be outdated or misremembered but the overall gist of what i'm saying is >90% true so i don't care if anyone nitpicks this:
Nim has UFCS (uniform function call syntax). so whenever you have f(a, b), you can write a.f(b), and it means literally the same thing (until you read the fine print for the parts where it's not). and you can also omit parentheses when it's unambiguous, so you can write stuff resembling method-chaining or unix pipelines in a totally natural way: foo.bar.baz(x, y).qaaz().quux is the same as quux(qaaz(baz(bar(foo()), x, y))) and way more readable bc less parens and the execution order is left-to-right. it's so, SO, tempting to write lots of code this way, because it's such a rare language feature, and it fits with the way I think.
but it's not just functions, there are a lot of function-like things, i.e. the stuff you can write as f(a, b): methods, ad-hoc overloaded functions, generic functions, templates, macros, iterators, etc. but things don't work consistently across all combinations of function-like objects, argument types, and function-call syntaxes. iterators is one part where the abstraction breaks, and iirc there are a few others (certain kinds of templates?).
there are two kinds of iterators: inline, and closure. inline iterators are meant to be a zero-cost abstraction, basically a for loop that gets inlined at the call site by the compiler, and they're not first-class objects. closure iterators otoh are first-class objects and can be passed around, but they have runtime overhead (idk how much). so lets say you want to make an API that consumes an iterator and does something useful with it, e.g. higher-order functions like python's itertools (Nim advertises itself as being similar to python in important respects like this so it's a valid comparison). great, so then you try to use it on the builtin "lines" iterator (the one that splits a file at newlines and yields each line as a string). oh no, you can't, because "lines" is an inline iterator so you can't pass it to a function.
fine, so the language has handed me this pile of dogshit that I can't do anything useful with directly. surely this would be a common enough problem that there must be a helper macro in the stdlib that lets you convert between inline and closure iterators? nope, there isn't. okay but writing one should be trivial, right, given the vaunted metaprogramming capabilities of Nim? well, I tried writing one in the most obvious way. and it behaved differently when I used UFCS vs not. and when I experimentally called it on a closure iterator (expecting it to be effectively a no-op), the compiler segfaulted. and when I asked about this in the discord, nobody could figure out why it didn't work. later I found an implementation of inline<->closure conversion macro and it was like hundreds of lines of gensym fuckery and god knows what. i don't know why it should be so complicated.
oh and btw, even with the supposedly "first-class" closure iterators, it is impossible to write a generic function like f: iterable[T] -> iterator[T]. you have to use a template. and the syntax for doing it is counterintuitive. and the "iterable" keyword in the function signature doesn't mean what you think anyway. when you ask in the chat "oh my god just please tell me how to do lazy iteration", they say "don't worry it's easy, just use [x]", where x is one of half a dozen mutually incompatible 3rd party libraries, each one expecting you to learn its own mad little DSL that you can't really extend or integrate with normal Nim code. and then you look at the implementation: enormous inscrutable macros, which are that way presumably to work around all the crap I described in the last paragraphs and even more I don't know about. I don't want that in my dependencies! the docs don't prepare you for all this complexity; templates/macros/iterators are documented like that "draw the rest of the fucking owl" meme.
the "sugar" module has a macro to let you write lambdas more compactly. but if you try to do something straightforward like pass one into sort() as a comparison function (ie the kind of stuff that comprises 95% of the legit uses of anonymous functions in grugbrain code), it doesn't fucking work reliably. like it will probably work on a simple case like sorting a bunch of strings by their length, but the minute you introduce some complication like generics it all falls apart and the compiler spams ten pages of indecipherable type errors at you. and then they'll say "just use sortIt" -- no, fuck you, i will never use sortIt, i hate anaphoric macros, just let me pass in an honest function.
what I'm getting at is, you know how frictionless it is to sling around iterators and generators and first-class functions and so on in Python, even with mypy --strict? and you read about Nim's UFCS and macros and generics and you think "great, best of both worlds", imagining yourself as a ninja doing "myfile.txt".lines.map(func1).filter(func2).max(key=blah).frobnicate, and it all Just Works[tm]? well the reality is as frictionless as dragging your face across raw asphalt.
Can't argue with that logic :-P You've obviously spent years writing nim and know what you're talking about /s
But in all seriousness, as the author of the sugar.collect macro, I am fond of it. I understand that not everyone likes how fp is done nim but it's ok.
It's great that a composition of libraries (sequtils, sugar, algorithm) can get us close to the effortless quasi-FP people may be used to from LINQ. I just wish this would be merged into one library. Pretty much every single module that uses one of them imports all three in my code. We need one, consistent, awesome library to interact with collections.
https://nim-lang.org/1.6.0/gc.html
for upcoming v2: https://nim-lang.org/docs/mm.html
Note that beginning with v1.6.2 it's specified with `--mm:[choice]` instead of `--gc:[choice]`, though the latter still works.
And beginning with v2, the default GC will be orc, while to date it's refc. That's an important change and has involved a lot of hard work by maintainers and contributors leading up to the release of v2.0.0.
See also the user guide for Nim's compiler: