As an exercise in trying out Julia, I've implemented a function to compute AWS Version 4 Authentication headers (attached).
The Julia code runs in 7887ms seconds vs 124ms for the Tcl code.
Google tells me that there is a heavy start-up penalty in Julia for importing modules.
Some other observations:
- It took quite a bit of digging to select from the multiple available packages for SHA256, Dates, HTTP URIs, etc... If would be nice if things as basic as this were included in an "official" library of some sort.
- Many of the package on http://pkg.julialang.org seem to be of far lower quality than Core and Base. It is great to have a place to share quick hacks and starting points for collaborative development, but as an engineer trying to get things done to a deadline, it would be great if there was a clear distinction between solid packages and works-in-progress.
- Tcl's dicts preserve insertion order for iteration. This has very little overhead and is really nice in many situations.
- I got confused about why I could not use the Base string() function without using the full name Base.string(). It turned out that I had a local variable lower down in the function called "string". The error message did not help me find this problem. It took quite a bit of trial and error to figure it out. In Tcl there is no name-clash between function names and variable names. I understand why there is a clash in Julia, and I like that functions are first-class data objects, I guess I just have to think more about name clashes when I choose variable names.
- I was surprised that I could not do sort(keys(dict)). So I added: sort(i::Base.KeyIterator) = sort([k for k in i]). It is a really nice feature than I
can do this without editing some system library source code (Tcl handles this nicely too).
- It is a little disappointing that I can't implement @set(var_name, value) for local variables. This is a pretty big hole in the claim that meta-programming is supported. However, I can work around it. (A common pattern in my Tcl code is to unpack the contents of a dict into local variables.) It seems pretty arbitrary to allow assignment by name in the global scope, but not in the local scope. Smells like "harder to implement".
- I don't understand why I have to provide a default value for named arguments. I understand why only positional arguments take part in dispatch decisions. I understand why there are no defaults for positional parameters (just add another method). But it seems that there is no benefit in insisting that named arguments have defaults. If there is a missing parameter, I want a "missing parameter error".
I've been using Tcl for production work since 1995.
I have taken time out to learn a few new-fangled high-level languages along the way (perl, lua, python, eiffel, java, javascript etc). However, I keep going back to Tcl. Julia is the first language I've tried where I'm not finding lots to dislike. (I assume the startup performance issues can be fixed easily by caching compiled code).
Regards,
Sam O'Connor
Sam-OConnors-MacBook-Pro-17:scratch sam$ time ./aws4_test.jl
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/iam/aws4_request, SignedHeaders=content-md5;content-type;host;x-amz-content-sha256;x-amz-date, Signature=1a6db936024345449ef4507f890c5161bbfa2ff2490866653bb8b58b7ba1554a
Content-MD5: r2d9jRneykOuUqFWSFXKCg==
Content-type: application/x-www-form-urlencoded; charset=utf-8
host: iam.amazonaws.com
x-amz-content-sha256: b6359072c78d70ebee1e81adcbab4f01bf2c23245fa365ef83fe8f1f955085e2
x-amz-date: 20110909T233600Z
real 0m7.687s
user 0m7.720s
sys 0m0.324s
Sam-OConnors-MacBook-Pro-17:scratch sam$ time ./aws4_test.tcl
Authorization: AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20110909/us-east-1/iam/aws4_request, SignedHeaders=content-md5;content-type;host;x-amz-content-sha256;x-amz-date, Signature=1a6db936024345449ef4507f890c5161bbfa2ff2490866653bb8b58b7ba1554a
Content-MD5: r2d9jRneykOuUqFWSFXKCg==
Content-type: application/x-www-form-urlencoded; charset=utf-8
host: iam.amazonaws.com
x-amz-content-sha256: b6359072c78d70ebee1e81adcbab4f01bf2c23245fa365ef83fe8f1f955085e2
x-amz-date: 20110909T233600Z
real 0m0.124s
user 0m0.098s
sys 0m0.022s