Women in Technology

Hear us Roar



Article:
  Technologies to Watch: A Look at Four That May Challenge Java’s Development Dominance
Subject:   More fun...
Date:   2005-10-25 06:46:37
From:   billrobertson42
Multiple assignments look about the same as multiple variable decls on the same line to me. I got out of that habit with the advent of C++ a while back.


We can get a little bit more compact with the fib function, a few less recursive calls, but still has some issues related to recursion because IIRC, JVM's don't optimize away tail recursion like some run time environments do.



public static void fib(int x1, int x2, int depth) {
System.out.println(x2);
if(depth > 0) fibo(x2, x1+x2, depth-1);
}


Speaking of fibs, if you want all of them it's a bit more work in Java than in Haskal, but still...



public static void bigFib() {
BigInteger x1 = BigInteger.ZERO;
BigInteger x2 = BigInteger.ONE;
BigInteger total = BigInteger.ONE;
while() {
System.out.println(total);
total = x1.add(x2);
x1 = x2;
x2 = total;
}
}


Of course, you won't get all of them for a couple of reasons.


1. The memory on your PC is finite.
2. Your time on this earth is finite.


So think a little bit about #2 if for some reason this post (or the original article) upsets you for some reason. Just relax, go with the flow and have fun.