where Business Processes, Data and Rules meet.
Blog

FizzBuzz

0

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:

FlexRule-FizzBuzz

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.

Happy FizzBuzz!

To learn more about Decision Tables and alternatives to modeling a Decision Table (DT), please visit http://wiki.flexrule.com/index.php?title=Decision_table

Recommended Posts

Leave a Comment

You must be logged in to post a comment
Contact Us

We're not around right now. But you can send us an email and we'll get back to you, asap.