Live data from Hacker News

Ask HN: What metaprogrammable language do you/would like to use?

news.ycombinator.com

61–70 of 76 posts

Re: Ask HN: What metaprogrammable language do you/would like to use?

#61
post #42

JavaScript. It is awesome.

Not sure if it's sarcasm. True, JavaScript is fun to meta-program. But it's hell to debug.

You never know about sarcasm. But I just wanted to give a shoutout to good old JavaScript as it lends itself beautifully to metaprogramming and it is actually widely used unlike some of the more academic languages mentioned here.

Re: Ask HN: What metaprogrammable language do you/would like to use?

#62

> Of all the kitchen-sink features that Nim has, I can't accept camelCased == under_scored names otherwise it could have been first. Just to clarify for the general public (because this is often a source of confusion and misunderstandings): first letters are case-sensitive in Nim, so you can do `var car: Car` (where `car` is a name of the variable, and `Car` is a type). When it comes to style-insensitivity, I also th…

I don't see how this is required for one drop and if that's the use case, it sho_uLd only be used there and not everywhere. It makes it harder for tooling and for searching for all references. Inconvenient, like spaces in filenames.

Re: Ask HN: What metaprogrammable language do you/would like to use?

#63
post #56

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…

Please don't let adherence to stlye-insensitivity limit language adoption.

Re: Ask HN: What metaprogrammable language do you/would like to use?

#64

> Ruby is notably absent as I use it and am looking for something better/different what issues do you have with ruby? it's the de-facto standard for meta-programming I often use things like `define_method`, `constants`, `method_missing`, etc in select places. last fun thing I did was adding `let` and `it` to rails's tests.

Every large, long -lived Ruby app I've worked on eventually needs more performance, better concurrency, and would benefit from static typing. It's great that each company got to the point of 'a problem you want to have'. I'm just looking for the best of both worlds: good to start, good to scale.

Re: Ask HN: What metaprogrammable language do you/would like to use?

#65
post #56

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…

Please don't let adherence to stlye-insensitivity limit language adoption.

If 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.

Re: Ask HN: What metaprogrammable language do you/would like to use?

#67
I use Red (full disclosure, I'm on the team), and have used Rebol (Red's direct ancestor) since 2001. When I find something that works, I stick with it, though I also keep an eye out for new things.

Red's heritage comes from Lisp, Forth, and Logo. It's homoiconic and metacircular (it is its own meta language). Where Rebol was strictly interpreted, Red can also be compiled, and has hygienic macros. But you don't really need them. They're nice for moving things to compile time, but Red puts a twist on Lisp's sexpr model that obviates the "need" for them in most cases. Technically, you can say Red uses an fexpr model, but a more human-friendly way to say it is that "Everything is data until it is evaluated.", and you have a lot of control over when evaluation occurs.

For interop, Red has a system-level dialect called Red/System. It's a C level language and is a dialect of Red. That is, Red is high level and is used to define the Red/System dialect, which is used to implement Red. It's the circle of life. :^) You can also compile Red as a library and call into it via an API, so you can use it as an embedded language, or doing things like the Excel example in this blog entry about Red's macros: https://www.red-lang.org/2017/03/062-libred-and-macros.html which also mentions one of the easiest ways to preprocess input, with the `system/lexer/pre-load` feature.

ASTs are mentioned in a few comments, so I should add that while you can certainly do that with Red, it's another thing that can often be avoided entirely. With other langs and tools, you almost have to take that approach, to make it manageable. With Red, there is a function called `parse` which consumes input and supports BNF-like rules to process it. `Parse` is a Red dialect, and the rules are just data it interprets. Rather than building ASTs (though there are some cool examples, and tree-rewriting systems out there), just interpret the input directly.

If it sounds like I'm against metaprogramming, while being on a team creating a language that supports it deeply, that's not the case. Metaprogramming is a great tool for thinking, but it can also make things much harder to debug and maintain. For real work, use what makes your intent clear, and avoids as much complexity as possible.

Re: Ask HN: What metaprogrammable language do you/would like to use?

#68

Considering only production code here. Do use: Common Lisp, Racket, Python, Ruby Would like to use: Julia, Rust, Elixir I metaprogram when I see I have already built a mini-language/pattern in my code. Even when writing Lisp, I begin with simple code without extending the language, and only when I have written a bit do I consider looking for patterns.

Out of curiosity, why do you have Python on your list? Python doesn’t really support metaprogramming? I’ve written my fair share of Python but don’t remember ever coming across anything meta in the language. Even if it has some passing implementation, it definitely doesn’t have it in the way Lisp/Julia/Rust/etc have it.

> it definitely doesn’t have it in the way Lisp/Julia/Rust/etc have it.

Yes, but then again, Rust, Julia, and Lisp are _high_ standards of metaprogramming. Python's approach to metaprogramming, like most of its other parts, is simple and concise. For simple tasks that are repeated often, Python sometimes provides easy ways to abstract the how and show only the what. While Python does have metaclasses — which, unfortunately or otherwise, I've never needed to write — I've sometimes found myself reaching for simpler tools like decorators, magic dunder methods, even iterators and generators. And, of course, there's always the ability to generate Python AST, or have something generate it for you.

Examples:

1. the new-in-3.7 feature: dataclasses[0];

2. the library that inspired it: attrs[1];

3. the (de)serialisation library with a strikingly simple design: marshmallow[2];

4. the leaky-abstraction of SQL that makes it somewhat composable: sqlalchemy[3];

5. Google's python bindings for Protocol Buffers[4]; and, of course

6. the lisp-in-Python: Hy[5];

----

[0]: https://www.python.org/dev/peps/pep-0557/

[1]: http://www.attrs.org/

[2]: https://marshmallow.readthedocs.io/en/3.0/_modules/marshmall...

[3]: https://docs.sqlalchemy.org/en/13/orm/extensions/declarative...

[4]: https://developers.google.com/protocol-buffers/docs/pythontu...

[5]: http://docs.hylang.org/en/stable/language/internals.html

Re: Ask HN: What metaprogrammable language do you/would like to use?

#69
post #55

OCaml has some metaprogramming facilities through the ppx system. It wouldn't be my first choice for metaprogramming, but it's there if you just want to know the full map of how different languages do it. I have found the ppx system a little bit underdocumented and challenging to use, but it can be very powerful. OCaml fits all of your other requirements.

I've run into OCaml before but haven't taken the time to get into it. If I were to, I think I might look at F# but I have no idea if the metaprogramming is the same.

Re: Ask HN: What metaprogrammable language do you/would like to use?

#70
post #48

It depends a bit what you mean, but Groovy is quite interesting from a meta-programming point of view. Much of the syntax can be completely reprogrammed at run time through an object's 'metaClass', and you can write AST transformations that deeply rearrange the code at compile time. Although it is certainly not as pure as the Lisp-like languages, it can be an incredibly fast and easy way to create a DSL to solve your…

I never thought of Groovy for metaprogramming but it's used to make DSLs so it makes sense. My only run in has been with Gradle which is so slow and/or a memory hog so didn't leave a good impression on me.
Post reply on HN