News for hackers. Stuff that matters.
Re:What's Wrong with Tech Hiring by 72f988bf on Thursday September 16, 2021 @12:52PM (#28554155)
FizzBuzz is one of those puzzles where majority of experienced programmers won't find the solution easily as it involves the modulo operator in weird ways.

The modulo operator is rarely used in practice, unless you're writing your own hash table or some other internal where bucketizing by some ID is relevant.

Using the modulo within a for-loop though, virtually never happens.

So unless you're niche where using modulo every other day, or you're just out of school where you just learned about "+,-,*,/,%" , you have a good chance at failing fizzbuzz if you don't remember it's "that modulo 3 and modulo 5 silly puzzle"

There are better ways of testing for iterating, iterating through a real collection of elements is already much better than FizzBuzz.

Re:What's Wrong with Tech Hiring by jmaygarden on Thursday September 16, 2021 @01:45PM (#28554775)
I'd never considered the modulo operator to be that uncommon, but I've mostly worked in systems software and firmware. Is that really the case?
Re:What's Wrong with Tech Hiring by pc86 on Thursday September 16, 2021 @02:34PM (#28555387)
The only time I've ever used it in programming is FizzBuzz.
Re:What's Wrong with Tech Hiring by jmaygarden on Thursday September 16, 2021 @05:40PM (#28558033)
To prevent rehashing this, I have discovered the exact same discussion from 5 years ago.

https://news.ycombinator.com/item?id=11884645

Re:What's Wrong with Tech Hiring by ffdzghg on Thursday September 16, 2021 @07:48PM (#28559310)
Curious: How do you do “every other row” in a loop if you don’t do modulo?
Re:What's Wrong with Tech Hiring by wst_ on Friday September 17, 2021 @07:11PM (#28571923)
Not advocating for being oblivious about modulo op, but you could use stepping in some languages. Example, in Kotlin: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/s...
Re:What's Wrong with Tech Hiring by pc86 on Friday September 17, 2021 @12:36PM (#28567547)
Why would you want to do every other row in a database? That just sounds like "a random half" with extra steps if you're doing math on your DBMS's equivalent of RowID.
Re:What's Wrong with Tech Hiring by arp242 on Saturday September 18, 2021 @08:00AM (#28575519)
Things like applying a different colour or styling for visual effect is a common-ish reason, or parsing some input which looks like:

  Stuff I want
  Extra stuff belonging to the above line I want to ignore
  More stuff I want
  More ignore stuff
  [..etc..]
Which can be from a CLI tool, a web scraper tool, something copy pasted from a webpage, or something like that. This data can often be "messy" but in a regular way. I've parsed WikiText tables from Wikipedia like this (very crude, but it only needs to run once).

Another example of "% 2" is for centre aligning strings in a grid (e.g. a terminal; if it's odd you need to add one extra space to one side). I've also used it for time calculations (e.g. printing seconds as "hour:minutes:seconds").

That's from the top of my head; I've probably used it in other things as well. Note this is all high-level application work: no muckery with low-level controllers, firmware, or whatnot.

Is the % operator very common? No; but I don't think it's as "virtually never happens"-uncommon as was mentioned a few posts up the thread.