Sean Kanaley wrote on 08/04/2015 12:04 PM:
" I cannot think of any good uses for eval in Racket."
Any time the mental time spent using eval (or defmacro) is less than
that of figuring out how to not use eval or defmacro by using
let-parameterize-syntax-splicing-local-transformer-binding-apply-values instead,
which for the average programmer is probably always.
I think maintainability is relevant here.
Just for the list: maintainability is a constant concern for most
software engineering activity, for very practical, nonreligious,
reasons. Maintainability is not just about whether the next programmer
to come along will be able to read the code. It's about how easily and
effectively you and your team can evolve the system over time, whether
you can actually ever make a complex thing viable, whether and how often
you get into debugging nightmares or failures, etc. Unless you're able
to IPO or job-hop very early in a system lifecycle (and are a bad
person), developing with maintainability as a consideration should be
very important to you, for very practical reasons. That doesn't mean
maintainability doesn't get traded off appropriately at times, but it
should be a conscious and informed decision.
Programming in perfect Racket (or any language) is like finding the
optimal solution to the traveling salesman, or finding a large prime
with 100% certainty. You are spending disproportionate efforts for the
~same result.
Very little code is purist-perfect, and that's OK.
You might be able to find an academic purist who'd say, "don't use eval,
because blah blah blah denotational semantics blah blah blah my
dissertation blah blah blah". But I think you'll have an easier time
finding practical expert practitioners who'd tell a newbie, "don't use
eval, because it's usually a clusterfudge, for no good reason."
If asked about a particular use of eval, a good practical expert
practitioner should give thoughtful and nuanced consideration, not cling
to "don't use eval" like an unthinking devotee. But for broadcasting
general advice to newbies/students, I think the default practice of
saying "don't use eval" is appropriate. Even better is to say, "for the
love of all that is good, textbook people, stop making newbies think
that eval is in their toolkit, when they don't yet even know how to use
the other tools."
(define (confirmation target)
(eval '(printf "Are you sure you wish to nuke ~a?" target) namespace)
...)
To a purist, the above code is horrifying.
(Excepting the horrifying application domain.) That example does show
eval being used for no good reason. Though usually the needless uses of
eval are much more dangerous, and/or expensive/encumbering to maintain.
Neil V.
--
You received this message because you are subscribed to the Google Groups "Racket
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.