5 ms·
I have used Nim extensively and done a lot of metaprogramming in it. The biggest risk to metaprogramming is that it allows crazy syntax that you have to learn s
by dom96 8y ago
I have used Nim extensively and done a lot of metaprogramming in it. The biggest risk to metaprogramming is that it allows crazy syntax that you have to learn separately. Nim does very well here to enforce limitations which work well in reducing this risk.
Comparing Nim's metaprogramming to Rust's shows what I mean. In Rust you can write macros that act on token streams, so as long as the token stream is valid it can be used. This allows libraries like the typed-html package[1].
In Nim you cannot do this unless you put the HTML in a string literal. This limitation created a syntax that is far more idiomatic, admittedly at the expense of familiarity for users of HTML:
buildHTML():
html():
head():
title: text "My webpage"
body:
p(class="red"): text "Hello World"
In my experience this works quite well, you can see a larger example in our Forum's code which is written using a SPA framework called Karax[2].
Please don't let style insensitivity discourage you from using this wonderful language.
1 - https://docs.rs/typed-html/0.2.0/typed_html/ https://docs.rs/typed-html/0.2.0/typed_html/
2 - https://github.com/nim-lang/nimforum/blob/master/src/frontend/threadlist.nim#L116-L155 https://github.com/nim-lang/nimforum/blob/master/src/fronten...
- karmakaze 8y agoPlease don't let adherence to stlye-insensitivity limit language adoption.
- dom96 8y agoIf it was up to me I would have removed this feature long, but not because it's a problem, only because of people like you who judge programming languages based on what they see at the surface. There are still plenty of people who dislike Python because "significant whitespace, bleh" with no objective reason why they dislike it except "it gets messed up when I copy the code". That's a tooling problem, just like with style insensitivity, it's not hard to search in a style insensitive manner and in fact all tools should allow this mode for convenience.
- karmakaze 8y agoOkay, so what's the regexp for finding all the style insensitive versions of myVariable? Something like m_?[Yy]_?[Vv]_?[Aa]_?[Rr]_?[Ii]_?[Aa]_?[Bb]_?[Ll]_?[Ee] I never want to type a regexp like that just to find all occurrences of a simple var name. Even if a plugin did it for me, it would still be slower and it doesn't help me on the command line.