Scanner scanner;
try {
scanner = new Scanner(filename);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
ArrayListlines = new ArrayList ();
while (scanner.hasNextLine())
lines.add(scanner.nextLine());
All I can think of is what a shame it is that I have to declare scanner before the try-catch block (and that the curlies are mandatory).
Here's the equivalent in my experimental programming language Jax:
Scanner scanner = try new Scanner(filename)
catch (FileNotFoundException e)
throw new RuntimeException(e);
ArrayListlines = new ArrayList ();
while (scanner.hasNextLine())
lines.add(scanner.nextLine());
That first line shows how try-catch blocks evaluate to an expression. Everyone should be thrilled about Jax so I have motivation to continue working on it!
4 comments:
If you make it so it's an addition to java, and then make it work with eclipse, people would probably be interested in it.
There's a problem with the syntax that requires a ; after some }'s.
for example
if (condition) {
foo()
};
// other things
that semicolon is required in Jax but not in Java. It would be possible to make it not required but only with a lot of sloppy parsing logic similar to javascript's semicolon insertion. i feel more inclined toward the python 3 philosophy of quality over backward compatibility. but then python 3 isn't real successful yet and C++ is. so idk
First gain support, then make it awesome.
in order for it to be awesome, i have to break compatibility with Java.
Post a Comment