scala

warning: Creating default object from empty value in /opt/bitnami/apps/portal/htdocs/modules/taxonomy/taxonomy.pages.inc on line 33.

making conference a safer space for women

in

This post was coauthored by Eugene Yokota and Yifan Xing.

We need to change the culture around tech conferences to improve the inclusion of women (and people from other backgrounds too!). For that, there needs to be clear signaling and communication about two basic issues:

  1. No, it's not ok to hit on women at a conference.
  2. Assume technical competence, and treat women as professional peers.

These points should be communicated over and over at each conference before the keynote takes place, and before socializing hours.

stricter Scala with -Xlint, -Xfatal-warnings, and Scalafix

in

Compile, or compile not. There's no warning. Two of my favorite Scala compiler flags lately are "-Xlint" and "-Xfatal-warnings".
Here is an example setting that can be used with subprojects:

ThisBuild / organization := "com.example"
ThisBuild / version      := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.12.6"
 
lazy val commonSettings = List(
  scalacOptions ++= Seq(
    "-encoding", "utf8",
    "-deprecation",
    "-unchecked",
    "-Xlint",
    "-feature",
    "-language:existentials",

all your JDKs on Travis CI using jabba

in

Whether you want to try using OpenJDK 11-ea, GraalVM, Eclipse OpenJ9, or you are stuck needing to build using OpenJDK 6, jabba has got it all. jabba is a cross-platform Java version manager written by Stanley Shyiko (@shyiko).

AdoptOpenJDK 8 and 11

Here's how we can use jabba on Travis CI to cross build using AdoptOpenJDK 8 and 11:

sudo: false
dist: trusty
group: stable
 
language: scala
 
scala:
  - 2.12.7
 
env:
  global:
    - JABBA_HOME=/home/travis/.jabba
 
matrix:

bringing back power assert with Expecty

in

I wanted give Expecty a try, so I forked the repo to eed3si9n/expecty, added sbt build, patched up the code so it works with 2.10, 2.11, 2.12, and 2.13.0-M4, sent a few pull requests upstream, changed the package name, and published my fork to Maven Central:

libraryDependencies += "com.eed3si9n.expecty" %% "expecty" % "0.11.0" % Test

and for Scala.JS and Scala Native:

libraryDependencies += "com.eed3si9n.expecty" %%% "expecty" % "0.11.0" % Test

Here's how we can use this:

scala> import com.eed3si9n.expecty.Expecty.assert
import com.eed3si9n.expecty.Expecty.assert
 
scala> assert(a * b == 7)
java.lang.AssertionError:
 
assert(a * b == 7)
       | | | |
       1 3 3 false
 
  at com.eed3si9n.expecty.Expecty$ExpectyListener.expressionRecorded(Expecty.scala:25)
  at com.eed3si9n.expecty.RecorderRuntime.recordExpression(RecorderRuntime.scala:34)
  ... 38 elide

As you can see, you get a nicer error message automatically.

detecting Java version from Bash

in

Yesterday I wrote about cross JVM testing using Travis CI.

testing Scala apps on macOS using Travis CI

Here's how we can test Scala apps on macOS using Travis CI. This is adapted from Lars and Muuki's method: Testing Scala programs with Travis CI on OS X

dist: trusty
 
language: scala
 
matrix:
  include:
    ## build using JDK 8, test using JDK 8
    - script:

herding cats: day 17

in

Wrote herding cats: day 17 featuring initial and terminal objects, product, duality, and coproduct.

encoding file path as URI reference

in

In this post I am going to discuss an old new problem of encoding file path as Uniform Resource Identifier (URI) reference.

As of 2017, the authoritative source of information is RFC 8089 - The "file" URI Scheme written by Matthew Kerwin.

Future readers might also want to search for "file URI scheme RFC", and find the latest version. If you're a programmer, read the RFC. This post is to raise the awareness of the some of the issues around file to URI encoding, but it's not a substitution.

Recently I've been running into interop problems as some platforms are unable to parse file:/foo/bar. But this is not the first time I'm having trouble with file path represented as URI. Considering that the notion of filesystem goes back to 1960s, and URL has been around since 1990s, it's surprising that we haven't come to a concensus on this. But then again, like decimal numbers, once you start digging deeper, or start exchanging data, we find some glitches in the Matrix.

Gigahorse 0.3.0

in

Gigahorse 0.3.0 is now released. See documentation on what it is.

OkHttp support

0.3.0 adds Square OkHttp support. Gigahorse-OkHttp is availble for Scala 2.10, 2.11, and 2.12.

According to the JavaDoc you actually don't have to close the OkHttpClient instance.

scala> import gigahorse._, support.okhttp.Gigahorse
import gigahorse._
import support.okhttp.Gigahorse
 
scala> import scala.concurrent._, duration._
import scala.concurrent._
import duration._

herding cats: day 16

in

Contraband, an alternative to case class

in

Here are a few questions I've been thinking about:

  • How should I express data or API?
  • How should the data be represented in Java or Scala?
  • How do I convert the data into wire formats such as JSON?
  • How do I evolve the data without breaking binary compatibility?

limitation of case class

The sealed trait and case class is the idiomatic way to represent datatypes in Scala, but it's impossible to add fields in binary compatible way. Take for example a simple case class Greeting, and see how it would expand into a class and a companion object:

 

Syndicate content