Live data from Hacker News

Rosencrantz – A Web DSL for Nim

github.com

21–30 of 31 posts

Re: Rosencrantz – A Web DSL for Nim

#21
post #20
post #19

Earlier quoted context omitted.

The problem with this approach is that it would be difficult to make handlers first-class. What if your post routes are a handler imported from another module? Templates would allow for the syntax you present, but do not combine.

That's not at all the case. Templates can return values. So really, you could think of the templates as syntactic sugar around the existing functions you've got right now. For example, the 'firstOf' template above would be responsible for scanning the AST it's given, taking each node and putting it in to a sequence. Then it instantiates a Handler with that sequence and returns it.

Of course template can return values.

The problem is that they need to be given the AST. What if one constructs a handler somewhere in another module (say an authentication handler) and you import it? How can you reuse it, considering that it needs to surround other handlers (that is, if auth fails, you do not go inside inner handlers)?

With Rosencrantz it is easy: if `auth` is our authentication handler, and in your module you define a handler `h`, you can use `auth -> h`, or `auth[h]` if you want to spell `h` inline.

Now, what you could in fact do is write a template `authTemplate` that takes a handler `h` and returns `auth -> h`, so that you can still write in template style. But you have to do this for all handlers.

It could make sense to provide such templates for builtin handlers, though... want to chime in? :-)

Re: Rosencrantz – A Web DSL for Nim

#22
post #6

Earlier quoted context omitted.

Yeah, I also had positive experience with nim. I'm not sure why it's so unknown, maybe because it fits in the same niche between rust and go and not backed up by any major company in industry. But I highly recommend trying Nim out!

Nim is great, and I use it (in production), but I know exactly why it isn't as popular: Nim is fucking huge. Most programmers I know don't even know what a pragma is; Nim uses them extensively. Nim has types, objects, is low level, can be compiled to shared objects (something that didn't come out to Go until 1.5), macros, generics, templates, oh and it compiles to both C and JavaScript (and C++, and Objective C in ca…

What you've just described is a hodgepodge of stuff thrown together. That's a lack of language design with a surplus of features. My readings on older reports for language designs showed the art was figuring out just how much power to include in the language & keeping it all consistent/sensible. One can overdo it.

An example of a clean, carefully-thought language that's low-level, consistent, and very powerful is PreScheme:

https://en.wikipedia.org/wiki/PreScheme

Modula-3, a C++ and Java competitor, was another where they made careful tradeoffs of features, safety, compile speed, run speed, and ease of learning/reading.

https://en.wikipedia.org/wiki/Modula-3

There's also some dialects of Haskell and ML focusing on system level. Didn't hit those levels of maturity though. What I'd like to see is someone take the Nim tech, subset it, change inconsistent stuff to be consistent... basically clean it up into a coherent picture... then deploy that as a new language. It could be pretty awesome if it happens. Right now, it's too complex and incoherent except for people, as you said, willing to do a huge learning curve.

Note: Nim is so huge now that it might be easier to add Ada static checks and Rust dynamic/concurrency checks to PreScheme instead of fixing Nim. You'd have a low-level, safe LISP. Put a 3GL front end on top of it for more adoption. That's what Julia people did.

Re: Rosencrantz – A Web DSL for Nim

#23

Earlier quoted context omitted.

Nim is great, and I use it (in production), but I know exactly why it isn't as popular: Nim is fucking huge. Most programmers I know don't even know what a pragma is; Nim uses them extensively. Nim has types, objects, is low level, can be compiled to shared objects (something that didn't come out to Go until 1.5), macros, generics, templates, oh and it compiles to both C and JavaScript (and C++, and Objective C in ca…

What you've just described is a hodgepodge of stuff thrown together. That's a lack of language design with a surplus of features. My readings on older reports for language designs showed the art was figuring out just how much power to include in the language & keeping it all consistent/sensible. One can overdo it. An example of a clean, carefully-thought language that's low-level, consistent, and very powerful is Pre…

Well I don't have a negative view of Nim in general, and I wouldn't describe it as a hodgepodge. I would describe Nim as a language that doesn't hold you back and doesn't save you from yourself. Personally I refrain from using most of the complex stuff, but when I need it I love how it is there for me. For example, the shared objects make it very easy for me to just roll things in Nim then link them to Ruby through the FFI.

Will your average developer need these features? No. But the average developer writes ASP, PHP, or JavaScript. I'd rather be formidable even if it means doing the work.

Re: Rosencrantz – A Web DSL for Nim

#24
post #6

Earlier quoted context omitted.

Yeah, I also had positive experience with nim. I'm not sure why it's so unknown, maybe because it fits in the same niche between rust and go and not backed up by any major company in industry. But I highly recommend trying Nim out!

Nim is great, and I use it (in production), but I know exactly why it isn't as popular: Nim is fucking huge. Most programmers I know don't even know what a pragma is; Nim uses them extensively. Nim has types, objects, is low level, can be compiled to shared objects (something that didn't come out to Go until 1.5), macros, generics, templates, oh and it compiles to both C and JavaScript (and C++, and Objective C in ca…

C++, Rust, D... other languages in this space are also quite huge in complexity.

Re: Rosencrantz – A Web DSL for Nim

#25
post #9
post #7

Sad to see all these [] and () in Nim, which has such a beautiful syntax to start with.

What would you suggest instead? Routes are naturally nested, and overloading [] seemed the best choice

Hi Andrea, as always, I'm very impressed by the diversity of high-quality, useful Nim projects you produce. :)

I agree with the other posters that the multi-line [ ] syntax is not very beautiful or Nim-idiomatic. As @Nycto suggests, nested code blocks would seem more Nim-idiomatic.

Also, I haven't seen anywhere else in Nim stdlib where multi-line [ ] expressions are used. In my mental model of Nim, [ ] is for 4 uses: 1. generics, 2. tuples/subranges, 3. array literals, and 4. array indexing. And none of these scenarios contain nested code blocks inside them.

For nesting of routes I would find nested code blocks most idiomatic. Or, if you find that nested code blocks simply do not work well, the key-value idiom of a table constructor {k:v} seems more idiomatic than [ ]: http://nim-lang.org/docs/manual.html#statements-and-expressi...

If it compiles (I admit I haven't tested it -- this is just off the top of my head), you could perhaps use a syntax something like:

  get {
    path("/api/status"): ok(getStatus()),
    pathChunk("/api/message"): # etc.
  }
Since the order of the (key,value)-pairs is preserved, this would automatically handle the ordered composition `h1 ~ h2`.

Re: Rosencrantz – A Web DSL for Nim

#27
post #25
post #9

Earlier quoted context omitted.

What would you suggest instead? Routes are naturally nested, and overloading [] seemed the best choice

Hi Andrea, as always, I'm very impressed by the diversity of high-quality, useful Nim projects you produce. :) I agree with the other posters that the multi-line [ ] syntax is not very beautiful or Nim-idiomatic. As @Nycto suggests, nested code blocks would seem more Nim-idiomatic. Also, I haven't seen anywhere else in Nim stdlib where multi-line [ ] expressions are used. In my mental model of Nim, [ ] is for 4 uses:…

Hi jboy, thank you! :-)

The problem with the syntax you propose is that it does not compose well.

For instance, in the example you give, `path`, `get` and `ok` are all handlers, but they appear in very different roles syntax-wise. It is not clear to me how one would add one more level, say to parse handlers.

I agree that the [] syntax is not the best-looking in the world, but I need something where I can do the equivalent of `h1[h2]`, where `h1` and `h2` are both handlers.

Templates and blocks would sort of work, but not in the case where both `h1` and `h2` are, say, stored in a variable. I am all for trying to obtain a better syntax, but I would not like to lose composability for that

Re: Rosencrantz – A Web DSL for Nim

#28
post #20
post #19

Earlier quoted context omitted.

The problem with this approach is that it would be difficult to make handlers first-class. What if your post routes are a handler imported from another module? Templates would allow for the syntax you present, but do not combine.

That's not at all the case. Templates can return values. So really, you could think of the templates as syntactic sugar around the existing functions you've got right now. For example, the 'firstOf' template above would be responsible for scanning the AST it's given, taking each node and putting it in to a sequence. Then it instantiates a Handler with that sequence and returns it.

In any case, I do not want to sound too critical. I would be happy to see a lighter syntax for Rosencrantz - I just do not know how to do it while preserving the composability of handlers.

If you have any proof of concept of how it might work, I would be glad to get a PR! :-) Ideally, it would be something that can be layered on top of the existing core, so that one could import "syntax helpers" from a separate module

Re: Rosencrantz – A Web DSL for Nim

#29

Earlier quoted context omitted.

What you've just described is a hodgepodge of stuff thrown together. That's a lack of language design with a surplus of features. My readings on older reports for language designs showed the art was figuring out just how much power to include in the language & keeping it all consistent/sensible. One can overdo it. An example of a clean, carefully-thought language that's low-level, consistent, and very powerful is Pre…

Well I don't have a negative view of Nim in general, and I wouldn't describe it as a hodgepodge. I would describe Nim as a language that doesn't hold you back and doesn't save you from yourself. Personally I refrain from using most of the complex stuff, but when I need it I love how it is there for me. For example, the shared objects make it very easy for me to just roll things in Nim then link them to Ruby through t…

"and I wouldn't describe it as a hodgepodge. I would describe Nim as a language that doesn't hold you back and doesn't save you from yourself."

That's kind of vague. When I say hodgepodge, I mean they threw in all kinds of capabilities into the language without integrating them into a consistent whole. The examples I gave leave no surprises. What you see reading others' code is even expected. You could do about anything in a variant of PreScheme that you could do in Nim given almost any language feature gets ported to a LISP as a library. Except, it's all consistent in its style, syntax, and techniques for doing whatever it does. Nim seems to lack that very-significant property that affects uptake, ease of formal analysis, and maintenance burden.

So, the language is powerful. People are doing neat things with it. Just lacks design traits that have historically been important for programming languages in terms of getting and keeping developers/users.

Post reply on HN