[swift-evolution] Custom annotation processors?

Talin viridia at gmail.com
Thu Jan 14 00:21:26 CST 2016


You can say that about any metaprogramming feature, including operator
overloading, parametric polymorphism, automated code generation, or any
other form of programmable syntax - all of these features have to be used
with care because they essentially create new dialects of the language. As
for using annotations to drive dependency injection, this is used by
thousands of Google engineers on a daily basis and people generally find it
quite powerful and helpful. I actually think it is syntactically less
dangerous overall than the ability to invent new infix operators, because
at least you have an imported name that you can search for.

My own personal interest is in metaprogramming, that is "code that operates
on code", whether it be by reflection, template instantiation, or automated
code generation. In Java, this is sometimes done through reflection, and
sometimes via annotation processors, which are plugins to the Java compiler
that can examine the annotations and generate additional helper classes. By
contrast, in my own experimental language, the output of the compiler is
stored in a generic introspectable binary file format, similar to protocol
buffers, which can easily be taken apart and re-assembled by any
programming language (C, Python, Swift, Go, etc), allowing any sort of
post-processing on a compiled module.


On Wed, Jan 13, 2016 at 10:01 PM, Yang Wu <pinxue at gmail.com> wrote:

> -1 on user-created annotation.
>
> I wrote Java since 90s and hate user-created annotation. Annotation is
> indeed a backdoor in syntax system, it makes source code totally
> un-understandable before you read reference of the annotation.
>
> 在 2016年1月14日,上午9:24,Talin via swift-evolution <swift-evolution at swift.org>
> 写道:
>
> As a former Googler, I've spent a lot of years writing Java code that uses
> dependency injection, and this relies heavily on the ability to have custom
> annotations/attributes in the language - particularly, user-defined
> attributes on function parameters - and to generate additional code at
> compile time via annotation processors. Although dependency injection does
> have it's detractors, it's getting better (current best of breed is
> http://google.github.io/dagger/), and it solves an amazing array of
> problems, including the ability for asynchronous programming to disappear
> into the underlying framework - you just write synchronous code and the
> framework handles the rest (no more futures!).
>
> Now, you can of course do dependency injection without custom attribute
> support in the language, but it's much more cumbersome. The user-defined
> attributes allow you to specify, in a simple declarative way, the runtime
> dependencies between various classes. Without it you have to build up those
> dependencies in code, using some sort of fluent interface or builder
> pattern.
>
> So my question is, is there any plan for Swift to support user-created
> annotations, and annotation processing compilation stages?
>
> --
> -- Talin
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
>


-- 
-- Talin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160113/0d842119/attachment.html>


More information about the swift-evolution mailing list