News for hackers. Stuff that matters.
Re:Why we switched from Python to Go by jamiesonbecker on Wednesday October 18, 2017 @10:07AM (#15499233)
For that project, we had very specific requirements: easily handle SSL/TLS with contexts and control over self-signed vs certificate checking, JSON processing, speed, nice syntax, and one of the most challenging requirements: statically compiled, linkable against musl and libressl, while still supporting mingw_64 for windows. Only a few languages have flexible compilers that can do this; for example, rust can't (afaik).

The experience so far has been outstanding. Nim has functioned flawlessly with a minimum of magic. It seems to work very cleanly and the compiler is cleanly integrated, but still swappable (ie between gcc, clang, ming..) Nicely color-coded, too.

Exceptions are caught with full tracebacks, and pre-compile checks quickly point out exact location of syntax errors. (Good, clear error messages are surprisingly missing from many languages.)

Here's an awesome example; in my first day of coding, I was able to replicate python's "+" string concatenator ("hello" + "world" versus "hello" & "world" in Nim) with a one-liner:

    proc `+` (x, y: string): string = x & y
This is pretty amazing; not only is it readable and concise (and more than a passing similarity to python's lambda, of course) but nim comes with the ability to define new operators right in the language, and the compiler raises an error if operators, procs, types, etc would introduce ambiguity.

Nim compiles quickly and its type inference (where it guesses what type of variable you're working with) makes strong typing mostly painless, and you still get all of the advantages (type safety, speed) of static typing.

There are some trade-offs that are made (obviously), but the language designers seem to make trade-offs in favor of speed and robustness over language features -- but this still leaves a lot of room for features.

I also like how the syntax has a lot of similarities to Python's. The only thing I've missed so far is a nim interpreter, so that I can get up to speed faster on the syntax or try things out quickly. The tutorial on the Nim website is definitely not for beginning coders (who would probably be quickly scared off by words like lexical), but it quickly covers the language syntax for experienced coders and seems to borrow a lot of the best ideas from other languages.

Nim is basically awesome. The few downsides are that the standard library is still pretty light (but that gives you an opportunity to build something great and have it be widely adopted), that there's no interpreter, and that the tooling is still a bit lighter than older languages. All of these will be improved with time.

And, it's fast. Really fast. Compare nim in these benchmarks[1] to any other mid-level (or even low-level) language and it really shines. It's generally much faster than Go, for instance.

1. https://github.com/kostya/benchmarks

Re:Why we switched from Python to Go by Tiberium on Wednesday October 18, 2017 @10:21AM (#15499366)
You can also check out this: https://github.com/Yardanico/nimpylib But there's almost no features in it as I'm lazy :) I think that the best feature in this lib is a python-like range type: https://github.com/Yardanico/nimpylib/blob/master/src/pylib/...
Re:Why we switched from Python to Go by jamiesonbecker on Wednesday October 18, 2017 @10:39AM (#15499496)
https://github.com/Yardanico/nimpylib/blob/master/examples/e... is really slick... looks so much like Python.
Re:Why we switched from Python to Go by bronze on Wednesday October 18, 2017 @11:23AM (#15499861)
> no interpreter

Try running `nim secret` on the command line, it's not perfect but it's enough to play around a bit.

Re:Why we switched from Python to Go by jamiesonbecker on Wednesday October 18, 2017 @03:05PM (#15501979)
Thank you!
Re:Why we switched from Python to Go by Tiberium on Wednesday October 18, 2017 @10:13AM (#15499294)
If you do concatenation a lot, it's better (for performance, of course) if you make it a template (so Nim will just replace a + b with a & b):

  template `+`(a, b: string): string = a & b
But probably C compiler is smart enough to inline your proc :)
Re:Why we switched from Python to Go by jamiesonbecker on Wednesday October 18, 2017 @10:37AM (#15499486)
Ah, brilliant! thanks!!
Re:Why we switched from Python to Go by steveklabnik on Wednesday October 18, 2017 @12:26PM (#15500491)
Rust can do what you asked, as far as I know.
Re:Why we switched from Python to Go by jamiesonbecker on Wednesday October 18, 2017 @03:08PM (#15501997)
Excellent-- thank you for the correction!