Live data from Hacker News

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

news.ycombinator.com

41–50 of 76 posts

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

#43

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

[deleted]

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

#45
post #4
post #2

If you are asking about learning metaprogramming as a paradigm I would rather suggest Racket. Lisps are famous for their metaprogramming capabilities and you have Clojure at the top of your list but writing macros are way easier in Racket than in Clojure. This is primarily because Racket IDE provides good debugging and tracing tools. Clojure is notorious for its cryptic error messages. This certainly doesn't help whi…

But Racket doesn't have macros a la Common Lisp, which are the most powerful way to achieve metaprogramming in the Lisp family.

Racket has syntax-case[1], which is hygienic, but allows you to break hygiene if you need to.

Racket also supports defmacro[2] like Common Lisp, and it's actually implemented using syntax-case.

I would argue that syntax-case is at least as powerful as defmacro.

[1] https://docs.racket-lang.org/guide/syntax-case.html

[2] https://docs.racket-lang.org/compatibility/defmacro.html

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

#46
Python has way more metaprogramming capabilities than people think.

Of course you can intercept pretty much anything with __dunder__methods (attribute missing, method access, instantiation, etc), you have full instrospection of pretty much anything (functions, objects, modules, call stacks...) and you also have monkey patching, decorators, metaclasses, bytecode injection...

But while we are far away from Lisp based languages, import hooks give you access to the ast of any module, and allow to use your own parser, before the result is loaded, to decide what to return. Which means you can pretty much make your own syntax and import it like a regular module.

However, the reason those tools are not very well known is that the community regards magic as dangerous as it is powerful, and everybody agrees on using it sparingly.

Hence the only popular libs that use a lot of magic are ORM (lot of metaclasses, dunders, etc) and test libs (monkey patching, bytecode injection, ast parsing), but not a lot more. I don't know of any popular lib that actually uses the import hooks to create a DSL.

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

#47

Earlier quoted context omitted.

You haven't seen any Lisp yet, have you? Compile and run-time MP and quasiquoting are basic features; I'd argue that a language without these doesn't even qualify as "supporting metaprogramming".

Sure, I'm intimately familiar with the Lisp family of languages. It lacks features that I prefer in a modern meta-programming language, in particular an expressive typing system with type inference, and a platform / eco-system like the JVM.

I stand corrected, and I agree with you here on both accounts - I'd love if CL in particular had a better type system standardized (current one sits in a kind of uncanny valley) and a better ecosystem. CL implementations are solid, but the mindshare unfortunately isn't there anymore.

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

#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 problems in a very idiomatic way.

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

#49

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.

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

#50
> 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 thought this would be a problem when I discovered Nim, but now—2 years later—there was not even one situation where that would cause a problem. (And if you use different styles of the same name to mean different things in other languages: this will bite you sooner or later)

Nim's standard library is written uniformly in camelCase style, which is what I also accepted for my code (even though I come from snake_cased Python).

So why this even exists? To make easier to use libraries written (in another language, e.g. C) in another style, while keeping the uniform style in your code. Basically, this feature makes it easier to use just one style consistently.

To conclude:

If this is the only (or just a major) thing that keeps you from using Nim: I would suggest you to reconsider and give it a chance.

Post reply on HN