1. 56
  1. 8

    I would be nice to see a comparison between Comby and Coccinelle from the point of view of the users (the “patch writer”).

    For example, it seems that it would take more to create a patch using Comby rather than using Coccinelle. The syntax of Comby has the obvious advantage of being quite language-agnostic, but it requires the users to type out the whole set of code lines that they want to modify. The semantic patch language used by Coccinelle is instead an extension of the unified patch format. For the users that means that they just need to annotate an existing and valid patch created by another tool, rather than typing out code.

    Another topic: context. I haven’t found in the documentation whether there is any support for “context” or if the context has to be programmatically checked. In other words: how do I write a patch that only applies to instructions that happen to be after or before other instructions? Do I need to match something in the surrounding code and then use a where rule?

    1. 3

      Belated reply (found this post a bit late): Coccinelle is a great tool, and I’d also be interested in a comparison from the pov of users. There’s recent work on extending Coccinelle to Java. My impression is that it takes more effort to write a fully-fledged grammar for different languages depending on their semantic properties, and that can introduce more complexity in the “patch language”, if we take Coccinelle as an analog.

      Re context: it’s difficult to say where the expressivity overlaps here, because it depends a lot on the rewrite (i.e., what syntactic or semantic context you need to achieve a rewrite, which also bears on the syntax/semantics of the language). Comby doesn’t use any semantic information right now, but syntactic patterns can often serve as proxy for semantic properties. For example, in Go we can assume some of the structure following the func keyword, match on the arguments or or statements in the body syntactically, and learn something about static properties like variable uses of the function. As you intuited, where rules exist in part to refine match/rewrite behavior inside of surrounding syntactic code/context, like nested terms.

      At the end of the day, I look at program transformation tools as lying on a spectrum, from something rudimentary like sed up to extremely sophisticated and language specific-tools like Clang. These tools make different design choices that impose varying levels of effort, (language) generality, and power/expressivity. I.e., there is always going to be a need for these different flavors of tooling depending on the task. In my research I worked a lot with modifying small program fragments for various applications, and I wanted something minimally declarative, language-general, and sensitive to certain syntactic structures. Existing solutions were a bit limiting for those needs, and now there’s this tool. Thanks for your thoughts and I’m happy to share more. In the meantime, let’s keep our fingers crossed for future comparative studies of user experiences with program transformation tools :)

    2. 4

      I saw a talk for this at Strange Loop, and I have to say it is delicious. I can’t wait to show it to my team and put it into use next week. Maybe I’ll write my first emacs minor mode to employ it.

      1. 4

        Gema is an incredibly powerful pattern matching language that seems along the same lines.

        1. 2

          Have you used it? If so, what for?

          1. 1

            I’ve only played around it without it for code golf, but from the little I’ve seen it’s impressive and far superior to tools like awk/sed/etc, which are normally used for the same kinds of tasks.

            EDIT: This old article is probably a good explanation of its power, and how it compares with sed/awk/etc:


        2. 3

          It looks cool, but… it’s just a macro system, and one I could definitely imagine creating far more trouble with its inevitable idiosyncrasies than it’s worth. Might be useful, but color me dubious by default.

          1. 2

            I’ve read through it and it’s unclear what problem this tool is solving. As I understand it replaces macros with some values. But when is this useful? What problem does this solve that’s not already solved by, say, Go or Python built-in features?

            1. 2

              Here’s the Strange Loop video on it, it addresses your questions. He actually presents an example of the AST manipulation it would take in Go to accomplish the same thing he does with Comby.

            2. 1

              Is it possible to match something like

              %{:a => a_val, :b => b_val}

              And change it to:

              %{a: a_val, b: b_val}

              With this tool? Because I haven’t succeeded with such simple task.

                1. 1

                  Hi there, I’m the author of this tool. Belated reply (unfortunately I found this post a little late). For your example, it depends what assumptions can be made. But in the simplest case, you can:

                  Match: ::[x] => :[y]_val

                  Rewrite: :[x]: :[y]_val

                  which repeats over both matching instances (https://bit.ly/30l5yfA). I suspect that it makes more sense to perform this within %{...}, in which case you want to repeat over the body. So, the way this is possible is by matching on the body of %{...} at the toplevel, and then use a rewrite rule to rewrite each instance inside: https://bit.ly/30gfoj1.

                  Thanks for you sharing your example, always interested in learning about the sorts of changes that come to mind. If you have more thoughts or questions, feel free to reach out to me on the tool’s Gitter chat.

                  1. 1

                    The point is that the _val isn’t common suffix like in an example, it is more like example, where a_val can be anything (including another map). This makes everything a little more problematic. While pattern ::[] => and rewrite :[]: will do, it was strange for me that ::[x] => :[y.] do not treat commas as punctuation.