Skip to content

Instantly share code, notes, and snippets.

@Horusiath
Last active December 4, 2015 13:47
Show Gist options
  • Select an option

  • Save Horusiath/9f416d132583c7bc3792 to your computer and use it in GitHub Desktop.

Select an option

Save Horusiath/9f416d132583c7bc3792 to your computer and use it in GitHub Desktop.

FSharp

type IReaderWriter =
  abstract member Read : unit -> unit
  abstract member Write : unit -> unit
  
type IReader =
  abstract member Read : unit -> unit

type SomeClass1(x: int, y: float) =
    interface IReaderWriter with
        member this.Read() = printfn "%d %f" x y
        member this.Write() = printfn "%d %f" x y
    interface IReaderWriter with
        member this.Read() = printfn "%d %f" x y

Unnecessarily verbose, but thanks to the interface implementation scoping it's easy to wrap the head around impl.

People tend to use things easy to do, and avoid things that takes more time to accomplish. Make defining types easy.

Ceylon

class Point {
  public int x;
  public int y;
}

41 chars, 12 tokens (including 4 symbols) - 5 have actual meaning: Point, 2 * int, x, y. It takes time to read the "meat" of this code.

FSharp

Extra note: all struct equality + automatic constructor creation for free

type Point = { 
  x: int
  y: int 
}

29 chars, 11 tokens (including 5 symbols) - 5 have actual meaning: Point, 2 * int, x, y. All clear and readable.

Groovy

class Point { int x, y }

23 chars, 8 tokens (including 3 symbols) - 4 have actual meaning: Point, int, x, y. Stil clear and quite readable.

Haskell

data Point = Int Int

20 chars, 5 tokens (including 1 symbol) - 3 have actual meaning: Point, 2 * Int. But yes - this is not so obviously easy to read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment