Say it once and say it well [View in browser](=.9Rkxb5eymWGZcBxuQbfbnryKLjw2UsI8kOyCDO1eMd4) Introducing: D-R-Y Hi there, We're bringing you the next instalment of our Clean Code Series to celebrate the launch of our new [PHP](=.c1aX_tQAppm7WaFg1kWpWgt4lyxVlq6qNnNfq0vTJtM), [Python](=.RI3NwvS1j0vfNIUsmBwnaiyeGyZa-hK956GPrwgaxiI), [JS](=.CG2z39DKCHCRRgMmGtEXtT0Q2YfjWOjugEwOVtjeev4), and [Architecture](=.hdFWliu7V0kTdA3HBkyZg-mCeeBLaFvDFqejhjFL_oQ) coding titles.
Today we're talking about the DRY principle, or Don't Repeat Yourself. Let's say you're building a web application that needs to perform calculations based on user input. You might be tempted to copy and paste the same calculation code throughout your application, wherever it's needed. But what happens if you need to modify the calculation logic? You'll need to find every instance of the calculation code and update it manually, which can be time-consuming and error-prone. Please avoid this. The invention of the computer allowed us fleshy humans to stop doing repetitive, manual calculations and hand it off to a machine. If you still find yourself pasting the same code in multiple spots around your app, you have let us all down. As a beginning developer, there are a few things you can do to apply the DRY principle: - Look for duplicated code: Scan your codebase for repeated code blocks or patterns. If you see the same code repeated in multiple places, it's a good indication that you can extract that code into a reusable function or module.
- Use functions and modules: Functions and modules are great tools for avoiding code duplication. They allow you to encapsulate code that performs a specific task, and then call that code from multiple places in your application.
- Refactor when necessary: As you work on your code, you may find that you've duplicated code without realizing it. When you do find duplicated code, take the time to refactor it into a reusable function or module. You might find it easy to remember if you follow this helpful mantra: "Don't repeat yourself. Don't repeat yourself. Don't repeat yourself. Don't repeat yourself. Don't repeat yourself." To learn more about this principle, as well as methods and strategies for writing clean code, check out our new titles on: =.E_vJmID4LwRfMyZ_RYKVhKTAWFdo2-c-hnSVzzcqv5k [PHP](=._kh74VeQ21LjSzH5dmc-uJJ7Oxe-DiAayfQmAJ46odE), [Python](=.c3IUQAv8xNl_nxjCUAYKgjOe8FIAQ7bVvcD6wuPKZ74), [JS](=.phd20LGYWinndsUwvBGc3oYB3pjK0sX2ss0wYVaFE_Y), and [Architecture](=.rdbBzjjd1FtHq3D8QcK12foyvu74tloEk7Hg8d6yI8g). Happy Learning,
The SitePoint Team The Clean Code Series [Clean Code in Python](=.zgxl-quznNP7kM-7zlulRiOuju400-WSZKRxAlkt6KA) Clean Code in Python, Second Edition will help you understand the problems that arise due to inefficient code formatting, and more importantly, demonstrate how to correct them. [Read Now](=.uhsNW07O8u6FgkQm2Be1iPm0Rr9KKHUHZ2pxthcbZGQ) [Clean Code in PHP](=.5lxweaGbSg9drOw3yDWpId4deEC1t-39Yh5RjppGmx0) Clean Code in PHP is a must-have beginner-friendly guide for PHP developers. It will show you how to write human-friendly PHP code which will fuel your PHP career growth and give you an edge over the pool of other developers. [Read Now](=.tXHgg_4oGl_dnTiSdq8sP94cJ1nBljJzDz9mjze2SyE) [Solutions Architectâs Handbook](=.rXPEDJWREWFDobVhAND9xDyKr2-kB6giXpIejoOU3WM) Create robust, scalable, highly available, and fault-tolerant solutions by learning different aspects of solution architecture and next-generation architecture design in the cloud environment. [Read Now](=.gBVKCkvxklXRkHzrP1btFcLldJ_BjQP4RhJ_9xvt5xM) [Clean Code in JavaScript](=.5kdWrduADPw8QIPMaF7GHuYz0Y9Lo_2T_pqpSUP0A6c) This book presents principles, patterns, anti-patterns, and practices supported by use cases and directions for writing clean JavaScript code. It helps you refactor your legacy codebase in JavaScript and modernize your web apps. [Read Now](=.ff-5zP7TR_p8fhcZdErT_UuzYtA5IDJvlkM10yaeTM0) SitePoint 10-20 Gwynne Street, Cremorne
Australia [discord](=.vhD23Bs9yBfMHobsgJGA-MhDCaKMhwdCx05fjRr8Nyc) [twitter](=.QHFNJFxc7-kJmqeHJJzDAWklpPvrrciH6TAna7z_BBc) [facebook](=.HtsaHK0If7vFMtwvNM_OmRsU1bTdUopKxDfJvBxlTj0) You received this email because you signed up on our website or made purchase from us. [Unsubscribe](=.ff0AFg6RRpQcPKYO9LbugO9CqP2uCMtkgMMK_tQ8VoE)