Click here to Skip to main content
13,045,657 members (48,246 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 13 Aug 2011

Promising Features for Languages in the Future

, 13 Aug 2011
Rate this:
Please Sign up or sign in to vote.
Several features from Traceur which are supposed to be promising in the future of programming language design

Traceur is Google’s vehicle for JavaScript language design experimentation which allows you to use features from the future today. I have selected several features from Traceur which are supposed to be promising in the future of programming language design.

Destructuring Assignment

Destructuring assignment is a nice way to assign or initialize several variables at once:

let [a, [b], c, d] = ['hello', [', ', 'junk'], ['world']];
print(a + b + c); // hello, world

It can also destructure objects:

let pt = { x: 123, y: 444 };
let rc = { topLeft: { x: 1, y: 2 }, bottomRight: { x: 3, y: 4} };

let {x, y} = pt;  // unpack the point
let {topLeft: {x: x1, y: y1}, bottomRight: {x: x2, y: y2}} = rc;

print(x + y); // 567
print([x1, y1, x2, y2].join(','));  // 1,2,3,4

In my view, the destructuring assignment is just a limited version of pattern matching. Many applications written in Erlang using pattern matching and Erlang’s bit syntax are really impressive, which are able to parse binary data, e.g., TCP streams, in a clear and concise manner.


Generators are first-class coroutines, represented as objects encapsulating suspended execution contexts (i.e., function activations). In reality, generators can be seen as a useful idiom in using coroutines. For instance, generators can be used to implement the “infinite” sequence of Fibonacci numbers:

function fibonacci() {
  let [prev, curr] = [0, 1];
  for (;;) {
    [prev, curr] = [curr, prev + curr];
    yield curr;

Generators can be iterated over in loops:

for (n of fibonacci()) {
  // truncate the sequence at 1000
  if (n > 1000) break;

Generators are iterators:

let seq = fibonacci();
print(;  // 1
print(;  // 2
print(;  // 3
print(;  // 5

Deferred Functions

Asynchronous programming is very hard in ECMAScript host environments which are typically single threaded and use callbacks for operations which may take a long time like network IO or system timers. For example:

function animate(element) {
  let i = -1;
  function continue() {
    if (i < 100) { = i;
      window.setTimeout(continue, 20);

However, pausing execution for long periods is undesirable. Deferred functions allow you to write asynchronous non-blocking code without writing callback functions, which don’t compose well. With deferred functions, you can use control flow constructs that you’re used to, inline with the rest of your code.

function deferredAnimate(element) {
  for (let i = 0; i < 100; ++i) { = i;
    await deferredTimeout(20);

Rest Parameters and Spread Operator

Reset parameters allows your functions to have variable number of arguments.

function push(array, ...items) {
  items.forEach(function(item) {

The spread operator is like the reverse of rest parameters, which allows you to expand an array into multiple formal parameters.

function push(array, ...items) {

function add(x, y) {
  return x + y;

var numbers = [4, 38];
add(...numbers);  // 42


Many other features are not listed here since they have been already implemented, though rarely used or even seen, in languages such as Scala or Haskell. I think they are all very useful and essential for skilled programmers and will ease the burden of more and more complicated programming tasks.


This article, along with any associated source code and files, is licensed under The Creative Commons Attribution-Share Alike 3.0 Unported License


About the Author

Student Shanghai Jiao Tong University
China China
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 13 Aug 2011
Article Copyright 2011 by stfairy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid