Wasted keystrokes in popular languages

After looking more into Scala, Coffescript and Go, I wish other programming languages were more terse. It's easier to like a language that saves me keystrokes.

Steve Yegge wrote about the next big language in 2007 and opined that it would have to C-like syntax in order to be popular. He's probably right. But I hope we can shave off a few key-strokes here and there.

Andrew's Top Verbosity Annoyances:

1. Having to explicitly assign fields from constructor params. e.g.
// Javascript (fail)
function MyClass (param) { this.param = param; }

// C++ (fail)
MyClass(int param) : param(param) {}

// Java (fail)
MyClass(int param) { this.param = param; }

// Coffeescript (better)
class MyClass
  contructor (@param) ->

// Scala (win!)
class MyClass (param: Int)

// Go (win!)
struct MyClass {
  param int
}

2. Getters and setters. One pro of getters and setters is you can separately control access to reads vs. writes... but I rarely care. You could also choose to enforce invariants in your setters... sometimes nice, but I prefer to put validation elsewhere.

Net: I'd like to see less of this in NBL:

private int param;
public void setParam(int param) { this.param = param; }
public int getParam() { return this.param; }

I think Go is off on the right foot with "capitalize to export". I hope programmers will decide there are cases it's okay to access a field directly instead of creating the next generation of getter/setter bloat.

Scala also saves you keystrokes by making getters and setters implicit, but gives you the option to add an explicit setter if you need it. Smart!

3. Workarounds for not being able to return tuples. i.e. Something other than...

public static class MyReturnValue { public int x; public int y; }
public MyReturnValue doSomething() { ... }
// Or ...
public doSomething(Foo outputParam1, Foo outputParam2) { ... }

Scala, Go and Coffeescript all support multiple return values. Tuples aren't something I miss every day, but they're a definite nice-to-have.

Leave a comment

Recent Entries

  • WebGL Rogue-like

    This game/demo tickles me in a couple ways. I love Rogue-like games. I used to love playing them, now I appreciate them more as a...

  • Wasted keystrokes in popular languages

    After looking more into Scala, Coffescript and Go, I wish other programming languages were more terse. It's easier to like a language that saves me...

  • Guy roller skates down roller coaster

    The craziest thing about this video is that it only has 100K views.http://www.youtube.com/watch?v=k_pu7xDuJYA...

  • Trine game review

    I downloaded the Mac App Store a couple days ago and bought Trine--a clever, physics puzzle adventure with an RPG-twist. You play a thief, a wizard...

  • ShoppyBag

    News flash! Your friend did not tag you in a photo at Shoppy Bag. Don't click the link in the email....

Close