code

How to paste and load blocks of code in the Scala REPL

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 14.2, “How to paste and load blocks of code in the Scala REPL.”

Problem

You want to experiment with some code in the Scala REPL, and typing it in or trying to paste it into the REPL won’t work.

Source code for an Android ViewPager example (Activity and Fragment)

This is a little unusual for me, but I'm putting the following code here so I can remember how I implement a ViewPager in my current Android application. I want to put this code out here in its current state before it gets more complicated. In fact, I only wish I had copied it out here earlier, before I made it as complicated as it is.

The only things that are important to know are:

How to access an Android MenuItem from a Java Activity or Fragment alvin February 17, 2015 - 7:50pm

Here’s a quick example of how to access an Android MenuItem in a Java Activity or Fragment class (i.e., in your Java code).

Given a menu named res/menu/menu_landing_page.xml defined like this:

Software code too fluid to test right now

I love this comment from Martin Odersky, from the image shown, which comes from this link:

“Initially, things were too fluid to invest in tests. I simply did not know whether the design would hold up, had to fit a lot of pieces together first. But now is a good time to put these tests in place.”

So often people talk about “Test First Development” that I think they’re insane, or just regurgitating marketing-speak to sound good. There are times when you’re coding things like SARAH where you don’t know how things are going to shake out that “Test First” just doesn’t make sense. If you know what you’re getting into when you’re coding, Test First sounds good, but when you’re exploring, “Oh, this is how SARAH should work”, or, “I thought an FTP server worked like this but it works like that”, Test First doesn’t make sense. (Once you understand the domain, giddyup, test your heart out.)