Have you ever heard about the Strategy Pattern? The Strategy pattern allows you to define different algorithms/behavior for the same task and switch between them at runtime. Instead of hardcoding a specific behavior, the behavior is injected (the strategy injection). A common example is sorting. Imagine you have a list of users and sometimes you want to sort them by: • name • age • registration date Each of these is a different strategy for sorting users. Traditionally, this was implemented by creating a base strategy class and multiple implementations. A 'UserSorter' would receive one of these strategies and use it to perform the sorting. But in many modern codebases we often implement this pattern in a simpler way. Instead of creating multiple classes, we can just pass a function (lambda) that defines the behavior. The concept is exactly the same, we inject the algorithm/behavior that should be used. The difference is that today the strategy is often expressed as a function instead of a class. #programming #softwareengineering #developers #flutter #dartlang #designpatterns #strategypattern #softwarearchitecture #cleancode
Strategy Pattern: Dynamic Sorting with Dart
More Relevant Posts
-
Things that seem easy (but aren’t): Naming variables. At first, it feels trivial. Just pick something that works. Something short. Something “good enough.” But bad names don’t fail immediately. They fail later. When someone else reads your code. When you revisit it after a week. When the logic grows more complex. Now “data”, “temp”, “value” mean nothing. Good naming is not about creativity. It’s about clarity. It forces you to understand what the code is actually doing. And that’s why it’s hard. Because if you can’t name it clearly, you probably don’t understand it well enough. Simple on the surface. Deep in practice. What’s the hardest thing you’ve had to name in code? #softwareengineering #cleancode #developers #programming #engineering
To view or add a comment, sign in
-
-
Solved today’s LeetCode Daily and it made me pause 👇 “XOR After Range Multiplication Queries I” At first glance, it looks like: Segment Tree? Lazy Propagation? Some heavy optimization? 🤯 But the reality? Sometimes… brute force wins. --- Given constraints were small. And that completely changes the game. So instead of overengineering: ✔️ Just simulate each query ✔️ Jump with k steps ✔️ Apply multiplication (mod 1e9+7) ✔️ Take final XOR And that’s it. --- The interesting part 👇 As developers, we are trained to think: “Optimize first” But problems like this remind us: 👉 Understand constraints before choosing approach Because honestly, A simple O(n * q) solution can beat an overcomplicated design any day. --- What I learned today: • Not every problem needs advanced DS • Constraints are part of the problem statement for a reason • Simplicity is underrated --- Consistency check ✅ One more problem done. --- Curious 👇 Comment your approach. #LeetCode #DSA #Programming #Coding #Developers #ProblemSolving #Rust
To view or add a comment, sign in
-
-
⚡ The Biggest Lie in Tech: “I’ll Fix It Later” Developers often say: “I’ll optimize it later.” “I’ll clean this up later.” “I’ll refactor after this feature.” But “later” rarely comes. And slowly… ❌ Code becomes harder to manage ❌ Bugs become harder to fix ❌ Systems become harder to scale What started as a shortcut… turns into a long-term problem. 💡 At DevHonor, we believe: • Quality should not be delayed • Clean code should not be optional • Good architecture should not be postponed Because: Every “I’ll fix it later” is a future problem being created today. ⚡ Build it right while you’re building it. DevHonor #DevHonor #CleanCode #SoftwareDevelopment #Programming #TechMindset #SoftwareEngineering #CodeQuality #WebDevelopment #TechnicalDebt 🚀
To view or add a comment, sign in
-
-
How does #Parchment #Programming (#PP) address the #Discontinuous #Code #Transformation (#DCT) problem? Full story: https://lnkd.in/gnpyAJqE #Bottom #Line The #Discontinuous #Code #Transformation (#DCT) problem is essentially a problem of lossy intermediate representations wherever a human serves as the translation layer. Parchment Programming solves it by making the architecture diagram itself the lossless, AI-readable intermediate representation — replacing the human-as-translator with an AI-as-transformer operating on a richly structured artifact. The result is that the most expensive and error-prone DCT transition — ideas → source code — becomes a well-specified, reproducible, AI-mediated step rather than a creative act dependent on individual developer interpretation. Cc: Adam Bosworth
To view or add a comment, sign in
-
-
⚠️ 𝗪𝗵𝘆 𝘁𝘄𝗼 𝗰𝗼𝗿𝗿𝗲𝗰𝘁 𝗼𝗽𝗲𝗿𝗮𝘁𝗶𝗼𝗻𝘀 𝗰𝗮𝗻 𝗰𝗿𝗲𝗮𝘁𝗲 𝗮 𝘄𝗿𝗼𝗻𝗴 𝗿𝗲𝘀𝘂𝗹𝘁 Imagine two processes running at the same time. Both access the same data. Individually: ✅ correct ✅ valid Together: ❌ unexpected result That’s called a **race condition**. It happens when: ⚙️ operations depend on timing 🔄 execution order is unpredictable Example: Two users updating the same value at once. Result? Data inconsistency. 𝗧𝗶𝗺𝗶𝗻𝗴 𝗶𝘀𝗻’𝘁 𝗮𝗹𝘄𝗮𝘆𝘀 𝘂𝗻𝗱𝗲𝗿 𝘆𝗼𝘂𝗿 𝗰𝗼𝗻𝘁𝗿𝗼𝗹. That’s why systems use: 🔒 locks ⚙️ synchronization 📊 controlled access Have you ever faced a bug that only happens “sometimes”? #Programming #Developers #SoftwareEngineering #Concurrency #SystemDesign #Debugging #TechExplained #CodingLife #LearningInPublic #ITStudent #DeveloperLife #ComputerScience #ProblemSolving
To view or add a comment, sign in
-
-
Furthest point from origin Thought process: We’re given a string with 'L', 'R', and '_'. 'L' → move left 'R' → move right '_' → can be either left or right 🤔 So the key idea is: the final distance mainly depends on how we use '_'. To maximize distance, we should move all '_' in the direction that already has more moves (left or right). This way, the gap increases as much as possible. So, the ans becomes: abs(lCnt - rCnt) + underscore_cnt #programming #problemSolving #coding #developers #softwareengineering #DSA #algorithms
To view or add a comment, sign in
-
-
🧠 One small mistake can break your entire logic. Today I learned this while solving a grid problem 👇 💻 LeetCode #1559 — Detect Cycles in 2D Grid At first glance, it looks like a simple DFS problem… But there’s a catch ⚠️ 🔍 Common mistake developers make: 👉 “If I visit an already visited cell → cycle exists” Sounds correct… but it’s NOT ❌ 🚀 My Approach (DFS + Parent Tracking): Traverse the grid using DFS Move in 4 directions (up, down, left, right) Only move to cells with the same character 👉 While moving, I track the parent cell 💡 Key Logic: If I reach a cell that is: Already visited AND not the parent 👉 Then a cycle exists ✅ ⚙️ Why parent check is important? Because going back to the previous cell is normal 👉 It should NOT be treated as a cycle 🧠 Takeaway: In DSA, logic rarely fails… 👉 Edge cases do 🔥 The difference between wrong and correct solution is often just one condition Have you ever fixed your solution by changing just 1 line? 😄 #LeetCode #DSA #Algorithms #Programming #Debugging #ProblemSolving #Developers #CodingJourney
To view or add a comment, sign in
-
-
𝐁𝐢𝐠 𝐮𝐩𝐝𝐚𝐭𝐞 𝐭𝐨 𝐁𝐮𝐢𝐥𝐝 𝐃𝐢𝐬𝐭𝐫𝐢𝐛𝐮𝐭𝐞𝐝 𝐒𝐲𝐬𝐭𝐞𝐦𝐬, 𝐛𝐞𝐞𝐧 𝐰𝐨𝐫𝐤𝐢𝐧𝐠 𝐨𝐧 𝐭𝐡𝐢𝐬 𝐟𝐨𝐫 𝐭𝐡𝐞 𝐩𝐚𝐬𝐭 𝟐 𝐰𝐞𝐞𝐤𝐬. I have spent the last few weeks significantly expanding build-distributed-systems. It has been about a 3 weeks since the initial release, and I wanted to share a major update to the platform. The project is now at version 2.0. I have added 14 new tracks and hundreds of new tasks, bringing the total to 𝟐𝟖 𝐭𝐫𝐚𝐜𝐤𝐬 𝐚𝐧𝐝 𝟑𝟒𝟑 𝐭𝐚𝐬𝐤𝐬 𝐚𝐜𝐫𝐨𝐬𝐬 𝟖 𝐜𝐚𝐭𝐞𝐠𝐨𝐫𝐢𝐞𝐬. New materials cover topics like distributed file 𝐬𝐭𝐨𝐫𝐚𝐠𝐞 (𝐓𝐡𝐞 𝐅𝐢𝐥𝐞𝐬𝐲𝐬𝐭𝐞𝐦), 𝐙𝐨𝐨𝐊𝐞𝐞𝐩𝐞𝐫-𝐬𝐭𝐲𝐥𝐞 𝐜𝐨𝐨𝐫𝐝𝐢𝐧𝐚𝐭𝐢𝐨𝐧 (𝐓𝐡𝐞 𝐖𝐚𝐭𝐜𝐡𝐞𝐫), 𝐚𝐧𝐝 𝐝𝐢𝐬𝐭𝐫𝐢𝐛𝐮𝐭𝐞𝐝 𝐭𝐫𝐚𝐜𝐢𝐧𝐠 (𝐓𝐡𝐞 𝐓𝐫𝐚𝐜𝐞𝐫). I also 𝐞𝐱𝐩𝐚𝐧𝐝𝐞𝐝 many of the original tracks, such as Consensus and The Gossiper, with more advanced subtracks. The system now supports 𝟕 𝐩𝐫𝐨𝐠𝐫𝐚𝐦𝐦𝐢𝐧𝐠 𝐥𝐚𝐧𝐠𝐮𝐚𝐠𝐞𝐬. 𝐖𝐡𝐚𝐭'𝐬 𝐜𝐨𝐦𝐢𝐧𝐠: - Drag-and-drop protocol simulator where you can visualize how your design behaves under network partitions, node failures, different consistency guarantees - Capstone projects to tie everything together - Interactive visualizers for Raft, Gossip, consistent hashing - Cohort learning mode - More real-world system case studies If you are interested in learning how 𝐝𝐢𝐬𝐭𝐫𝐢𝐛𝐮𝐭𝐞𝐝 𝐬𝐲𝐬𝐭𝐞𝐦𝐬 are built from 𝐟𝐢𝐫𝐬𝐭 𝐩𝐫𝐢𝐧𝐜𝐢𝐩𝐥𝐞𝐬, I encourage you to try these tracks. Website: https://lnkd.in/gpCa-FGP #distributedsystems #softwareengineering #backend #kubernetes #systemdesign
To view or add a comment, sign in
-
-
Debugging is a skill every developer talks about… But very few actually master. In the beginning, I used to jump straight into fixing code. I assumed I already knew the problem. Most of the time, I was wrong. Now my approach is different: 1. Reproduce the issue 2. Understand the data flow 3. Log everything important 4. Fix the root cause Debugging is not about being smart. It’s about being systematic. And honestly, the calmer you stay, the faster you solve it. #Debugging #Programming #ProblemSolving #Developers
To view or add a comment, sign in
-
Explore related topics
- Code Design Strategies for Software Engineers
- Modern Strategies for Improving Code Quality
- Strategies for Writing Error-Free Code
- Intuitive Coding Strategies for Developers
- How Pattern Programming Builds Foundational Coding Skills
- Strategies For Code Optimization Without Mess
- Code Injection Strategies
- Emergent Design Strategies Using Refactoring
- Strategies for Writing Robust Code in 2025
- Optimization Strategies for Code Reviewers
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development