It's time to ditch Medium for good! 🌈⚡️

Introducing Devblog by Hashnode. Blog on your domain for FREE. Highly customizable and optimized for developers.

Learn more


If it can be split, split!

Reusability of bits of code is an important reason for splitting. In "good code practice", a single method doesn't have to make sense at all. It gets meaning by being called, thus getting a cognitive/explanatory environment.

If your enormous code block makes sense because of what you do in sequence, the same sense will come from calling the separate (explanatory named) methods that you created (probably also in sequence).

Passing data as arguments follows the black box principle, where a function always has input, processing, and output (which is just processed input). By using this practice, you will never have dependency and thus no scoping problems, because there's always just the input to work with.

That being said, when coding javascript I regularly use variables in the global scope, something that is similar to (or could be called) instance fields.

Reply to this…

(4 answers) Take me to the question