Can we hope not to need hSetBuffering someday?


I’d love to use Haskell more clash of code’s shortest mode, but this line makes it almost always useless :frowning:

1 Like

And it’s almost always unneeded. So just remove it!

Don’t tell me you keep the CG standard boilerplate when you clash in shortest mode?!

Oh, didn’t know it wasn’t always needed, thanks for the info
Of course not haha, I typically remove the do block and just leave >>'s and >>='s

When is hSetBuffering needed?

It’s needed when normal program termination isn’t enough of an upper duration bound for your program’s outputs.

Could you rephrase that? I do not get what you are saying

The referee expects your program output to come in a certain time limit.
Your program output “comes” when its buffer is full or when it is flushed.
The standard library automatically flushes when the program is finished.

The hSetBuffering call in the default stub sets the buffering mode to NoBuffering. This is always too conservative and is very likely to degrade performance (not necessarily noticeably, as the default String-based IO is already pretty bad).
You can always safely change it to LineBuffering, which flushes at each \n.

For clashes and I/O puzzles, and assuming your program doesn’t hang after it output the relevant information, program termination is enough of a flush and neither hSetBuffering nor explicit flush is necessary.

For multi-turn games, it is necessary that the referee gets the turn information in time for you not to be disqualified. How you achieve that depends on your code and the volume of output. Flushing once per turn always works.