Nice is a new object-oriented programming language based on Java. It incorporates features from functional programming, and puts into practice state-of-the-art results from academic research. Among the advanced features: generic types, anonymous functions, multi-methods, tuples, optional parameters to methods, design by contract, detection of many errors during compilation (in particular, concerning casts and null references). This results in more expressivity, modularity, and type safety.
Checkout the
The Nice programming language. Nice is currently in version 0.9.10
-
Nice - A new OO language based on Java (29 messages)
- Posted by: Tsozum Tsozum
- Posted on: March 07 2005 11:49 EST
Threaded Messages (29)
- Nice - New? by Toby Reyelts on March 07 2005 16:47 EST
- Very Interesting by Joe M. on March 08 2005 00:56 EST
-
Preventing NullPointerException by Daniel Bonniot on March 08 2005 03:11 EST
-
Preventing NullPointerException by Cedric Beust on March 08 2005 01:12 EST
- Preventing NullPointerException by Daniel Bonniot on March 08 2005 01:48 EST
-
Preventing NullPointerException by Toby Reyelts on March 08 2005 03:41 EST
-
Preventing NullPointerException by Ivan Bilenjkij on March 09 2005 11:06 EST
-
Preventing NullPointerException by Daniel Bonniot on March 09 2005 05:35 EST
-
Preventing NullPointerException by Ivan Bilenjkij on March 10 2005 04:21 EST
- Preventing NullPointerException by Daniel Bonniot on March 10 2005 06:45 EST
-
Preventing NullPointerException by Ivan Bilenjkij on March 10 2005 04:21 EST
-
Preventing NullPointerException by Daniel Bonniot on March 09 2005 05:35 EST
-
Preventing NullPointerException by Ivan Bilenjkij on March 09 2005 11:06 EST
-
Preventing NullPointerException by Cedric Beust on March 08 2005 01:12 EST
-
Preventing NullPointerException by Daniel Bonniot on March 08 2005 03:11 EST
- Very Interesting by Joe M. on March 08 2005 00:56 EST
- Nice - syntax highlighting, Intellisense, Debug ? by Vagif Verdi on March 07 2005 17:31 EST
- Tool support by Daniel Bonniot on March 07 2005 20:14 EST
-
Tool support by Rodolfo de Paula on March 12 2005 12:03 EST
-
Correction ? by Rodolfo de Paula on March 12 2005 12:05 EST
-
finally, i realized by Rodolfo de Paula on March 12 2005 11:32 EST
- finally, i realized by Daniel Bonniot on March 25 2005 03:29 EST
-
finally, i realized by Rodolfo de Paula on March 12 2005 11:32 EST
-
Correction ? by Rodolfo de Paula on March 12 2005 12:05 EST
-
Tool support by Rodolfo de Paula on March 12 2005 12:03 EST
- Tool support by Daniel Bonniot on March 07 2005 20:14 EST
- Bah... try something wilder... by Zoe Info on March 07 2005 17:57 EST
- no need for visitor by geoff hendrey on March 08 2005 00:55 EST
- no need for visitor by Kit Davies on March 08 2005 05:12 EST
- "deferred" is old by Brian Smith on March 09 2005 03:21 EST
-
well java should have it too! by geoff hendrey on March 09 2005 04:13 EST
-
oh well by geoff hendrey on March 09 2005 04:14 EST
-
read_only by Radu-Adrian Popescu on March 10 2005 03:01 EST
- cool by geoff hendrey on March 10 2005 11:34 EST
- read_only by Rodolfo de Paula on March 10 2005 01:09 EST
-
read_only by Radu-Adrian Popescu on March 10 2005 03:01 EST
-
oh well by geoff hendrey on March 09 2005 04:14 EST
-
well java should have it too! by geoff hendrey on March 09 2005 04:13 EST
- deferred by Liam Knox on February 10 2008 05:03 EST
- multityped variables by Holger Engels on March 08 2005 02:46 EST
- looks great by Thomas Whitmore on March 10 2005 20:08 EST
- looks great by Daniel Bonniot on March 11 2005 08:43 EST
-
Nice - New?[ Go to top ]
- Posted by: Toby Reyelts
- Posted on: March 07 2005 16:47 EST
- in response to Tsozum Tsozum
Nice is a pretty neat language - it's good to see bits and pieces of statically-typed functional programming becoming more mainstream. Daniel Bonniot is pretty "nice" too, being fairly responsive to people with questions. One good thing I hear, is that they're evaluating putting together an "interpreter" so people can more easily come to grips with the language.
Having said that, Nice is anything but new. IIRC, it's been around for nearly 5 years now.
God bless,
-Toby Reyelts -
Very Interesting[ Go to top ]
- Posted by: Joe M.
- Posted on: March 08 2005 00:56 EST
- in response to Toby Reyelts
This is very interesting. What percentage of null pointers can they prevent - that would be a great gain for productivity. -
Preventing NullPointerException[ Go to top ]
- Posted by: Daniel Bonniot
- Posted on: March 08 2005 03:11 EST
- in response to Joe M.
This is very interesting. What percentage of null pointers can they prevent - that would be a great gain for productivity.
100%! That is, the compiler will check that your code can never throw NullPointerException. This is possible because you can formally declare in types whether null is allowed or not (unlike Java were this is left for the javadoc at best, or unspecified at worst). And the compiler runs a powerful static analysis to detect what values might be null.
Of course, there are situations where you know a value cannot be null, but the compiler cannot detect it. In that case, you can still make him happy by adding an assertion. For instance:
Map<String,String> map = new HashMap();
map["a"] = "1"; // this is the same as map.put("a", "1')
?String value = map["a"];
// to use value here, you'd need to handle the null case too
The compiler knows that when getting from a Map, the value might be null if that key has no associated value, so the returned type is ?String (String or null). In this particular case, you, the programmer, know that "a" has a value. You can tell it to the compiler, either with:
assert value != null;
or alternatively, you can do directly:
String value = notNull(map["a"]);
In both cases, you can now use value as a real String. Obviously, if your assertion is not true, it will fail at runtime. What you gained over Java is that:
1) APIs formally declare where they accept null;
2) In most cases, the compiler can make sure your code will never throw NullPointerException, or point you to a potential error;
3) In the few cases where you know there is no potential error although the compiler cannot prove it, you have to write an explicit assertion. This encourages you to really think to make sure you are correct (or better, change your design to make the assertion unnecessary). -
Preventing NullPointerException[ Go to top ]
- Posted by: Cedric Beust
- Posted on: March 08 2005 13:12 EST
- in response to Daniel Bonniot
This is very interesting. What percentage of null pointers can they prevent - that would be a great gain for productivity.
100%!
I don't get it. How does the deferred keyword prevent null pointers? If the code has run through the new, all NPE's are avoided, whether there is a "deferred" or not.
--
Cedric -
Preventing NullPointerException[ Go to top ]
- Posted by: Daniel Bonniot
- Posted on: March 08 2005 13:48 EST
- in response to Cedric Beust
Deferred has nothing to do with Nice. Nice prevents null pointer exceptions in all cases, using static analysis of the code. -
Preventing NullPointerException[ Go to top ]
- Posted by: Toby Reyelts
- Posted on: March 08 2005 15:41 EST
- in response to Cedric Beust
I don't get it. How does the deferred keyword prevent null pointers? If the code has run through the new, all NPE's are avoided, whether there is a "deferred" or not.-- Cedric
To further Daniel's comment, you should look up "option types" and "maybe types", which are standard functional fare.
God bless,
-Toby Reyelts -
Preventing NullPointerException[ Go to top ]
- Posted by: Ivan Bilenjkij
- Posted on: March 09 2005 11:06 EST
- in response to Toby Reyelts
What I don't like is that you still have to test for null:
(name == null) ? 0 : name.length();
Wouldn't it be 'nice' to allow classes to define their own null instance behaviour (a la serialVersionUid):
class String {
static final null = new String();
// or override:
static final null = new String () {
public int length () {
return 0;
}
}
}
so that something like this:
String name; // is actually String name = String.null;
Regards,
Ivan Bilenjkij -
Preventing NullPointerException[ Go to top ]
- Posted by: Daniel Bonniot
- Posted on: March 09 2005 17:35 EST
- in response to Ivan Bilenjkij
You don't have to test for null all the time. For instance, if it makes sense to consider null to have length zero, you can define:
int length(?String s)
{
if (s == null)
return 0;
else
return s.length();
}
then you can use length even on possibly null values:
?String s = null;
println(s.length); // prints 0 -
Preventing NullPointerException[ Go to top ]
- Posted by: Ivan Bilenjkij
- Posted on: March 10 2005 16:21 EST
- in response to Daniel Bonniot
Daniel,
You just moved the 'if' part to another place. Also, the method you introduced is not an instance method so it explicitly declares 'this' reference in its arg list. And then it is used as an instance method - that is awkward.
IMHO, allowing any class to define its own 'null' instance is more elegant solution to prevent NPE. -
Preventing NullPointerException[ Go to top ]
- Posted by: Daniel Bonniot
- Posted on: March 10 2005 18:45 EST
- in response to Ivan Bilenjkij
Yes, declaring methods outside classes can seem strange at first, but read about multi-methods, and you will see how convenient and powerful they are.
Also, allowing classes to declare a null instance is a less general solution. True, it can prevent NPE by giving a default behaviour to all methods, but what if there is no meaningful default behaviour? (what is the name of a null User?) Nice allows you to specify where null is allowed and where it is not. This can give you safety that class null instance cannot give. -
Nice - syntax highlighting, Intellisense, Debug ?[ Go to top ]
- Posted by: Vagif Verdi
- Posted on: March 07 2005 17:31 EST
- in response to Tsozum Tsozum
Modern developers are so spoiled with syntax highlighting, Intellisense, Debug, and other IDE enhansements, that even such a *Nice* language will not get its well deserved attention, untill it provides all what we take for granted. -
Tool support[ Go to top ]
- Posted by: Daniel Bonniot
- Posted on: March 07 2005 20:14 EST
- in response to Vagif Verdi
Actually, there are lots of tools supporting Nice. There is an Eclipse plugin for Nice. There is also nicedoc for generating documentation. JSR 045 conformant debuggers can be used with Nice programs (JSwat, jdb, ...). There are plugins for Ant and Maven. Highlight support syntax highliting of Nice programs into many output formats. -
Tool support[ Go to top ]
- Posted by: Rodolfo de Paula
- Posted on: March 12 2005 12:03 EST
- in response to Daniel Bonniot
Daniel
Congratulations. Nice is really groovy ;)
Interesting, with all the hype about JVM scripts languages around, Nice is going to enforce compiler checkings. It´s nice to have these exceptions evicted by compiler. Less tests to write, isn´t ? (for TDD adicts)
About multi methods, from the alt.lang.jr article:
void laugh(String str){
println("haha, I'm holding an instance of " str);
}
lets suppose I want to do this :
int laughAndReturnIntensity(String joke){
if (joke.equalsIgnoreCase("haha, I'm holding an instance of " str)) {
println("haha, that´s funny !");
} else {
println("what ?");
}
return joke.length() ;
}
It is possible with Nice ? Can I refeer to joke instance ?
And about tools, I can't leverage Eclipse features like code completion and refactoring with Nice plugin (at least right now), right ? -
Correction ?[ Go to top ]
- Posted by: Rodolfo de Paula
- Posted on: March 12 2005 12:05 EST
- in response to Rodolfo de Paula
int laughAndReturnIntensity(String joke){
if (joke.equalsIgnoreCase("haha, I'm holding an instance of " joke)) {
println("haha, that´s funny !");
} else {
println("what ?");
}
return joke.getInstance().length() ;
} -
finally, i realized[ Go to top ]
- Posted by: Rodolfo de Paula
- Posted on: March 12 2005 23:32 EST
- in response to Rodolfo de Paula
int laughAndReturnIntensity(String joke){
if (joke.equalsIgnoreCase("haha, I'm holding an instance of " joke)) {
println("haha, that´s funny !");
} else {
println("what ?");
}
return joke.length() > 30 ? 0 : 1;
}
So if I can simulate AOP advise using Nice multi methods, why not:
void save("*POJO"){
// code to persist this object instance to a xml file
}
where "*POJO" would be the regular expression used to specify the classes I want to apply this advise, simulating an AOP pointcut ? Would be nice too ? -
finally, i realized[ Go to top ]
- Posted by: Daniel Bonniot
- Posted on: March 25 2005 03:29 EST
- in response to Rodolfo de Paula
Rodolfo, your last version is correct. No need to call something like "getInstance".
It's possible to dispatch on string values:
void save(String name) { ... }
override void save("*POJO"){ ... }
The second version will be called if the parameter is "*POJO" exactly, the string is not regarded as a regular expression.
It would be possible to add a more general mechanism where you could specify if an implementation is applicable using a boolean condition (for instance, matching a regex). However, the problem is: which implementation would be selected when several conditions are true? If they are defined in several files/packages, there is no obvious ordering. It would be clearer if that feature was only available for implementations defined in the same file. -
Bah... try something wilder...[ Go to top ]
- Posted by: Zoe Info
- Posted on: March 07 2005 17:57 EST
- in response to Tsozum Tsozum
... like a post-structuralist, object oriented system :P
Lua — Story of O
http://alt.textdrive.com/lua/19/lua-story-of-o
Even got Java bindings if you really, really want to:
http://www.keplerproject.org/luajava/ -
no need for visitor[ Go to top ]
- Posted by: geoff hendrey
- Posted on: March 08 2005 00:55 EST
- in response to Tsozum Tsozum
dynamic dispatch is the best part. I wish Java had it so I wouldn't need Visitor.
I also wish Java had delegates.
I also wish Java had a syntax like:
List myList = deferred new ArrayList();
the "deferred" keyword would delay instantiation of the ArrayList until the first time the code accessed myList. Has anyone heard of a feature like this in another language?
-geoff -
no need for visitor[ Go to top ]
- Posted by: Kit Davies
- Posted on: March 08 2005 05:12 EST
- in response to geoff hendrey
I also wish Java had a syntax like:List myList = deferred new ArrayList();the "deferred" keyword would delay instantiation of the ArrayList until the first time the code accessed myList. Has anyone heard of a feature like this in another language?-geoff
Visual Basic!
:o) -
"deferred" is old[ Go to top ]
- Posted by: Brian Smith
- Posted on: March 09 2005 03:21 EST
- in response to geoff hendrey
The effect that you are asking for is called lazy evaluation. Eiffel has "once" methods which is very similar to this. Many strict functional languages (e.g. O'Caml) have "lazy" type constructors that allow for deferred evaluation. Haskell has lazy (technically, "non-strict") evaluation by default. -
well java should have it too![ Go to top ]
- Posted by: geoff hendrey
- Posted on: March 09 2005 16:13 EST
- in response to Brian Smith
The effect that you are asking for is called lazy evaluation. Eiffel has "once" methods which is very similar to this. Many strict functional languages (e.g. O'Caml) have "lazy" type constructors that allow for deferred evaluation. Haskell has lazy (technically, "non-strict") evaluation by default.
Cool. Now if only Java had it! (oh, Cedric, this has nothing to do with preventing null ptr).
Also, I want java to add read-only functionality:
public read-only int x,y,z;
private Something somethingl
public read-only Something getSomething(){
return something;
} -
oh well[ Go to top ]
- Posted by: geoff hendrey
- Posted on: March 09 2005 16:14 EST
- in response to geoff hendrey
I guess it would need to be read_only not read-only. -
read_only[ Go to top ]
- Posted by: Radu-Adrian Popescu
- Posted on: March 10 2005 03:01 EST
- in response to geoff hendrey
Couldn't help it: it's called const and can also qualify methods (C++). -
cool[ Go to top ]
- Posted by: geoff hendrey
- Posted on: March 10 2005 11:34 EST
- in response to Radu-Adrian Popescu
does it have the effect of making an Object returned from a method immutable? -
read_only[ Go to top ]
- Posted by: Rodolfo de Paula
- Posted on: March 10 2005 13:09 EST
- in response to Radu-Adrian Popescu
Perhaps the old and good "final" modifier ? -
deferred[ Go to top ]
- Posted by: Liam Knox
- Posted on: February 10 2008 05:03 EST
- in response to geoff hendrey
You could obtain Deffered behaviour using a bit of AOP, and leveraging Spring and aspect werks -
multityped variables[ Go to top ]
- Posted by: Holger Engels
- Posted on: March 08 2005 02:46 EST
- in response to Tsozum Tsozum
I'd like do declare variables / methods / fields / parameters / .. with multiple types (0..1 classes and 0..n interfaces, but at least one interface or class). This would disburden developers from unsafe castings. Example:
Comparable, Serializable Observable whatever;
// ...
int c = whatever.compareTo(whatelse);
int h = whatever.hashCode(); -
looks great[ Go to top ]
- Posted by: Thomas Whitmore
- Posted on: March 10 2005 20:08 EST
- in response to Tsozum Tsozum
Hey, this has 3/4 of the stuff I've been wishing for while coding Java... !
All these methods external to the instance (eg callable on a null parameter), collaboration methods external to multiple instances, all this is *exactly* relevant.
Great stuff! Keep up the good work,
Cheers,
Thomas Whitmore
www.powermapjdo.com -
looks great[ Go to top ]
- Posted by: Daniel Bonniot
- Posted on: March 11 2005 08:43 EST
- in response to Thomas Whitmore
Thanks! Feel free to share about the remaining 1/4 to reach perfection! (either here or on Nice's mailing list)