[HN Gopher] Building a simple room-based chat application in Nim...
       ___________________________________________________________________
        
       Building a simple room-based chat application in Nim (using HTMX)
        
       Author : todsacerdoti
       Score  : 95 points
       Date   : 2021-12-17 16:51 UTC (6 hours ago)
        
 (HTM) web link (arhamjain.com)
 (TXT) w3m dump (arhamjain.com)
        
       | treeform wrote:
       | I love Nim. I been using it professionally for more than 3 years
       | now. At first I started with it just as a faster python with
       | types, but it so much more! You can run Nim everywhere regular
       | places such as backend, frontend, mobile, but also in crazier
       | places like GPU shaders and imbedded.
       | 
       | I also like the community. It's not so big that it feels like you
       | only see people once but not so small that there are no useful
       | libraries written. Just the right size for me. You can always get
       | people to help you out on stuff, reminds me of old IRC days.
        
         | speg wrote:
         | Reminds me of Crystal, which I'm also using with HTMX. I'm
         | afraid if I check out nim I'll have to start all over :)
        
         | 0-_-0 wrote:
         | Wait, did you say GPU shaders? How?
        
           | cb321 wrote:
           | https://github.com/treeform/shady
        
           | treeform wrote:
           | See this as one of the examples:
           | https://github.com/treeform/shady
           | 
           | It makes debugging shaders much easier as you can use print
           | statements and unit tests. You can also share code between
           | CPU and GPU side.
        
         | iffycan wrote:
         | > but not so small that there are no useful libraries
         | written...
         | 
         | Says the person responsible for a ton of really useful, well-
         | done Nim libraries, such as this amazing Cairo/Skia-like
         | library: https://github.com/treeform/pixie#readme
         | 
         | Thank you for all the things you've made for Nim!
        
           | bch wrote:
           | OT: but watching this made me wonder: is Skia[0] supposed to
           | form a pun[1] (Cairo/Skia), when mentioned with Cairo[2]?
           | 
           | Why does this sound like some sort of code[3][4] that leads
           | to some sort of Ouroboros[5] ultra pun[6]?
           | 
           | Quick! To Rome!!
           | 
           | [0] https://en.wikipedia.org/wiki/Skia_Graphics_Engine
           | 
           | [1] https://en.wikipedia.org/wiki/Chiaroscuro?wprov=sfti1
           | 
           | [2] https://en.wikipedia.org/wiki/Cairo_(graphics)#History
           | 
           | [3] https://en.wikipedia.org/wiki/The_Da_Vinci_Code
           | 
           | [4] https://drawpaintacademy.com/chiaroscuro/
           | 
           | [5] https://en.wikipedia.org/wiki/Ouroboros
           | 
           | [6] https://www.britannica.com/art/skiagraphia
        
       | [deleted]
        
       | gunapologist99 wrote:
       | Very, very cool demo! If someone decides to use this for
       | production, don't forget about sanitizing inputs to mitigate XSS,
       | CSRF, etc (and, of course, message storage, authentication, and
       | all those other things.)
        
         | ajusa wrote:
         | (Author here) Thanks! The inputs aren't sanitized in this
         | example, but the output (the generated HTML) actually is in
         | this case. Specifically this part:                 text ": " &
         | sentMessage.getStr()
         | 
         | The `text` function in the Karax DSL is actually escaped once
         | it is converted to a string, see
         | https://github.com/karaxnim/karax/blob/c71bc927494418c3f52f9...
         | for the implementation if you are curious. There is a way to
         | render raw HTML using `verbatim` instead of `text` in Karax.
         | 
         | So in this case, I believe it would be protected against XSS to
         | some extent, but I obviously haven't done an in depth security
         | check for a demo/simple project. There are plenty of other
         | potential issues as well (username collisions, websocket
         | errors, user lists) but I judged those to be out of the scope
         | of a simple project like this.
        
       | oneplane wrote:
       | At this point I'm more worried about the whole supply chain of
       | libraries and dependencies in the background than how nice the
       | abstractions are.
       | 
       | It used to be that a powerful demo of a framework or language
       | would be a pretty sweet starting point, but I'm not so sure about
       | that anymore.
        
       | kitd wrote:
       | This is a really good sales pitch for both Nim and Htmx IMHO.
       | I've used htmx a bit but never Nim. Even so, the code is easy to
       | read and follow.
        
       | makeworld wrote:
       | I wrote something similar with Go and HTMX. It's a powerful
       | combo, and HTMX is really great for someone like me who is not
       | interested in writing JavaScript. I had to write ~10 lines for
       | this project, but that's much less than doing the whole thing in
       | it.
       | 
       | https://neartalk.makeworld.space/
       | 
       | https://github.com/makeworld-the-better-one/neartalk
        
       | fouric wrote:
       | > In Nim, converters are automatically ran to convert between
       | types if needed.
       | 
       | Huh, this is an interesting take. Instead of taking either of the
       | extremes of "coerce types aggressively" (Perl, PHP, C (kinda)) or
       | "no type coercion ever" (CL (kinda), Rust?), Nim has programmable
       | type coercion, so you can enable it just when you need it.
        
       | e67f70028a46fba wrote:
       | Not bad for 70 loc!
        
         | cb321 wrote:
         | Much Nim code is similarly concise.
        
       | lelandbatey wrote:
       | This Nim example is very short. For comparison, I'd created a
       | similar chat service from vanilla Flask and Vanilla HTML (with a
       | tiny amount of jQuery) about 8 years ago and even though it was
       | very basic it took ~500 lines of Python2, HTML, CSS and JS (even
       | though it's only 3 files).
       | 
       | https://github.com/lelandbatey/flask_example/tree/master/fla...
        
       | wpietri wrote:
       | For those that want to know more about Nim, it is "a statically
       | typed compiled systems programming language. It combines
       | successful concepts from mature languages like Python, Ada and
       | Modula." : https://nim-lang.org/
       | 
       | And HTMX "allows you to access AJAX, CSS Transitions, WebSockets
       | and Server Sent Events directly in HTML, using attributes, so you
       | can build modern user interfaces with the simplicity and power of
       | hypertext": https://htmx.org/
        
       ___________________________________________________________________
       (page generated 2021-12-17 23:00 UTC)