Hacker News new | past | comments | ask | show | jobs | submit login

I guess this is just a limitation of JS the language showing itself. Other languages have actual aspect-oriented support where before/after/around methods are very clear name-wise and semantics-wise (if not always so clear without tooling support what happens if you come across a 'mount()' call). Maybe it's time for a new JS framework! /s



Which languages in common industry use in 2022 have language-integrated aspect-oriented programming support?


Fair point. I hinted with the idea of a new framework that you may be able to bolt something acceptable on top of JS (I'm sure it's been done already in the past with some framework) especially if you just want the before/after/around advice features of AOP without other stuff. Or perhaps go into custom syntax transpiled to JS/TS-then-JS since no one seems to mind heavy build processes these days. For the most common industry use, I'd have to say it's still Java's Spring AOP/AspectJ. Maybe it's not language-integrated, but it's pretty close.

For an uncommon use example of what could be possible:

    (defmethod react.component:mount :after ((self counter)) ...) ; instead of componentDidMount
    (defmethod react.component:update :around ((self counter)) ...) ; instead of shouldComponentUpdate
    (defmethod react.component:unmount :before ((self counter)) ...) ; instead of componentWillUnmount
    ; (the react.component namespace qualifier could be whatever else and not necessarily typed out)
However closely you integrate it with the language, having that machinery generally available seems better for naming and for providing new lifecycle functionality, without everyone having to reinvent the wheel and provide it in different incompatible ways. But it's clearly not a big issue.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: