Scala for Java Refugees

Saw the series from
http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-1

They really got quite a tutorial!

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to FurlAdd to Newsvine

Advertisements

Javascript or not?

saw the article – You Used JavaScript to Write WHAT?

IMHO….

I thought that article was a very bias view of javascript. I do agree that javascript has much performance issues but the argument about Halo 4 on javascript and not having javascript enabled doesn’t seems quite right.

I meant games usually have system requirements, example, directx installed, certain OS etc.

In that likeness, javascript enabled could very well be one of that list of system requirements. If the user really want to play that game, he could have turned on his javascript or find javascript support. Its the same as, now if we say Halo4 is on flash, flash would have to be installed and enabled also (Oops you need flash 9… flash 8 doesnt work!)

I feel that one of the capabilities of javascript is the concept of fat client. If we have to go to the server for every single request that its not really bandwidth effective. I guess many of us realised that nowadays, OS comes with a default web browser, its like an “installed” environment for you already.

 Of course, end of the day I still agree with the author that Halo4 on javascript sound really like a bad idea because of the performance issues and its limitations.

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to FurlAdd to Newsvine

The Explore Scala Series – Overview

I thought of reading up scala and come up with a simple series of scala tutorials, at the same time, help myself familarise with the language. The idea of functional language really attracts me, of course in java 1.6, there’s support for scripting language,s

Features

  • Object-Oriented
    • Everything is an object
    • Numbers are objects also (have methods)
  • Functional
    • Every function is a value
    • Supports higher order functions
  • Statically typed
  • Can ineract with java directly

Everything is an object

As mentioned above, number is also an object, i.e they have methods and behave like what we know for a typically object. So instead of

object A{
   def main(args: Array[String]){
      println(1 + 1);
   }
}

We could have

object A{
   def main(args: Array[String]){
      println(1.+(1));
   }
}

where in here + is a method of Number.

Functional Example

object A{
 def add(num1: int, num2: int): int = {
 	num1 + num2
 }

	def sub(num1: int, num2: int): int = {
 	num1 - num2
 }

	def op(f: (int,int) => int, para1: int, para2: int): int= {
 	f(para1,para2)
 }

	def main(args: Array[String]){
 	println(op(add, 1,2)) //takes in an add function and 2 para
 	println(op(sub, 1,2)) //takes in a sub function and 2 para
 }
}

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to FurlAdd to Newsvine

Scalable java – Scala

Hello World in java:

public class HelloWorld {
    public static void main(String args[]){
    	System.out.println("Hello World!");
    }
}

Hello World in scala:

object HelloWorld{
 def main(args: Array[String]){
 	println("Hello World!")
 }
}

Into the details(decompiled form):Java:

import java.io.PrintStream;

public class HelloWorld
{

    public HelloWorld()
    {
    }

    public static void main(String args[])
    {
        System.out.println("Hello World!");
    }
}

Scala:

public final class HelloWorld
{

    public static final int $tag()
    {
        return HelloWorld$.MODULE$.$tag();
    }

    public static final void main(String args[])
    {
        HelloWorld$.MODULE$.main(args);
    }
}
//--------------------------------------
import scala.Predef$;
import scala.ScalaObject;

public final class HelloWorld$
    implements ScalaObject
{

    public HelloWorld$()
    {
    }

    public void main(String args[])
    {
        Predef$.MODULE$.println("Hello World!");
    }

    public int $tag()
    {
        return scala.ScalaObject.class.$tag(this);
    }

    public static final HelloWorld$ MODULE$ = this;

    static
    {
        new HelloWorld$();
    }
}

Seems like there’s more stuff for a simple example like this.
But the language seems quite cool.
Several powerful factors includes:

  • compiling to java bytecode(as you can see from above, meaning that it runs on the JVM (hmm… its quite interesting that it is said to be scalable when its running on JVM, but anyhow, gotta explore further)
  • functional language, yet borrows ideas from OO (definitely a very attractive feature)

I’m still quite new to the language but probably I will compare (syntax-wise) java with scala when I’m doing slides for my java tutorial class 🙂

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to FurlAdd to Newsvine

Web X.0?

Web 2.0 has been the buzz word for quite a while. We are really moving in the collaborative way. From a “search-get” style(1.0) to a “search-get-share” style(2.0). I’m thinking that in web 3.0, it will be more web services centered/API style. Its true that currently many sites have been adopting it already(like facebook, google etc) but i guess we just need one major party to bring the whole hype up.

Saw this article

http://www.bin-co.com/blog/2008/01/defining-web-20-at-3-levels/

Thought the Design section was quite interesting.

  • Simple Design
  • Lots of white space
  • Nice icons
  • Badges
  • Big Wordings
  • Gradients
  • Reflections
  • Shadows

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to FurlAdd to Newsvine