refactoring

  • webpack resolve.alias removes the ../../..

    A deep component importing a helper writes ../../../lib/money, and the path breaks the moment the file moves — which makes reorganising a tree a mechanical exercise in fixing…

  • Extracting a service without a rewrite

    The reporting code had one caller and a six-hour test run. Finding the seam, dealing with the shared schema honestly, and routing traffic gradually rather than switching.

  • Collections: pipe and tap keep a chain readable

    A collection chain reads well until it needs one step that is not a collection method — a log line, a total computed from the whole set —…

  • preg_replace_callback_array for several patterns at once

    Applying several regular expressions with different callbacks meant chaining preg_replace_callback() calls, each re-scanning the whole subject — three patterns, three passes. Patterns are applied in the order given…

  • Debounce a function with ES6

  • Uniform variable syntax changed what $$a means

    PHP 7 made variable-variable expressions evaluate consistently left to right. That is an improvement and it silently changed the meaning of expressions that had been working for a…

  • Null coalescing chains, and where null still gets through

    ?? chains left to right and returns the first operand that is not null, which reads like a safe navigation operator and is not one. It only guards…

  • The N+1 queries you did not write

    1,400 queries on a page showing 40 rows. Eager loading, the difference between with() and load(), and the accessor that no eager load can fix.

  • Deep clone an object in JavaScript

  • The strangler pattern needs a router in front of it

    Replacing a system incrementally requires something able to send some requests to the old implementation and some to the new. Without it, the migration is all-or-nothing however carefully…