Blog Post

#428 Build 1.0.37

brian Sun 11 Jan 2009

Its been about a month since our last build, so I've posted a new build and updated the online docs.

Java FFI

This build completes phase 1 of the Java FFI feature which was introduced in the last build.

You can now override a Java method which uses primitives or arrays. For example:

// Java method
String foo(int[] array, int i)

// Fan override
override Str? foo(IntArray? array, Int i)

I've also added support to use a Fan function whenever a Java interface with one method is expected:

button := JButton("Press Me!")
{
  addActionListener |ActionEvent e| { echo("Button pressed!") }
}

Web Enhancments

The web and wisp modules have been enhanced to fully support HTTP 1.1 features including:

  • chunked output streams
  • pipelining and persistent HTTP connections
  • client-side HTTP support

The new WebClient class is used to manage client side HTTP connections:

// get a URI as a string
web::WebClient(`http://fandev.org`).getStr

// dump get response status and headers
c := WebClient(`http://fandev.org/`).writeReq.readRes.close
echo("$c.reqUri => $c.resCode $c.resPhrase")
c.resHeaders.each |Str v, Str k| { echo("$k: $v") }

See docLib and docCookbook for more details.

New Date and Time APIs

Our original design for the sys::DateTime API also called for a separate Date and Time class which I have finally implemented. These classes round out the core time APIs:

DateTime.now.date => 2009-01-11
DateTime.now.time => 12:20:13.859
Date.today => 2009-01-11
Time.now => 12:20:17.406

Sometime in the next year I will probably be implementing an iCal API for Fan too.

New Uuid API

I added a new sys::Uuid class. Unlike the Java version, it attempts to use your MAC address when generating a new UUID. This class might still change some - I think I might apply an SHA-1 hash to make it more suitable for distibuted hash table work.

New Unit API

There is a new sys::Unit class. This class is for modeling units (not necessarily applying them to the type system). This feature includes a unit database based on the OASIS oBIX specification which predefines a ton of units and enables conversion between them:

class UnitTester
{
  Void main()
  {
    convert(150f, Unit.find("pound"), Unit.find("kilogram"))
    convert(1f,   Unit.find("mile"), Unit.find("foot"))
    convert(1f,   Unit.find("acre"), Unit.find("square_meter"))
  }

  Void convert(Float x, Unit from, Unit to)
  {
    echo("$x $from.symbol -> ${from.convertTo(x, to)} $to.symbol")
  }
}

// outputs
150.0 lb -> 68.03865 kg
1.0 mile -> 5280.0 ft
1.0 acre -> 4046.872627 m²

Bootstrap Build

Starting in this build you need JDK 1.6 to compile from source. The build scripts still generate 1.5 classfiles and the runtime continues to only require 1.5.

I've also added a new "dumpenv" target to all build scripts:

C:\dev\fan\src>jfan\build dumpenv
---------------
  scriptFile:  /C:/dev/fan/src/jfan/build.fan [build::BuildJava]
  fanHome:     /C:/dev/rel/
  devHomeDir:  /C:/dev/fan/
  javaHome:    /C:/dev/tools/java/

See updated Bootstrap chapter for now information to help debugging your build environment.

Interal Type Checks

The compiler now reports an error if an internal type is used in a public API. This means that a public class or mixin cannot use an internal type in any public or protected field or method.

Change Log

Build 1.0.37 (11 Jan 09)

  • Java FFI: array overrides of methods which use primitives or arrays
  • Java FFI: coerce sys::Func to Java interface with one abstract method
  • New sys::Date and sys::Time APIs
  • New sys::Unit API
  • New sys::Uuid API
  • New web::WebClient API
  • Wisp support for chunked transfers and persistent connections
  • Str isAlpha, isAlphaNum
  • OutStream sync
  • Allow closures in constructor to set const fields (same for static ctors)
  • Change Obj.trap arg signature to Obj?[]?
  • Flux enhancements for goto into, find, find in files
  • Protection checks to prevent internal types being used in public APIs
  • Expose sys::File ctor to allow new implementations
  • Optimize common MimeTypes to be interned
  • BuildScript dumpenv target

JohnDG Tue 13 Jan 2009

This looks very good. Unfortunately, no time to check it out right now.

On the subject of promoting Fan, I think it would be great to show some front-page snippets of how to solve 1 or 2 different common tasks. Post side-by-side Java/C#/Fan versions. I'd suggest one task involving IO (counting words in a file?) and one task involving lists (finding all elements equal to another?).

brian Tue 13 Jan 2009

On the subject of promoting Fan, I think it would be great to show some front-page snippets of how to solve 1 or 2 different common tasks. Post side-by-side Java/C#/Fan

I think the best thing for promoting Fan is for people to use it and blog about it :-) But I like that idea - it would have to be pretty minimal for the front page, although also having a more in-depth cookbook for side-by-side compares would be cool. If anyone has some chunks of ugly Java code which would be good candidates, please submit them (in another thread).

Login or Signup to reply.