Nice TWiki > Doc > StaticFieldsAndMethods (r1.1 vs. r1.2) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
 <<O>>  Difference Topic StaticFieldsAndMethods (r1.2 - 11 Feb 2003 - TWikiGuest)
Added:
>
>


 <<O>>  Difference Topic StaticFieldsAndMethods (r1.1 - 06 Feb 2003 - TWikiGuest)
Added:
>
>

%META:TOPICINFO{author="guest" date="1044494100" format="1.0" version="1.1"}% %META:TOPICPARENT{name="NiceTutorial"}%

Staticmethods

A static method in Java is just a function (no dispatch) and it has no implicit 'this' parameter. So in Nice you can write a function instead (directly at the package level, not inside a class). For instance instead of Java's

package java.lang;

abstract class Math
{
  static int max(int x, int y)
  {
    return x > y ? x : y;
  }
  ...
}
You would write in Nice:
package nice.lang;

int max(int x, int y)
{
  return x > y ? x : y;
}

Staticfields

Similarly to static methods, the equivalent of Java's static field is a package variable. Java Code:

package a;

class Color
{
  static Color[] colors;
  ...
}
Nice code:
package a;

var Color[] colors;

class Color
{ ... }
One has to be aware that static variables have a great disadvantage: they do no play well with repetitive or concurrent uses of a library. Since libraries are often first written as a standalone program, this problem is often overthought. Later, the static variables have to be replaced with fields of a State object that is passed around. Therefore I think static variables should be seldom used. Now I wonder if language design can help discouraging their use. Should they be disallowed completely? Do some languages try to adress this issue?

-- DanielBonniot - 14 Jun 2002


Topic StaticFieldsAndMethods . { View | Diffs | r1.2 | > | r1.1 | More }
Revision r1.1 - 06 Feb 2003 - 01:15 GMT - TWikiGuest
Revision r1.2 - 11 Feb 2003 - 13:36 GMT - TWikiGuest
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.