This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
type declaration best practices?
- From: Jamison Hope <jrh at theptrgroup dot com>
- To: kawa at sourceware dot org
- Date: Thu, 12 Nov 2009 18:11:15 -0500
- Subject: type declaration best practices?
Is there a definitive set of best practices for declaring types of
variables? I see mention here and there that using angle brackets is
out, but they're still all over the place in Kawa sources and the Kawa
homepage.
These appear to all be valid and equivalent:
(define (tagged-vector3f tag :: <symbol> x :: <float> y :: <float>
z :: <float>) :: <pair>
(cons tag (make <javax.vecmath.Vector3f> x y z)))
(define (tagged-vector3f tag :: symbol x :: float y :: float z ::
float) :: pair
(cons tag (make javax.vecmath.Vector3f x y z)))
(define (tagged-vector3f (tag symbol) (x :: float) (y :: float) (z ::
float)) :: pair
(cons tag (make javax.vecmath.Vector3f x y z)))
(define (tagged-vector3f (tag symbol) (x float) (y float) (z
float)) :: pair
(cons tag (make javax.vecmath.Vector3f x y z)))
Likewise:
(define-alias Vector3f <javax.vecmath.Vector3f>)
(define-alias Vector3f javax.vecmath.Vector3f)
[or s/alias/namespace/g in that]
Which of these are the preferred forms? Are there situations in which
angle brackets are still required?
Also, I realize that there are differences between an alias and a
namespace:
(let ((x 3)) (define-namespace y x) (define-alias z x) (set! x 4)
(list x y z))
=> (4 3 4)
but it seems like when used with a class name as the second operand,
both define-namespace and define-alias are chiefly useful in order to
avoid having to repeatedly type a FQCN, like a Java import. So, which
is truly conceptually closer to a Java import statement? Which
produces better code? When declaring a variable's type, or as the
first argument to the make procedure, is there a performance
difference when using (1) a built-in type (an instance of
gnu.bytecode.Type), (2) a fully-qualified class name, (3) a namespace,
or (4) an alias?
Thanks,
--
Jamison Hope
The PTR Group
www.theptrgroup.com