jackfirth / resyntax

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

Don't suggest function `define` shorthand in class bodies #186

Closed jackfirth closed 11 months ago

jackfirth commented 1 year ago

Resyntax currently rewrites this:

(define f (lambda (x) (+ x 42)))

To this:

(define (f x) (+ x 42))

In this discussion, it was pointed out that this can make code more confusing when the define form in question is inside the body of a class. Within a class, define creates a field and define/public and related class-specific forms create methods. A definition like (define f (lambda (x) (+ x 42))) in such a context is intended to be an instance-specific field (possibly a callback, especially in GUI code) but rewriting that to (define (f x) (+ x 42)) obscures whether it's instance-specific state or just a private method. Resyntax should avoid performing this rewrite within class bodies.