oakes / odoyle-rules

A rules engine for Clojure(Script)
The Unlicense
530 stars 20 forks source link

Formatting help for rules? #10

Closed kkinnear closed 3 years ago

kkinnear commented 3 years ago

The backstory: I was giving a brief presentation to a Meetup where I was looking for opinions on how to implement a new capability in zprint. One of the folks mentioned odoyle-rules as a possibility. So I watched the video, and indeed, odoyle-rules might be a reasonable approach. I haven't quite wrapped my head around how I would approach that, but I did notice that the way you formatted the rules in the video was different than how you format them in source files.

The new capability in zprint that I am working on (and which is not yet released) is designed to allow one to do creative and unusual things with formatting -- like formatting rules. So I looked around for a file with a lot of odoyle-rules in it, and found session.cljc in paravim. Building a formatter for rules and testing it with session.cljc was a great experience, because it has a lot of real-world oddities in it that I would not have considered on my own. Anyway, having built this rule formatting capability, I thought I'd share it with you to see if you had any feedback on it. Is it interesting? Would you use it? Would you want the rules formatted some different way?

I have attached a formatted version of session.cljc to this issue (I had to call it session.txt to get GitHub to let me upload it). It is formatted for 80 columns, but of course that is trivially configureble. It uses default zprint formatting for everything except the rules, which may or may not be what you would want to use if you liked the rule formatting. zprint is almost ridiculously configurable, so if you like the rules it is probable that anything you don't like in the code could be configured differently so that it was more to your taste.

Anyway, I'm just curious if you think this is interesting. Thanks for listening.

oakes commented 3 years ago

I wouldn't use a code formatter personally but i do like the way it spaces the [id attribute value] columns in the :what block. I'm normally too lazy to manually do that. I think the indentation of those tuples looks odd but i suppose it makes the sections pop out a bit more. If that was all done in an automated way that's pretty cool.

kkinnear commented 3 years ago

Thanks for the feedback! I will be releasing the rules formatting as an experimental feature in zprint 1.1.2, which I am in the later stages of wrapping up. It will be accessible as a "style" using the options map {:style :odr} for anyone that is willing to use zprint. Thanks again for giving the file a look.