Since Javascript is an interpreted language, entire functions can be changed during runtime. I have recently been contemplating a framework that would allow for dynamic code changes (such as UI plugins) to take effect without having to reload the page, while still providing enough information to undo the change if desired.

I have begun to test this concept with small examples with success, but have not had the chance to test the idea for anything useful.

Is there any common adverse side effects to changing code during runtime or is it considered bad practice?


Self-modifying code has been almost universally viewed as an invention of the devil almost since the beginning of computing time.

The fundamental issue is this: When the code can modify itself at runtime, you no longer have any idea what code is really running. Is it the code in the listing, or is it something that was beamed down from an extraterrestrial hacker on the smaller moon of Rigel 7?

Plugins are useful, but you want to be very careful what you do and what you allow plugins to do.

  • 1
    I wouldn't entirely dismiss or view self modifying code quite so harshly. I believe it is often critical for such things as mock objects and meta programming DSL's and so on and so forth. – JustinC Jun 4 '13 at 20:25

What you're probably referring to is more dynamic language features. As such, that's how you'll find more information about benefits and drawbacks.

In general, this has been well-explored. The primary adverse side effect you'll probably have when changing code at runtime is that it explodes the complexity of debugging by a nontrivial factor, because in order to solve problems, you generally have to figure out where they're coming from. This can be anywhere from relatively "easy" (jQuery is a decent example) to really really hard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.