Fizzbuzz in Java sweetened by Kotlin

I want them to know that we play FizzBuzz!What is FizzBuzz?After a fair bit of trial and error I’ve discovered that people who struggle to code don’t just struggle on big problems, or even smallish problems (i.

e.

write a implementation of a linked list).

They struggle with tiny problems.

So I set out to develop questions that can identify this kind of developer and came up with a class of questions I call “FizzBuzz Questions” named after a game children often play (or are made to play) in schools in the UK.

An example of a Fizz-Buzz question is the following:Write a program that prints the numbers from 1 to 100.

But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”.

For numbers which are multiples of both three and five print “FizzBuzz”.

Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes.

Want to know something scary?.The majority of comp sci graduates can’t.

I’ve also seen self-proclaimed senior programmers take more than 10–15 minutes to write a solution.

— Imran GhoryWhy it is needed to learn & not ctrl+v ?- This is just my experience about general naive practices of getting things done.

Even when we know how a particular implementation works we copy paste it.

I’m not saying we shouldn’t use available resources.

Reinventing the wheel is the fools game.

We should rather focus on learning the concept, testing it & then adding it to our source code.

I go by this code of conduct.

“ Code is like humour.

When you have to explain it, it’s bad.

” — Cory HouseThen what’s the catch?.The first and foremost suggestion.

When we say it is a programming language that we use, it’s the only medium two developers can speak and should speak.

Imagine if I write a comment for every line in this blog.

Well, that’s why we need to understand that our code should talk for us.

Also, there are many such ethics in software development we can talk but I’m here for Fizzbuzz.

This is my attempt to improve and share some perspective.

The Question?- This is usually asked in almost every programming language interview.

Write a program that prints the numbers from 1 to 100.

But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”.

For numbers which are multiples of both three and five print “FizzBuzz”.

How do we even approach this?- We should only take an oath that we won’t panic for a mere question.

Get A Problem, Solve a ProblemBreak the question, Let’s do It!- Print the numbers from 1 to 100, your suggestion yes!.We need a loop to print this.

-Expected Output: For multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”.

For numbers which are multiples of both three and five print “FizzBuzz”.

1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, Fizz Buzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, Fizz Buzz, 31, 32, Fizz, 34, Buzz, Fizz, .

-Now you have all the liberty to avert your eyes from the screen and implementing it but you’ll find tons of resources so what’s the use?.

Let’s see how by looking at a solution.

Well, this is some solution, FizzBuzz assumes that people should be thinking of architecture and the updating process all the time.

What I think happens is that people choose the path of least resistance.

It’s a small program that isn’t expected to change that much?.Quick-and-dirty usually works just fine.

You’re working on creating the next-gen operating system?.Architecture is a must.

So when they see a short list of simple product requirements (that don’t even imply coding for the future), architecture isn’t really going to matter.

Scale the program up and they’ll change priorities.

Hence why this test isn’t indicative of how good a programmer is.

Okay right, the solution in Java doesn’t seem promising what about if we use Kotlin does it help?- Let’s look at this Kotlin solutionThis seems readable and interesting, Kotlin does solve things it reduces code, readability and improves quality.

Well, fizzbuzz solved by legacy code is something very silly when you can do the same thing in a single line.

Imagine if there are 10 more utility functions and the java solution might take several lines and with Kotlin even with this modern language, you can increase line count only if you don’t know to use operator functions.

Remember Remember:- Always code as if the person who had to maintain it after you, was a bloodthirsty axe-wielding murderer who knew where you live.

-It’s actually about servitude, generally, people mistakenly take it in a negative way, I know it’s not their fault.

The Google definition goes bythe state of being a slave or completely subject to someone more powerful.

The way I see it, it’s about helping people by solving their problems.

Serving means you are applying your skills for the betterment of some other human being.

This song is something more relatable to what I want to convey.

Bob Dylan — Gotta Serve Somebody.

ConclusionIn this post, you learned the philosophy of computer science and what actually a software engineer does a long game of fizzbuzz but responsibly.

Your solutions are always welcomed.

If you like these principles, clean architecture and Kotlin programming language let’s connect.

Sharan Salian – Apps on Google PlayPassionate about app development.

My aim is to build a product which will be used by millions of people all around the…play.

google.

com.

. More details

Leave a Reply