Contact Info

(for those who care)

Instant Gratification   



Thu, 20 Oct 2011

“If you would build a ship don’t drum up men to gather wood, divide work and give orders. Instead, teach them to yearn for the endless sea.”

12:43 CST | category / entries / tweets
permanent link | comments?

Wed, 19 Oct 2011

Programming Language Roundup

I guess it’s on everybody’s mind lately, but here is an excellent overview of “new” languages to come out in the past few years. Definitely a lot more than I thought there were at first.

In this post I will provide a list of fairly new languages (let’s say 5 years with a little flex) that display interesting features and display higher-order thinking in the way that they tend toward an evolution of past learnings in programming language thinking.

[source…]

The one that sticks out to me is Shen which has a few very interesting features.

Taking a look at each point in turn, once you get past the parenthesis, lisp syntax is very cool. If you try to do a good job of following functional / immutable / transormative programming you end up changing the way you write code.

// procedural style
var abc = 6;
double( abc );
triple( abc );
assert( abc == 36 );

// functional style
var abc = 6;
var def = double( abc );
var result = triple( def );
assert( 36 == result );

// "clean" functional style
var result = triple(
                 double( 6 )
             );
assert( 36 == result );

Obviously the above is a contrived example (to be even “cleaner” you would do away with the temporary “result” variable), but you can see that as you get “more functional” you naturally tend to collect parenthesis, no matter the language you are working in.

The “pattern matching” aspect that I really liked from ML is pretty much syntactic sugar for if / else or case / switch but built in to the language.

I find that I’m often writing code like this:

// old style
function foo( a, b ) {
    if ( 1 == a ) {
        alert( 'foo ' + b );
    }
    else if ( 2 == a ) {
        alert( 'bar ' + b );
    }
    else {
        alert( "unknown action: " + a );
    }
}

// new style
function foo( a, b ) {
    var mapping = {
        1: function( b ) { 
              alert( 'foo ' + b );
           },
        2: function( b ) { 
              alert( 'bar ' + b );
           },
    }

    if ( mapping.hasOwnProperty( a ) ) {
        mapping[a]( b );
    }
    else {
        alert( "unknown action: " + a );
    }
}

// "better" new style
function foo( a, b ) {
    var mapping = {
        1: doAlertWithFoo_ref,
        2: doAlertWithBar_ref
    }

    if ( mapping.hasOwnProperty( a ) ) {
        mapping[a]( b );
    }
    else {
        alert( "unknown action: " + a );
    }
}

// "hypothetical" pattern-matching style
function foo( 1, b ) {
    alert( 'foo ' + b );
}
function foo( 2, b ) {
    alert( 'bar ' + b );
}
function foo( a, b ) {
    alert( "unknown action: " + a );
}

Again, an extremely contrived example, the point being that you treat conditionals as mappings instead of bare if/else clauses. Then, the only bugs you can have are “I am missing a mapping” or “My mapping is criss-crossed” or worst “My target action is buggy”.

The pattern-matching aspect of a language makes it easier (supposedly!) to reason about functions. Instead of having to read inside a function to determine how it behaves (for many if/else cases), you can promote that to the top level of function definition (in the above, read function foo( 1, b ) as: when foo is called with 1 as the first parameter).

The coup de grâce for me though is the inclusion of a version of Prolog core within the language. In the same way that regexes make string processing a million times easier, prolog makes logic processing a million times easier. And who would have thought… but logic processing turns out to be a useful thing to optimize from time to time.

You’ll have to bear with me on this one because it’s a little harder to explain. But let’s say we have a computer.

 def isComputer( x ):
    return x has memory and x has cpu and x has hard_drive

 def 4gig_o_ram is memory
 def 2gig_o_ram is memory
 def 1gig_o_ram is memory

 def amd_chip is cpu
 def intel is cpu

 def seagate is hard_drive
 def western_digital is hard_drive

 my_computer = 4gig_o_ram and intel and western_digital

 def canRunWindowsVista( x ):
     isComputer( x ) and has 4gig_o_ram

 canRunWindowsVista( my_computer )?
 => true

Again, a really contrived, terrible example with incorrect syntax. But the idea is that you set out the facts and you let the computer (90% of the time) figure out all the boring crap of making sure your arbitrary constraints aren’t violated.

You run into this problem All. The. Time. when working with config files, validating function parameters, determining if a user has permission to perform an action, etc, etc, etc. Regexes are very information dense around a well-defined problem. “Prolog” is a bit more verbose around problems that you define yourself, which is my theory as to why there has never been a “like-a-regex-but-for-prolog” included in any languages.

I can tell you it excites me to see this Shen project try. Definitely worth paying attention to.

00:52 CST | category / entries
permanent link | comments?

Tue, 18 Oct 2011

Interesting #bash tip instead of sed: … | while read ; do echo $REPLY ; done http://stackoverflow.com/questions/1670577/indenting-bash-script-output/1670632#1670632

14:27 CST | category / entries / tweets
permanent link | comments?

Mon, 10 Oct 2011

On “Go” and “Dart” - Google Wants You

Inspired by Mr. KrestenKrab, I feel obligated to comment on Google’s language development activities.

Posit. They’ve released “Go” and “Dart” which are improvements to the “C-style” and “Javascript” languages respectively.

Posit. They’ve released GWT which is “Javascript for Java-devs” and they’ve mucked with “fixing” both Python and Java to run in a sandbox / secure environment.

Oh, and I almost forgot they’ve implemented a Javascript engine in V8.

Publicly they’ve talked about their internal tooling capabilities when working with source code (bytecode inspection, singleton detection, the ability to focus unit tests on potentially impacted code based on what lines were changed in a file / diff).

Unfortunately I don’t have all the references handy, but if you pay close attention to what google is doing, you begin to see that they are most definitely on the “other side” of the bell curve from most people in their ability to navel-gaze at their product code.

There are a lot of people who are slamming google and I can’t tell if it’s because they think it’s the cool thing to do, or they don’t understand what they’re doing, or maybe it’s because they are afraid of change?

I can’t tell what it is, but from my perspective, Google’s moves are interesting and fairly transparent.

Obviously they’ve written a lot of code and have a bunch of engineering talent. They’ve also spent a lot of time “cleaning up” other languages / language implementations (javascript-v8 / java-gae / python-gae). They also appear to have taken a hard look at their own code and found areas where C/C++ makes things difficult, as well as that red-headed stepchild: Javascript.

You might also have noticed that each of Go and Dart have “shipped” with online / live compilers exposed to the internet, pretty much from day one. That speaks volumes to their confidence in their ability to lock down the code for use with untrusted input.

Go and Dart both appear to be fairly pragmatic languages, focused on making it easier to write correct programs.

From the Go FAQ:

Go is an attempt to combine the ease of programming of an interpreted, dynamically typed language with the efficiency and safety of a statically typed, compiled language. It also aims to be modern, with support for networked and multicore computing. Finally, it is intended to be fast: it should take at most a few seconds to build a large executable on a single computer. To meet these goals required addressing a number of linguistic issues: an expressive but lightweight type system; concurrency and garbage collection; rigid dependency specification; and so on. These cannot be addressed well by libraries or tools; a new language was called for.

[source…]

From the Dart FAQ:

Create a structured yet flexible programming language for the web.

Make Dart feel familiar and natural to programmers and thus easy to learn.

[source…]

…and from their leaked document, you’ll also hear that Dart was designed to allow for more complete “tooling” (right-click => refactor) as a design goal compared to the 4-5 “basic” ways that javascript supports classes (bare objects, constructor functions, prototype inheritence, module pattern, etc, etc.).

So… why have Go and Dart “leaked” from the lab into the real world?

This is the interesting part of the Google story. In my day job, I regularly rail on people for inventing dumb libraries, NIH and the like. Right now I’m using a unit test library for perl that is in use nowhere else outside of my company.

The question I always ask: “Can I buy a book on it?” Followed immediately by: “Why is this different than what the blogs are telling me to do?” and “How long would it take somebody to ramp up if I hired them off the street?”

Sometimes there is a good reason, but more often there aren’t good answers to those questions.

So Google’s a smart company, and I’m a smart guy. That means that Google has some of those same concerns. Even if the new languages that Google has put together are materially better than the other languages out there, it still doesn’t help Google until outside people start using them.

They’ve already pushed Guice, GWT, their Java / C development standards, their testing blog, map reduce, everythingmany things they’ve learned internally they’re trying to share with the outside world so that it isn’t quite as big of a shock when fresh meat enters the grind.

If you look at how the existing programming languages were made, they each grew on a strong base (C++ on C. Java on C++. PHP on Perl [heh]. Python on Basic.) and tried to make incremental improvements yet be fundamentally “better” taking into account the shared experience that only real-world use can give.

I think that Google is following in the same tradition, and given their internal experiences, only a fool would dismiss it out of hand.

It was (kindof?) a stroke of genius when Yahoo! ditched their internal template system for PHP. I’m sure it had a profoundly positive impact on their hiring productivity “Oh, you know the most popular web scripting language? Good, that’s the one we use.”

In the same way, if we assume that Go and Dart are in fact materially improved languages (especially if they are materially better inside of Google), it is in Google’s vested interest to get as many people as possible using it. The more someone knows before joining a company, the lower their training costs are, the higher their productivity.

Their focus with these languages (at least with Go) appear to be laser-like on reliability, ease of programmer use, and ease of inspection / whole program manipulation.

I think that the leaked memo for Dart forced Google’s hand to get something out there quicker than they really wanted. I also think that looking at Dart briefly it would benefit from similar “bold changes while in flight” as they have made to Go based on community feedback (the basic one for Dart they’ve screwed up is not tagging functions with a simple keyword- “def / sub / func / function” so you can grep for things).

Go has been out for approximately two years (November 2009) and they are closing in on their own “Go 1.0” release and have made significant changes to the language during that process.

It will probably be a while before Dart reaches anywhere near the same relevance as “Go” has (which is to say: not that much outside of Google), but I have high hopes, especially if they steward the project well.

Based on the evidence of Go’s evolution and apparent benefits over C, I would hope that Dart follows a similar path. For Google, I assume it will see a lot of use (and quickly!) because they already support cross compiling to Javascript (GWT) and already have a cross-compiler from Dart to JS.

It is not surprising that Google has released these languages. As a matter of fact, they are just following with the tradition of corporations releasing languages they’ve invented and found useful (Erlang=>Ericcson, C=>Bell Labs, Java=>Sun, lots more programming language origins) but what is surprsing is that there are now so few Universities involved in advancing the state of the art in programming.

I wonder if we are entering a “new era” of Computer Science where pragmatism trumps expressing algorithms, or if they have somehow (necessarily) merged into one but now with corporations driving the bus.

21:14 CST | category / entries
permanent link | comments?

Wed, 05 Oct 2011

Did you know that translate.google.com does an excellent job, especially if you “help it” by looking up its alternate translations? #boggled

10:03 CST | category / entries / tweets
permanent link | comments?

Like what you just read? Subscribe to a syndicated feed of my weblog, brought to you by the wonders of RSS.



Thanks for Visiting!