argument

Never argue with a fool ~ Mark Twain

“Never argue with a fool. Onlookers may not be able to tell the difference.”

~ Mark Twain (used recently in reference to Antonio Brown on Twitter)

Don’t raise your voice; improve your argument

“My father always used to say, ‘Don’t raise your voice; improve your argument.’ Good sense does not always lie with the loudest shouters, nor can we say that a large, unruly crowd is always the best arbiter of what is right.”

~ Archbishop Desmond Tutu

This is a page from my book, “How I Sold My Business: A Personal Diary”

Monday, September 30, 2002

An Alaska polar bear

Taking the advice of a friend, I declared today a "Mental Health Day" for myself. I called my client to let them know I wasn't coming, left a message at the office, had breakfast at a little restaurant I know, and then went to the zoo. For some reason I like to go to the zoo once a year, with or without other people, and I love to commune with the polar bears.

How to use Scala varargs fields from Java (varargs annotation)

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is a short recipe, Recipe 17.5, “How to annotate varargs methods in Scala.”

Problem

You’ve created a Scala method with a varargs field, and would like to be able to call that method from Java code.

Solution

When a Scala method has a field that takes a variable number of arguments, mark it with the @varargs annotation.

How to create a Scala/Akka Actor whose constructor requires arguments

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 13.2, “How to create a Scala/Akka Actor whose constructor requires arguments.”

Problem

You want to create an Akka actor, and you want your actor’s constructor to have one or more arguments.

Solution

Create the actor using the syntax shown here, where HelloActor takes one constructor parameter:

Scala: How to create methods that take variable-arguments (varargs) fields

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 5.7, “How to create methods that take variable-arguments (varargs) fields.”

Problem

To make a method more flexible, you want to define a method parameter that can take a variable number of arguments, i.e., a varargs field.

Solution

Define a varargs field in your method declaration by adding a * character after the field type:

How to use parameter names when calling a Scala method

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 5.4, “How to use parameter names when calling a Scala method.”

Problem

You prefer a coding style where you specify the method parameter names when calling a method.

Solution

The general syntax for calling a method with named parameters is this:

methodName(param1=value1, param2=value2, ...)

This is demonstrated in the following example. Given this definition of a Pizza class:

How to set default values for Scala method parameters

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 5.3, “How to set default values for Scala method parameters.”

Problem

You want to set default values for method parameters so the method can optionally be called without those parameters having to be assigned.

A Scala implicit method argument and field example

UPDATE: This example shows how to create an implicit method in Scala 2.9 or older. You can use a slightly simpler approach with Scala 2.10 and newer, which I've documented in this Scala 2.10 implicit class example.

I'm not going to do much writing here today, but instead I'll just demonstrate how an implicit method argument works with implicit fields in Scala. Without any further ado, here's some code: