
Show HN: Wireworld written in Nim - JHonaker
https://github.com/JHonaker/wireworld-nim
======
JHonaker
Author here, I spent this weekend making an implementation of a lesser known
(to me at least) cellular automaton, Wireworld.

It was my first non-trivial project in Nim. I had a lot of fun. It uses SDL 2
as the graphics engine. Let me know if you have any little suggestions for it,
or any questions about the development.

~~~
sevensor
284 lines! I'm impressed by the brevity. Were the SDL bindings as
straightforward to use as they appear?

~~~
Jach
I've worked with Nim's sdl2 interface too, it is indeed pretty
straightforward, and it was easy for me to tell vim to know how to jump to the
nim wrapper's source. The main pain points for me were 1) sdl2 is harder than
sdl1 and 2) I thought some type conversion behavior (or lack thereof) was odd,
especially when working with 'cints' (which is what the wrapper api expects
everywhere).

For a more flushed out example there's:
[https://hookrace.net/blog/writing-a-2d-platform-game-in-
nim-...](https://hookrace.net/blog/writing-a-2d-platform-game-in-nim-with-
sdl2/)

~~~
JHonaker
I actually used a few snippets of this tutorial to figure out how to use the
SDL bindings. I'd never used SDL before.

------
cookiecaper
It's cool to see Nim getting more visibility. It's a cutting-edge language
that gets overshadowed just because it doesn't have MegaTechCo's name behind
it.

~~~
throwaway7645
It's really nice for the small hobby projects I do. Small native executables
is great.

~~~
squarefoot
To me it seems just the right choice for embedded systems: fast, small, easy
to understand and translates to C.

------
dom96
This is really well written, thank you for taking the time to post it to HN to
give Nim a bit of visibility. Have you considered using Nim's JS back end to
make it work in the browser?

~~~
JHonaker
> This was really well written

That means a lot to me!

> Have you considered using Nim's JS backend to make it work in the browser?

I was thinking about it after seeing someone else's GoL in this thread. I'm
guess I would need to write another display layer though.

------
rwbt
Nim is probably the most easiest language I've picked up. It's a delight to
program in Nim and the performance is stellar (beats hand coded C in many
cases). It's a rare feat really.

~~~
swah
Be very careful about stating that GC'ed languages beat C - jblow might appear
suddenly to correct you... with pure common sense.

~~~
rwbt
Coming from C++ (with C experience too), I too was hesitant about Nim because
of GC. But I can turn it off completely or even better "\--gc=stack" which
makes it behave like C++ (dealloc when going out of scope). The compiler is
also good at telling you what calls use GC'ed memory, so you can work around
them if necessary.

But even with GC on, Nim is super fast. I use it in real time rendering and I
honestly didn't see any significant performance loss. In fact, it made some
routines much faster because the Nim compiler produced much better C code than
I ever did.

~~~
pjmlp
> But even with GC on, Nim is super fast....

This is what I experienced with GC enabled systems programming languages
(Oberon family of languages) back in the late 90's, just with C++ as
comparison on my case.

The main problem is the culture of micro-optimizing code without profiling it,
that is so prevalent in those communities.

------
Cieplak
Here are the commands I ran to get this running on FreeBSD:

    
    
        pkg install nim nimble sdl2
        git clone https://github.com/JHonaker/wireworld-nim.git
        cd wireworld-nim
        nimble install sdl2
        nim c display.nim
        ./display

~~~
JHonaker
Ah yea, I should probably add the nimble install line to the instructions.

------
throwaway7645
I always enjoy seeing these little Nim projects.

