DEV Community

Nwanguma Victor
Nwanguma Victor

Posted on

#1 Tip for Readable Code Across Teams and Personal Projects

Have you ever written code and months later you come back to that same code and be like "what the heck was I thinking".

💡 Tip: You can easily put links referencing the documentation, site or stack overflow question from where you got that cool and fancy one-liner, solution or concept.

It helps if you think someone else would have a hard time understanding your code

// https://laravel.com/docs/9.x/collections#method-collapse
// https://stackoverflow.com/questions/62872479/laravel-incorrect-json-response-structure-when-using-unique

$collection = collect([
    $abc,
    $validated['abc']
])->collapse()->unique()->values();
Enter fullscreen mode Exit fullscreen mode

Advantages of this approach

  • Team members can easily understand what's going on in the code directly from the source or from other examples.
  • It helps Junior developers understand the codebase better.
  • It's easy to adopt into any team or project.
  • Easy adoption ensures consistent comments across teams.

Top comments (0)