If you Google FizzBuzz, you will see there are gazillion implementations in different programming languages of these rules:
For numbers 1 through 100,
- if the number is divisible by 3 print Fizz;
- if the number is divisible by 5 print Buzz;
- if the number is divisible by 3 and 5 (15) print FizzBuzz;
- else, print the number.
What's wrong with not writing code at all for the rules for FizzBuzz, and model it instead in the way everyone understands? I could not find any implementation of FizzBuzz as simple and self-descriptive as this one:
I am just trying to say that sometimes it is better not to code the logic, simply because it is easier to understand and maintain.
Ok look, here is a random solution just by Googling:
class FB{static public void main(String[]b){for(int i=0;i<100;System.out.println((++i%3<1?"Fizz":"")+(i%5<1?"Buzz":i%3<1?"":i)));}}
When you write business logic in code, that's exactly what it looks like in a couple of months (if not the week after you've written it!). No matter how well you've written it, it's going to be hard to understand after a while, because you are going to lose the context, no matter what.
Book a Custom Demo
Happy FizzBuzz!
To learn more about Decision Tables and alternatives to modeling a Decision Table (DT), please visit https://resource.flexrule.com/knowledge-base/decision-table
Last updated July 23rd, 2024 at 10:05 am Published July 3rd, 2015 at 05:27 pm




