Home New Trending Search
About Privacy Terms
#
#CleanCoding
Posts tagged #CleanCoding on Bluesky
Post image

🧹 Clean code means fewer bugs & less stress.

At #IntPHPcon, Timo Körber shares 10+ practical techniques to clean your PHP code and improve long-term maintainability.

#IntPHPCon |📍BER | 📅 June 8 – 12, 26

🎓About the session: https://f.mtr.cool/aayfywqcjb

#PHP #CleanCoding

0 0 0 0
Post image Post image Post image Post image

The next round of scientific rigor educational units is brewing. Sign up to join our community and get timely updates about our curriculum, events, and more.

Join us at c4r.io/join

#Causality #CleanCoding #LiteratureSearches #DataVisualization #ScientificRigor

1 1 0 0
Make Your Chat UI Responsive with Tailwind CSS An Autism Friendly Coding Tutorial
Make Your Chat UI Responsive with Tailwind CSS An Autism Friendly Coding Tutorial YouTube video by AutistiCoder

Just posted a follow-up to my chat UI tutorial:
One small change—responsive text scaling—makes it so much easier to read.
Built in Tailwind. Calm, clear, and made for autistic/ADHD coders.

youtu.be/fleRAet59yM

#TailwindText #FrontendUX #CleanCoding #AutismCoding #NeurodivergentTech #CodeAccessibly

1 0 0 0
Post image Post image Post image

Stay tuned for the beta release of our upcoming scientific rigor educational units: Causality and Clean Coding!

>Join us at C4R.io/join to receive updates about our unit releases and community events.

#causality #cleancoding #scientificrigor #communityforrigor

0 0 0 0
Preview
Single Responsibility Principle in Java ## Introduction The **Single Responsibility Principle (SRP)** is the “S” in the SOLID principles of object-oriented design. It’s often mentioned, sometimes misunderstood, and rarely applied correctly in large Java applications. > **Definition** : A class should have only one reason to change. In practice, this means a class should encapsulate **a single, well-defined responsibility** — not “one method” or “one functionality,” but **one axis of change**. In this article, we'll go beyond trivial examples and explore **real-world SRP violations** , how to spot them, and how to refactor for maintainability and testability. ## 1. A Real-World Example: User Registration Consider the following `UserService` class: public class UserService { public void register(String email, String password) { if (!email.contains("@")) { throw new IllegalArgumentException("Invalid email"); } String hashed = BCrypt.hash(password); User user = new User(email, hashed); userRepository.save(user); sendWelcomeEmail(user); } private void sendWelcomeEmail(User user) { // SMTP connection setup // Template rendering // Email dispatch } } This looks fine... until you need to: * Add a new hashing algorithm * Change email provider * Handle registration for third-party OAuth SRP is violated. Why? ## 2. Identifying the Responsibilities The `UserService` class currently does **at least three things** : 1. **Validates input** 2. **Manages user persistence** 3. **Handles email communication** Each of these concerns could change independently. * Marketing wants to change email templates. * Security wants a new hashing policy. * DevOps wants to decouple SMTP config. All are _reasons to change_. That’s your SRP alarm. ## 3. Refactoring for SRP Let’s extract each responsibility into its own class. ### ✅ Extract validation: public class RegistrationValidator { public void validate(String email) { if (!email.contains("@")) { throw new IllegalArgumentException("Invalid email"); } } } ### ✅ Extract password logic: public class PasswordEncoder { public String encode(String password) { return BCrypt.hash(password); } } ### ✅ Extract email logic: public class WelcomeMailer { private final EmailClient client; public WelcomeMailer(EmailClient client) { this.client = client; } public void send(User user) { client.send(user.getEmail(), "Welcome", "Thanks for joining!"); } } ### 🔁 Updated `UserService`: public class UserService { private final UserRepository userRepository; private final RegistrationValidator validator; private final PasswordEncoder encoder; private final WelcomeMailer mailer; public UserService(UserRepository userRepository, RegistrationValidator validator, PasswordEncoder encoder, WelcomeMailer mailer) { this.userRepository = userRepository; this.validator = validator; this.encoder = encoder; this.mailer = mailer; } public void register(String email, String password) { validator.validate(email); String hashed = encoder.encode(password); User user = new User(email, hashed); userRepository.save(user); mailer.send(user); } } Now: * Each class has **one reason to change** * You can **test independently** * Replacing email providers or validators becomes trivial ## 4. When Is SRP Worth It? Over-applying SRP can lead to fragmentation in **small projects**. But in **medium to large systems** , SRP is essential for: * Isolated unit testing * Team collaboration * Clean domain boundaries A good rule: **When a class grows past 50–70 lines and touches multiple infrastructure layers, SRP may be at risk.** ## 4.5. SRP vs. Microservices: A Note A common misunderstanding is to equate the **Single Responsibility Principle (SRP)** with microservices — as if one microservice should only do one thing. But **SRP applies at the class level** , not the system level. In fact, it’s possible (and common) to: * Have a **monolith** that applies SRP cleanly within each service or module. * Build a **microservice** that violates SRP internally by mixing responsibilities into one giant class (e.g., a `UserService` that also sends emails, logs metrics, and transforms DTOs). SRP helps define **cohesion within a module or microservice** , not how many services you should have. ### ✅ Example Even in a microservice like `OrderService`, you can still break SRP: class OrderService { void createOrder(...) { ... } void sendConfirmationEmail(...) { ... } void updateInventory(...) { ... } } This service may be “small” and “independent,” but the class itself handles **too many responsibilities**. The SRP-compliant version would delegate: * `OrderProcessor` → handles core business logic * `InventoryUpdater` → manages stock * `NotificationService` → sends emails SRP helps you **organize code within microservices** , not decide how many services to build. ## Conclusion The Single Responsibility Principle helps you write Java code that is **easier to change** , **easier to test** , and **easier to understand**. In the real world, SRP is less about counting methods and more about **clarifying responsibilities**. When applied well, it becomes a foundation for clean, robust architecture. You can find the complete code of this article here in GitHub. > 📚 Related: Open/Closed Principle in Java Originally published on my blog: https://nkamphoa.com/single-responsibility-principle-in-java/

Single Responsibility Principle in Java Introduction The Single Responsibility Principle (SRP) is...

dev.to/noel_kamphoa_e688aece072...

#cleancoding #java #programming

Result Details

0 0 0 0
Preview
Writing Clean Code in Front-end: KISS, DRY, YAGNI, and Beyond In the fast-paced world of software development, writing code that simply works is no longer enough. As systems grow more complex and teams become more collaborative, clean code becomes essential, not just for functionality, but for maintainability, scalability, and readability. Clean code isn’t just aesthetically pleasing. It’s a discipline. It reflects thoughtful engineering and a respect for both your future self and your fellow developers. In this article, focusing on the front-end developer, we’ll explore what clean code means and dig into three core principles that help us write better software: KISS, DRY, and YAGNI. # KISS: Keep It Simple, Stupid The KISS principle reminds us not to overcomplicate. Complexity is the enemy of maintainability. KISS = Don't build a rocket ship when a bicycle will do. Avoid clever, convoluted solutions when a simpler approach would suffice. The goal is not to impress, but to communicate. Simplicity often requires more thought and a better understanding of the problem at hand, but it pays off long-term. ## Examples ### Don't do this const isAdmin = user?.roles?.includes('admin') && user?.permissions?.some(p => p.code === 'ALL_ACCESS') && user?.metadata?.active === true; ### Do this const isAdmin = checkUserIsAdmin(user); # DRY: Don’t Repeat Yourself DRY is a fundamental principle in clean code: eliminate repetition. Repeated code is harder to maintain, more error-prone, and signals an opportunity for abstraction. Every piece of knowledge should have a single, unambiguous representation in your codebase. That could mean extracting common logic into a helper function, using inheritance or composition, or consolidating configuration in one place. But beware: Don’t Repeat Yourself doesn’t mean “abstract everything.” Over-abstraction can lead to confusion and make simple things harder to change. DRY is about meaningful consolidation—not premature generalization. ## Examples ### Don't do this <button className="btn btn-primary">Save</button> <button className="btn btn-primary">Submit</button> <button className="btn btn-primary">Send</button> ### Do this const PrimaryButton = ({ children, ...props }) => ( <button className="btn btn-primary" {...props}> {children} </button> ); <PrimaryButton>Save</PrimaryButton> <PrimaryButton>Submit</PrimaryButton> <PrimaryButton>Send</PrimaryButton> # YAGNI: You Ain’t Gonna Need It YAGNI is a mantra of agile and lean coding: `Don’t write code until you absolutely need it.` It’s tempting to try to "future-proof" software by adding features or flexibility that might be useful someday. But that leads to bloat, confusion, and wasted effort. YAGNI keeps us focused on solving today’s problems with clarity and purpose. Build only what is required. When the need truly arises, refactor or extend. # Clean Code Is a Mindset These principles, KISS, DRY, and YAGNI, aren’t just checklists. They reflect a mindset of craftsmanship. Clean code comes from empathy: writing software that your colleagues (and future you) can understand, modify, and trust. Clean code is code that is easy to read, easy to understand, and easy to change. It’s not just about making things "look nice"—it's about writing code that others (and future-you) can work with confidently and efficiently. In frontend development, clean code ensures that your UI logic, components, styles, and data flows are predictable, modular, and maintainable. Whether you’re working with React, Vue, or vanilla JavaScript, the principles of clean code help you ship features faster, debug less, and collaborate better. Clean code is: Readable – Someone new to the codebase can understand what’s happening without asking questions. * Simple: Avoids unnecessary complexity. Clear over clever. * Consistent: Follows the same naming conventions, formatting, and structure across the project. * Modular: Organized into small, single-purpose pieces (e.g., components, functions). * Testable: Designed in a way that makes unit and integration testing easy. * Descriptive: Uses meaningful names for variables, functions, and components. `"Clean code always looks like it was written by someone who cares." — Robert C. Martin (Uncle Bob)` In the world of frontend, that care translates to things like: * Writing small, focused components * Keeping business logic separate from UI rendering * Using clear naming (e.g., SubmitButton instead of Btn1) * Avoiding prop-drilling hell or unnecessary global state * Writing styles that are easy to manage and extend Clean code makes everything smoother, from code reviews and onboarding to bug fixing and feature scaling. # Conclusion Writing clean code isn’t an afterthought. It’s a foundational skill that distinguishes good developers from great ones. In the fast-evolving world of frontend development, where UI complexity grows and user expectations are high, clean code becomes even more critical. By embracing simplicity (KISS), avoiding repetition (DRY), and resisting the urge to over-engineer (YAGNI), we not only write code that works, we write code that scales, lasts, and empowers teams to move fast without breaking things. Clean code is also an act of kindness toward your teammates, your future self, and anyone who’ll ever touch your codebase. `Remember: Code is read more often than it is written. Make yours worth reading.`
0 0 0 0