Rate my revolutionary language. It's called C2, because it's twice as good as C.
using c2.Application;
using c2.data.Json;
using c2.net.Http;
using c2.io.File;
// Python-style indentation-based syntax for a fresh, clean look
class ExampleMain implements Application:
/*
auto is the equivalent of @Autowired in Spring
e.g. the value gets injected by the runtime upon class instantiation
this reduces coupling in comparison to using Java's System.out
*/
auto Output stdout
constructor():
// C-style semantics for endless possibilities
int a = 42
void run():
stdout.writeLine('Hello World!')
File f = File.open('test.txt', 'wt')
f.writeLine('for me')
// UFCS - gets converted to this.myWriteLine(f, ...)
f.myWriteLine('and you')
f.close()
Http.get('api.4chan.org/status', func(Json data):
// Json object gets implicity stringified, obviously
stdout.writeLine('Response is:', data)
)
// Main thread ends while the request is still in progress,
// but like in Java, program doesn't quit until all threads have finished
// Output is a generic OutputStream-like interface
// for convenience, it handles both byte- and character-based IO
void myWriteLine(Output f, Any... text):
f.write('Special output: ', text, '\n')
~$ c2 --verbose example.c2
Compiling example.c2...
Found 1 implementation(s) of c2.Application:
- ExampleMain
Instantiating ExampleMain
Calling Application.run
Hello World!
Response is: {'status': 'ok'}