A couple of years ago, I wrote that "The Builder pattern is a finite state machine!". A state machine consists of states and transitions between them. As a developer, I want to make illegal states unrepresentable, i.e., users of my API can’t create non-existent transitions. My hypothesis is that only a static typing system allows this at compile-time. Dynamic typing systems rely on runtime validation. In this blog post, I will show that it holds true, with a caveat. If your model has many combinations, you also need generics and other niceties to avoid too much boilerplate code. My exploration will use #Python, #Java, #Kotlin, #Rust, and #Gleam. With that background in mind, let’s move on to the model itself. #builderpattern #finiteStateMachine #illegalState #programming #coding (link in the comments)
Builder Pattern Ensures Illegal States in Finite State Machines
More Relevant Posts
-
🚀 Turning Spaces into URLs — Another Small Win! Today I solved a basic but practical problem on GeeksforGeeks: URLify a string — replacing spaces with "%20". This is actually something used in real-world applications like web development and URL encoding. It made me realize how even simple DSA problems connect to real use cases. I used a clean and efficient approach with Python’s built-in function: 👉 replace() — simple, readable, and powerful. ✅ All test cases passed ✅ Clean one-line solution ✅ Real-world relevance ⏱ Time Complexity: O(n) 💾 Space Complexity: O(n) Sometimes the best solutions are not the most complex ones, but the most elegant ones. Small steps. Daily progress. Strong foundations 💪 How would you solve this — built-in function or manual approach? 🤔 #python #dsa #coding #programming #geeksforgeeks #strings #webdevelopment #developers #learning #100daysofcode
To view or add a comment, sign in
-
-
🚀 Day 79 of #100DaysOfCode 💡 LeetCode 338 – Counting Bits Solved today’s problem with a clean and efficient Dynamic Programming + Bit Manipulation approach 💪 🔍 Problem: For a given number "n", return an array where each index "i" contains the number of 1’s in the binary form of "i". ⚡ My Approach: Instead of recalculating bits every time, I reused previous results: 👉 "ans[i] = ans[i >> 1] + (i & 1)" 🧠 Why this works: - "i >> 1" → removes the last bit - "(i & 1)" → checks if last bit is 1 📈 Performance: ✅ Runtime: 3 ms (Beats 95% 🚀) ✅ Memory: 20.14 MB 🔥 Key Learning: Patterns in binary operations can simplify problems drastically. DP + bit tricks = powerful combo ⚡ #Day79 #LeetCode #CodingJourney #Python #DSA #DynamicProgramming #BitManipulation #100DaysOfCode
To view or add a comment, sign in
-
-
🔁 Understanding the While Loop in Python The while loop is used when you want to execute a block of code repeatedly as long as a condition is True. It’s especially useful when the number of iterations isn’t fixed. Example: i = 1 while i <= 5: print(i, end=" ") i += 1 Output: 1 2 3 4 5 Key things to remember: • Initialize the variable before the loop • Update the variable inside the loop • Avoid infinite loops by ensuring the condition becomes False Common use cases: ✔ Input validation ✔ Iterating until a condition is met ✔ Counting and accumulation ✔ Menu-driven programs Mastering loops is a small step that builds strong programming logic. #Python #LearningPython #WhileLoop #Coding #Programming #DataAnalytics #PythonBasics
To view or add a comment, sign in
-
Hey connections!! Ever struggled to actually understand how sorting algorithms work? Same here. So instead of just memorizing code, I decided to build something… Sorting Visualizer! Watching the bars move, swap, and organize themselves in real-time made everything click for me; things that felt confusing before suddenly started making sense. 💡 What I built: • Visualizations for Bubble sort, Insertion sort, and Selection sort • Speed control for better understanding • Clean, game-inspired UI🎮 • Sound effects 🔊during comparisons and swaps • Live count of comparisons and swaps • Time complexities and Space complexities (best, worst, average) for all three sorting methods • Code implementation in C, Java, and Python • Highlighting the exact line of code being executed in real-time This project reminded me that the best way to learn is by building . Still improving and adding more features😃 #CodingJourney #SortingAlgorithms #FrontendDevelopment
To view or add a comment, sign in
-
🚀 Day 3/100: Mastering Logic Flow & Decision Making! 🏝️ The #100DaysOfCode journey is heating up! Today was all about Control Flow and Conditional Logic in Python. I built a "Treasure Island" text adventure game to practice: ✅ Nested if/elif/else statements ✅ Complex logical operators (AND / OR) ✅ Managing user input edge cases Understanding branching logic is a massive step toward building robust automation scripts and handling real-world data scenarios. ⚔️ Check out my code here: 🔗 https://lnkd.in/gxyRjpGh Onward to Day 4! 🚀 #Python #100DaysOfCode #LogicBuilding #Programming #DevLife #GrowthMindset #CodeNewbie
To view or add a comment, sign in
-
Day 56 - DSA Practice Solved the Isomorphic Strings problem, which checks if two strings can be transformed into each other by consistently mapping characters. Each character in the first string must map to exactly one character in the second string without conflicts. A mapping structure is used to ensure that no two characters map to the same character incorrectly. The approach validates both forward mapping and uniqueness of mapped values. This problem strengthens understanding of hash-based mapping and character relationships in strings. #LeetCode #DataStructures #Algorithms #Java #CodingPractice #ProblemSolving #TechSkills #Programming
To view or add a comment, sign in
-
-
What will be the output of this code? a = [[0]*3]*3 a[0][0] = 1 print(a) A) [[1, 0, 0], [0, 0, 0], [0, 0, 0]] B) [[1, 0, 0], [1, 0, 0], [1, 0, 0]] C) Error D) Something else? Drop your answer below 👇 #Python #Programming #Coding #DeveloperLife
To view or add a comment, sign in
-
🧠 I built my own programming language — and here it is running on CLI. This is GreyMatter — a custom interpreted language I built from scratch using Python and SLY. What you're seeing in this terminal: → The GreyMatter interpreter starting up (v0.01) → A variable being assigned: a = 50 → An IF/ELSE conditional executing in real time → Output: a is even ✅ The entire interpreter was built by me — from the Lexer and Parser to the AST and Runtime Engine. Why did I build this? Because the best way to understand how Python, JavaScript, or any language works... is to build one yourself. Every keyword you type, every error you get, every output on your screen — there's an entire pipeline behind it. Building GreyMatter made me truly understand that pipeline. 🔗 GitHub: github.com/Abineshabee Drop a 🧠 in the comments if you'd like to see more about how it works! #Python #Programming #OpenSource #BuildInPublic #ComputerScience #InterpreterDesign #GreyMatter #StudentProject #Ben10
To view or add a comment, sign in
-
-
Unpopular take: Before jumping to Big-O, swapping data structures, or blaming the framework or language — fix the simple things first. There’s a handful of well-known things that are dead simple, yet quietly abused in almost every codebase I’ve seen. Correct those before reaching for alternative exotic optimizations. You’ll be surprised how often that’s the whole fix. #python #softwareengineering #programming #coding #softwaredevelopment #techleadership
To view or add a comment, sign in
-
Project 03 of my AI/ML Project Series: AI Code Debugger Debugging for 3 hours? Upload your error screenshot. My AI reads it and fixes your Python, JavaScript, or C++ bugs in seconds. Two modes: Hints → Learn why it broke Solution → Get working code instantly Which mode saves you more time? Hints or Solution? GitHub: https://lnkd.in/g_dusxvv #softwareengineering #coding #python #javascript #webdev #artificialintelligence #programming #codinglife
To view or add a comment, sign in
More from this author
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
https://blog.frankel.ch/illegal-state-unrepresentable/