mage2tv / magento-cache-clean

A faster drop in replacement for bin/magento cache:clean with file watcher
BSD 3-Clause "New" or "Revised" License
531 stars 63 forks source link

Not criticizing, just asking: Why closure? #76

Closed PauloPhagula closed 4 years ago

PauloPhagula commented 4 years ago

Not criticizing, just really curious: Why use closure, for a project that is all around PHP (and Node.js)?

Vinai commented 4 years ago

Good question. There are several reasons.

First, I really enjoy writing Clojure, more than I enjoy PHP or JavaScript. From a language perspective it's far superior because it helps me think about the problems I'm solving and makes me more productive by providing a consistent API and great data structures. Immutability and many higher order functions help keep functions pure and most of the time things "just work".

Second, this project was an experiment to see how maintainable a small but useful code base is without tests thanks to interactive REPL driven development. My answer at the moment is it's okay, but I still prefer to have repeatable tests. Still, I'm surprised how maintainable the code has been to date.

Third, originally I intended to use the utility to experiment with the GraalVM compiler to compile the source to a native binary. One thing I've learned is that it doesn't work as expected with JS source, as it would simply embed the full JS runtime in the binary. I might still choose to extract the functions that use JS interop into a separate namespace and add a Java implementation for those, so I can compile it to a Java program, in addition to node JS. Then I can compile that with GraalVM to a native binary. Because the utility shells out to PHP in order to determine the Magento modules and themes I'll probably won't do that though after all (unless GraalVM get's support for PHP (unlikely)).