Scala/Java: How to convert a stack trace to a string for printing with a logger

As a quick note, I just got a little bit better about logging stack traces when writing Java or Scala code. In Scala I used to get the text from a stack trace and then log it like this:

// this works, but it's not too useful/readable

In that code, getStackTrace returns a sequence, which I convert to a String before printing it.

What Digital (eBook) and Print sales look like for a computer programming book

If you ever wondered what Digital and Print book sales look like for a technical book (a computer programming book, in this case), here you go. This is a slightly cleaned up chart that O’Reilly provides to me for sales of the Scala Cookbook over time, showing eBook sales vs the printed book sales.

putStrLn doesn’t print to STDOUT ... it describes how to print to STDOUT alvin June 12, 2017 - 9:57am

putStrLn doesn’t print to standard out, it returns a value — of type IO () — which describes how to print to standard out, but stops short of actually doing it.”

From the article, An IO Monad for Cats.

How to print an array in Android Log output (Logcat)

If you need to dump the contents of an array to the Android Log (Logcat) output, I can confirm that this approach works, at least with simple arrays of integers and strings that know how to print themselves:

Log.i("MyAndroidClass", Arrays.toString(arr));

If you’re trying to print more complicated arrays of custom objects you’ll probably need to implement good toString methods on those objects, and then this technique should work.

Haskell problem: putStr not evaluated in the proper order (lazy)

I just ran into a problem where the putStr function in Haskell was not printed out in the order I wanted it to be. I wanted to prompt a user for input, then read their input, but the putStr output didn’t appear until later, after I hit the Enter key. (putStr is preferred here over putStrLn because it does not add a newline character after the output.)