DEV Community

Arpit Mohan
Arpit Mohan

Posted on • Originally published at insnippets.com

How dependency injection improves code quality

TL;DR notes from articles I read today.

Benefits of dependency injection

  • It improves code maintainability. Stand-alone classes are easier to fix than complicated and tightly coupled classes.
  • It improves code quality by improving code testability. If it is easy to test code, it will get tested more often which will lead to higher quality codebase.
  • Dependency injection makes code more readable as the classes used are small, to the point, compact and more clearly defined.
  • When you use dependency injection, you get loosely coupled code that is more flexible. Small classes that do one thing can more easily be reassembled and reused, which in turn saves time and money.
  • It leads to a more extendable class structure.
  • It facilitates team development as after defining abstractions, teams working together can write their code using the abstractions, even before implementations are written.

Full post here, 4 mins read


How to continuously profile tens of thousands of production servers

Some lessons & solutions from the Salesforce team that can be useful for other engineers too.

  • Ensure scalability: If writes or data are too voluminous for a single network or storage solution to handle, distribute the load across multiple data centers, coordinating retrieval from a centralized hub for investigating engineers, who can specify which clusters of hosts they may want data from.
  • Design for fault-tolerance: In a crisis where memory and CPU are overwhelmed or network connectivity lost, profiling data can be lost too. Build resilience in your buffering and pass the data to permanent storage, while allowing data to persist in batches.
  • Provide language-agnostic runtime support: If users might be working in different languages, capture and represent profiling and observability data in a way that works regardless of the underlying language. Attach the language as metadata to profiling data points so that users can query by language and ensure data structures for stack traces and metadata are generic enough to support multiple languages and environments.  
  • Allow debugging engineers to access domain-specific contexts to drive their investigations to a speedier resolution. You can do a deep search of traces to match a regular expression, which is particularly useful to developers debugging the issue at hand.

Full post here, 9 mins read


Get these notes directly in your inbox every weekday by signing up for my newsletter, in.snippets().

Top comments (1)

Collapse
 
djnitehawk profile image
Dĵ ΝιΓΞΗΛψΚ

i tend to discourage DI in my team. this video explains why: youtu.be/UfBe_At-TGE