📎 Webclip
7 tips for writing clean code
The thread lists concrete tips for writing clean code and an additional set of practices to improve overall code quality, with emphasis on readability, structure, and testability. It states that experienced developers quickly spot code smells, and that this skill can be developed through extensive practice. The author also promotes a weekly newsletter focused on .NET and software architecture advice.
Reading notes#
- The author presents 7 tips aimed at writing clean code.
- Merging nested or sequential
ifstatements is suggested to simplify control flow. - Applying the early return principle is recommended to avoid deep nesting and complex branches.
- Replacing magic strings with enums is advised to make code more explicit and safer.
- Replacing magic numbers with constants is recommended to clarify intent and ease maintenance.
- Using custom exceptions is preferred to better express specific error conditions.
- The thread suggests using LINQ to make code more concise.
- The author recommends extracting complex boolean expressions into methods.
- Good developers are described as being able to recognize code smells at a glance.
- The ability to spot code smells is described as a learnable skill.
- The author states that lots of practice is required to develop this skill.
- A bonus list offers 6 more tips focused on improving code quality.
- Writing unit tests is recommended as part of improving code quality.
- The author advises optimizing code primarily for readability.
- Low coupling and high cohesion are highlighted as desirable design traits.
- The “rule of 3” is mentioned as a guideline for handling code duplication.
- Using consistent naming conventions is recommended.
- Functions in the range of 10–20 lines are suggested, with the note that this is not a strict rule.
- The author promotes “The .NET Weekly” newsletter, promising a practical tip on .NET and software architecture every Saturday.
- The thread notes that over 34,000 engineers have joined the newsletter.
- The author invites readers to reflect on whether writing clean code matters to them.
