Skip to content

Instantly share code, notes, and snippets.

scalajavatimeRoot  + scalajavatimeCrossJVM/testOnly org.threeten.bp.zone.TestTzdbZoneRulesCompiler
[info] Setting version to 2.11.8
[info] Reapplying settings...
[info] Set current project to scalajavatimeRoot (in build file:/home/soc/Entwicklung/scala-java-time/)
[info] TestTzdbZoneRulesCompiler:
[TestNG] Running:
Command line suite
[info] -
[info] -
public SimpleEdge(long, long);
descriptor: (JJ)V
flags: ACC_PUBLIC
Code:
stack=7, locals=11, args_size=3
0: aload_0
1: lload_1
2: putfield #43 // Field _u:J
5: aload_0
6: lload_3
== Kotlin
class T {
fun t(): Unit {
val double = { x:Int -> x * 2 }
listOf(1,2).map { x -> x * 2 }.map{ it + 1 }.map( double )
}
}
creates
startup, version: 3103 linux x64 channel: stable
executable: /opt/sublime_text/sublime_text
working dir: /
packages path: /home/soc/.config/sublime-text-3/Packages
state path: /home/soc/.config/sublime-text-3/Local
zip path: /opt/sublime_text/Packages
zip path: /home/soc/.config/sublime-text-3/Installed Packages
ignored_packages: ["Vintage"]
pre session restore time: 0.100141
startup time: 0.322647
Context bounds are typically used with the so-called _type class pattern_.
A context bound like `Numeric` on a type parameter `T` looks like this:
T : Numeric
While upper bounds constrain `T` to be a subtype of the upper bound,
context bounds also constrain the `T` albeit in a more flexible fashion.
`T : Numeric` can be read as "a `T` which supports numeric operations".
https://docs.google.com/presentation/d/1mkBEHmaxkiebh-r79xdSlZsqghWsZREYaBDN48Ex9xY/pub?start=false&loop=false&delayms=60000
package parser.opus
import scodec.Codec
case object OggS
case object Version
case class Header(continuation: Boolean, beginningOfStream: Boolean, endOfStream: Boolean)
case class Page(
oggS: OggS.type,
version: Version.type,
/** Returns the size and the remaining vector. */
def segmentBodySize(vector: ByteVector): (Int, ByteVector) = {
def loop(index: Int = 0, accum: Int = 0): (Int, ByteVector) = {
val value = (vector(index) & 0xFF)
if (value != 255) {
(value + accum, vector.drop(index + 1))
} else {
loop(value + accum, index + 1)
}
}

Avoid abbreviations

  • Often there are multiple ways to abbreviate a name, but usually only one unabbreviated name. Don't make your users guess.
  • Sometimes it's tempting to abbreviate names, but consider that having consistency across libraries is often more important, than a particularly nice or clever abbreviation.
  • Users can rename things on import. This makes it straightforward to look up an abbreviated name, if the user decides to abbreviate something.

Avoid symbolic names

  • Sometimes it is tempting to pick a symbolic name, but consider that it makes it hard for users to search for these names on the web, and causes issues with pronouncing these names.
  • As a general rule of a thumb: If the cost/benefit ratio of a symbolic name is lower than ???, it's probably not worth it.

Constructors

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
@Retention(RetentionPolicy.RUNTIME)
@Target(value = Array(ElementType.TYPE, ElementType.METHOD))
@throws[RuntimeException] @Foo @Val(/*clazz = classOf[String]*/) class Baz