Nice TWiki > Doc > LanguageComparisons > NiceVersusScala (r1.20) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }

Scala

Scala has many things in common with Nice: "Scala is a modern multi-paradigm programming language designed to express common programming patterns in a consise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages".

There are also fundamental differences: Scala has far less in common with Java (Scala targets CLR as-well-as JVM), Scala uses single dispatch, and has a different type system (nuObj).

This at a glance comparison is based on Scala version 1.0.0-b6 and Nice version 0.9.8

Classes

  Unified Types Traits Mixins External Methods Inner classes Abstract Interfaces
Nice Yes NA NA Yes No Yes
Scala Yes Yes Yes No Yes No

Nice and Scala move forward OO programming in different ways. Nice addresses the problems of adding functionality to existing classes and binary methods with Multi Methods; Scala addresses the problem of implementation reuse with Traits and Mixins.

Methods

  Anonymous Functions Higher-Order Functions Currying Dynamic Dispatch Nested Functions
Nice Yes Yes Not yet (at call site) Multiple Dispatch Yes
Scala Yes Yes Yes (at definition) Single Dispatch Yes

Type Parameters

  Generic Classes Generic Methods Variant Class Type Parameters Upper Type Bounds Lower Type Bounds Multiple Bounds
Nice Yes Yes Not yet completed Yes Yes Yes
Scala Yes Yes Yes Yes Yes Yes

Someone with a better understanding of type systems could comment here

Java Commonality

  Use Java classes Parameterize Java classes Subclass Java classes Subclass in Java Java Statements/Operators
Nice Yes Yes Yes Yes Yes
Scala Yes No Yes Yes No

Although Scala can use Java classes (and in the future .Net classes) there's no intent to make the language familiar to Java programmers; Nice looks a little more like a Java 2.0 than an entirely new language.

Some of these differences can be seen in the following example. In Scala we use a HashMap defined in a Scala library; in Nice we use local type inference with the Java HashMap. In Scala we use a sequence comprehension; in Nice an extended for statement, or a Java for statement.

Scala Nice
import scala.collection.mutable.HashMap;

object hash {
  def main(args: Array[String]) = {
    val n = toPositiveInt(args);
    var count = 0;
    val table = new HashMap[String,Int]();

    for (val i <- Iterator.range(1,n+1)) 
      table(Integer.toString(i, 16)) = i;

    for (val i <- Iterator.range(1,n+1)) 
      if (table contains Integer.toString(i, 10)) 
        count = count + 1;

    Console.println(count);
  }

  private def toPositiveInt(s: Array[String]) = {
    val i = 
      try { Integer.parseInt(s(0)); } 
      catch { case e: Exception => 1 }

   if (i>0) i else 1;
  }

}
 


void main(String[] args){
  let n = toPositiveInt(args);
  var count = 0;
  let table = new HashMap();

  for (int i : 1..n)
    table[ Integer.toString(i, 16) ] = i;

  for (int i = 1; i <= n; i++) 
    if (table.containsKey(Integer.toString(i, 10))) 
      count++;

  println(count);
}

private int toPositiveInt(String[] s){
  int i;
  try { i = Integer.parseInt(s[0]); }
  catch (Exception e){ i = 1; } 

  if (i>0) return i; else return 1;
}

Other

Methods Pattern Matching Local Type Inference Comprehensions Option Types User Defined Coercions Tuples
Nice Enum Classes & Multi Methods Monomorphic (at present) No String & ?String No Yes
Scala Case classes Monomorphic, Polymorphic, Non-Recursive Functions Yes Some(String) & None Yes Library

Of course, both Scala and Nice have other interesting features.

Opinion

Nice Option Types seem to have found a middle course, allowing non-null types to be distinguished without making them harder to use when a value may be null.

Every Scala expression has a value, so there are fewer explicit return statements - I'm familiar with that from Smalltalk, so it's difficult to judge if I just like it because it's familiar. In some cases Scala syntax seems more consistent; Nice seems to extend Java and so add syntax. For example, def square(x: Int) = { var y=x; y*y } and def square(x: Int) = x*x; whereas Nice has int square(int x){ var y=x; return y*y; } and a shorthand form int square(int x) = x*x;

Paradoxically, Nice's syntax is closer to Java, and Nice more effectively reuses Java libraries, but in a fundamental way Scala is more like Java - it's based around classes.

-- IsaacGouy - 26 Jan 2004 (thanks Arjan) 化工泵 净化设备 稳压电源 初级会计师 留学签证 珠海生活 波峰焊 晶振 移动PC 视频点播 聊天室 消毒 越野车 电容器 电磁阀 类风湿 留学专家 首饰 晶体 内存 东莞生活 拓展训练 股票证券 留学中介 广告 电教 液晶屏 超声波 桌面 黑客帝国 挤出机 汽车租赁 消毒液 博天堂 投影仪 黄历 液晶显示器 温控器 动画 屏幕保护 白癜风 垫片 证券 电热膜 主机 户外 扑克 防火墙 肝硬化 注册税务师 广东生活 逆变电源 北京现代汽车 枫叶卡 资源库 风湿 脉管炎 汇款 电脑报价 西联 工作站 监控 广州生活 空间租用 信息化 螺丝 套管 外语 强直性脊柱炎 邮件系统 办公楼 胶粘剂 压力变送器 电线 铃声 皮具 星座 扣件 印花 工商注册 温度计 实验台 歌曲下载 文化 工业控制 雨伞 管理咨询公司 证卡打印机 液压件 注册 助剂 豆粕 胰岛素泵 电子元件 链条 流水线 防爆电机 水处理公司 水产品 紧固件 铸件 保健品 粉末涂料 文件柜 工装 隔离器 中药 手推车 光通信 喷涂设备 铸造 绿茶 宽带接入 计算机学校 工控 激光测距仪 清洗机 尖锐湿疣 网络布线 手电筒 读卡器 网络维护 数码管 栈板 蜂胶 打码机 思科 托盘 免费下载 野营用品 护肤 絮凝剂 色织布 护肤品 儿童玩具 人才招聘 旅游用品 减速电机 金属材料 不锈钢制品 癫痫 电视 电视剧 电工工具 电动摩托车 客车 抛光 黄页 磨床 洗地机 木门 圆珠笔 铜门 调节阀 搜索引擎 环境实验设备 塑料管材 呼吸机 节能 电解电容 网页 医疗 司法考试 结婚 防腐涂料 玻璃仪器 书店 光盘制作 医药 音乐网站 臭氧 网球 铁柜 医院管理 洗衣 致富信息 冠心病 保姆 报关 法语 散热片 毛巾 形象设计

Topic NiceVersusScala . { Edit | Attach | Ref-By | Printable | Diffs | r1.22 | > | r1.21 | > | r1.20 | More }
Revision r1.20 - 27 Jan 2005 - 06:22 GMT - LiYan
Parents: WebHome > LanguageComparisons
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.