jackfirth / resyntax

A Racket refactoring engine
Apache License 2.0
51 stars 10 forks source link

De Morgan rewrites frequently make code more confusing #187

Closed jackfirth closed 1 year ago

jackfirth commented 1 year ago

Resyntax currently rewrites this code:

(define (different-slots? item-key next-item-key)
  (or (not (= (quotient item-key 100)
              (quotient next-item-key 100)))
      (not (= (sgn item-key)

To this:

(define (different-slots? item-key next-item-key)
  (not (and (= (quotient item-key 100)
               (quotient next-item-key 100)) (= (sgn item-key)
                                                (sgn next-item-key)))))

This is equivalent and technically smaller, but it's less clear what's going on. The De Morgan's laws rewrites in Resyntax frequently have this problem: they make boolean expressions significantly harder to understand and only marginally smaller. They're not worth keeping around and should be removed.

Metaxal commented 1 year ago

Just an idea: how about proposing such a rewrite if the code size difference is large enough?

On Sun, 26 Mar 2023, 08:05 Jack Firth, @.***> wrote:

Closed #187 https://github.com/jackfirth/resyntax/issues/187 as completed via #201 https://github.com/jackfirth/resyntax/pull/201.

— Reply to this email directly, view it on GitHub https://github.com/jackfirth/resyntax/issues/187#event-8846676780, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMU2HEJUOVYIC6ULMFXIIDW57TCDANCNFSM6AAAAAAVTAXNXQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Metaxal commented 1 year ago

Using a command-line-tunable parameter for example

On Sun, 26 Mar 2023, 09:57 Laurent, @.***> wrote:

Just an idea: how about proposing such a rewrite if the code size difference is large enough?

On Sun, 26 Mar 2023, 08:05 Jack Firth, @.***> wrote:

Closed #187 https://github.com/jackfirth/resyntax/issues/187 as completed via #201 https://github.com/jackfirth/resyntax/pull/201.

— Reply to this email directly, view it on GitHub https://github.com/jackfirth/resyntax/issues/187#event-8846676780, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMU2HEJUOVYIC6ULMFXIIDW57TCDANCNFSM6AAAAAAVTAXNXQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

jackfirth commented 1 year ago

That might be nice. I'd prefer to see some examples of real code that it would help with first.

Metaxal commented 1 year ago

Of course. Just something to keep in mind, perhaps.

On Sun, 26 Mar 2023, 10:11 Jack Firth, @.***> wrote:

That might be nice. I'd prefer to see some examples of real code that it would help with first.

— Reply to this email directly, view it on GitHub https://github.com/jackfirth/resyntax/issues/187#issuecomment-1484039165, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMU2HCQYKVYX7OWAREZDK3W6AB2TANCNFSM6AAAAAAVTAXNXQ . You are receiving this because you commented.Message ID: @.***>