We have now tooled up to do YouTube.
I’m glad you discussed Athena in this one. I glanced at Athena in the past, but was turned off by the multitude of annotations. It seemed so foreign to what I’ve seen in other frameworks. Hearing some of the pros to this approach was enlightening.
I use annotations a lot (in the languages that support them: Java, C#, Crystal) as it simplifies configuration and creates less code.
I was in a similar boat. I am not as use to annotations but have used them in Java. I really enjoyed the interview because I think it brings a good perspective to Crystal even I don’t use it. But I have been thinking of hot to use it more.
Glad to hear , I hope it inspired you to give it another look .
It definitely takes a different, non Ruby inspired approach, especially if you never worked any languages that make use of them.
I think there is a lot of merit in them tho. The most impactful benefit of them that I touched on in the interview was that they are shard agnostic. In the end you’re just working with types, methods, and instance variables. You can think of it as just applying metadata to standard Crystal concepts as opposed to each shard/framework implementing their own custom macro DSL specific to each project. That’s not to say you can’t do both.
As I also mentioned, another benefit is that the features I can provide from the framework’s point of view can only improve as macros and annotations mature within the language. There is some exciting stuff on the horizon when Specify annotation targets · Issue #8148 · crystal-lang/crystal · GitHub, Add `ASTNode.warning` macro method · Issue #9246 · crystal-lang/crystal · GitHub and especially [RFC] Macro Defs - Methods in Macro land · Issue #8835 · crystal-lang/crystal · GitHub are resolved/implemented.
There are definitely places where they can work well, but as with any language feature it’s knowing what your options are, and using the right tool for the job. Annotations excel for just wanting to store data tied to a specific thing that you can later read and use in a macro.
I wrote Utilizing Macros & Annotations in a Web Framework - DEV Community a while ago, probably could use an update but I imagine the information there is still valid (even the syntax isn’t). I think I’ll write a new article related to some of the patterns I learned in the past year while working on Athena that have been working quite well for me.
I use annotations a lot (in the languages that support them: Java, C#,
Crystal) as it simplifies configuration and creates less code.
also, rust attributes are annotations to me: https://doc.rust-lang.org/reference/attributes.html