VMWare Fusion has a “shared folders” feature which allows you to
seamlessly share folders on the host Mac system with the virtualised
guest OS. With a Linux guest, vmware-tools will install the
“Host-Guest File System” (hgfs) driver and add an entry to
/etc/fstab to automagically mount all shared folders under
/mnt/hgfs.
This is great, but unless your user id in the Linux guest happens to
match your user id OS X, you will not be able to access the mounted
directories as a regular user. Luckily, you can get the hgfs driver to
mount the shared folders as your user. Edit /etc/fstab as root:
$ sudo vi /etc/fstab
and look for a section like:
# Beginning of the block added by the VMware software
.host:/ /mnt/hgfs vmhgfs defaults,ttl=5 0 0
# End of the block added by the VMware software
Add options for uid and gid:
# Beginning of the block added by the VMware software
.host:/ /mnt/hgfs vmhgfs defaults,ttl=5,uid=1000,gid=1000 0 0
# End of the block added by the VMware software
The values I’ve used, 1000 for uid and gid, are the defaults for the
first user created on an Ubuntu desktop install. To find the correct
values for your user, run the id command in the guest OS:
$ id
uid=1000(mrowe) gid=1000(mrowe) groups=...
Recently, my friend Gav wrote about using STL to filter a vector of
values in C++ in which he explained a surprising gotcha. I’m sure
he knows what he’s talking about, but it struck me how ugly this
(presumably idomatic) code was. So I figured I’d see what it would
look like in a few more “modern” languages:
Ruby
>> numbers = 1..9
=> 1..9
>> numbers.reject { |n| n.even? }
=> [1, 3, 5, 7, 9]
Or, if you skip the separate assignment of the input data:
>> (1..9).reject { |n| n.even? }
=> [1, 3, 5, 7, 9]
Python
>>> numbers = range(1,10)
>>> [n for n in numbers if n % 2]
[1, 3, 5, 7, 9]
or
>>> [n for n in range(1, 10) if n % 2]
[1, 3, 5, 7, 9]
user=> (def numbers (range 1 10))
#'user/numbers
user=> (filter odd? numbers)
(1 3 5 7 9)
or
user=> (filter odd? (range 1 10))
(1 3 5 7 9)
Yeah, I get that this wasn’t the point of the original post—sometimes
you’re just stuck with C++. But if you do have the choice, other
languages can be far more expressive for this common kind of list
processing.
If you have examples in other languages (or improvements to my
efforts) send them in and I’ll post them here.
Update: From Julian Doherty:
Erlang
1> Numbers = lists:seq(1,9).
[1,2,3,4,5,6,7,8,9]
2> [X || X <- Numbers, X rem 2 =/= 0].
[1,3,5,7,9]
Update: From Ben MacLeod:
C#
using System;
using System.Linq;
// ...
var numbers = Enumerable.Range(1, 10).Where(n => n % 2 != 0);
// or, equivalently:
//var numbers = (from n in Enumerable.Range(1, 10) where n % 2 != 0 select n);
foreach(var number in numbers) {
Console.WriteLine(number);
}
// ...
Update: From John Carney:
PHP
5.2
function not_even($x) {
return $x & 1 ;
}
$numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9) ;
$numbers = array_filter($numbers, "not_even") ;
5.3
$numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9) ;
$numbers = array_filter($numbers, function($x) { return $x & 1 ; }) ;
Bash completion, the magic that allows you to start typing the name of
a file, directory, etc. in bash then press TAB to complete it, can be
taught new tricks, including knowing about your git repository. But if
you’re on a Mac, the magic is not installed by defaut.
If you are running git from MacPorts, you probably don’t have the
bash_completion variant installed. You can install it with:
sudo port install git-core +bash_completion
If you do already have git installed without this variant, you’ll
probably need to deactivate it first:
sudo port deactivate git-core
Then reinstall with the variants you need:
sudo port install git-core +bash_completion +gitweb +svn +doc
You can then activate completion by adding the following to your
~/.bash_profile:
if [ -f /opt/local/etc/bash_completion ]; then
. /opt/local/etc/bash_completion
fi
Thanks to Denis Barushev for this tip.
A couple of weeks ago I attend the JAOO 2009 conference in
Brisbane. What follows is a biased, incomplete and probably misleading
account of my impression of the two days.
Keynote
I always assumed conference keynotes were meant to be broad, sweeping
and inspiring. This one was narrow, technical and delivered in a
mind-numbing monotone. Maybe it’s just the way they do things now?
Introduction to Objective-C
This was clearly targeted at people who have no exposure to
Objective-C, but rather than just being a dry survey of the language
syntax and libraries, Glenn Vanderburg provided a nice historical
overview of the Objective-C and its heritage.
My take away: Objective-C is basically SmallTalk, and SmallTalk is
basically Lisp.
Google App Engine: Building an App the Google Way
Pamela got rave reviews in Sydney, and she’s certainly an entertaining
speaker. If you’d never heard of GAE, or never looked at its
capabilities, this would have been a very good introduction. I’ve
built a couple of small GAE apps though (in Python), and other than
seeing the Java version of some of the APIs, this talk really told me
nothing new.
1,001 Iterations: Product Design, Illustrated
This was a recounting of the process Avi Bryant went through
taking a new idea from its inception through many refinements to a
polished product.
Perhaps most the interesting part for me was Avi’s assessment of the
relative strengths of the various languages he ended up using to
implement the product:
Squeak - for “thinking” in (i.e. the interesting problems and
their solutions)
Java - for nuts-and-bolts computing (crunching numbers)
Ruby - for interfacing with external libraries and APIs (e.g. twitter)
JavaScript - for interacting with the user
I’m not sure it’s always a good idea to mix so many technologies in
the one product, but it certainly makes some sense to not get hung up
on the One True Language, and just use each where they’re best suited.
Speeding Ducks
Avi again. Much more technical this time. Avi’s main point: Ruby
really is slow, but there’s no reason it has to be.
He began with an interesting history of Java’s Hotspot VM, which was
based on technology developed for SmallTalk and Self in the 1980s. But
Google’s V8 was built by three people in about 3 months—surely we
can do the same for ruby!
At the end of the talk, Avi was challenged by Joshua Bloch. Josh
disputed Avi’s claim that because V8 was built in three months, all
optimising “hotspot” VMs should be easy to build. Java’s current VM
has been constantly improved over many years, and solves many
non-trivial problems.
Of course, this sort of interaction between notable figures in our
industry is exactly why you go to conferences like JAOO.
Hey You! Get On To My Cloud! - Application Development in the Clouds
Dave Thomas gave us some thought provoking ideas about current
languages development platforms. Is JavaScript the way of the future?
I’m not so sure, but I think one of Dave’s main points is worth paying
attention to: functional programming is the way forward if we want to
improve the speed with which we can build software.
Atlassian
Mike Cannon-Brookes gave us a bit of background of Atlassian’s
history (they’ve gone from two people and one product to nearly 100
engineers and ten products in eight years), then listed what he
thought were the ten key practices that have made them successful.
I’ll excerpt just the ones I think are worth talking about, and add my
thoughts (not necessarily agreeing with Mike):
Agile - it’s the principles that are important, not any
particular methodology or set of tools
Code review - there’s plenty of hard evidence that code
review/inspection is one of the best ways to reduce the number of
defects in software. Of course, pairing is the ultimate form of
code review.
Optimise tests - the main goal: get feedback to developers as fast
as possible. Some of the things Atlassian do to achieve this
include selectively running only tests that could possibly be
affected by a code change (by doing static analysis on coverage),
and splitting functional tests into parallel builds.
This is a common problem—functional test suites that take so long
to test an application that the pipeline from code check-in to the
“you broke the build!” feedback can be hours. Atlassian’s solution
is to split the tests into chunks that run in a maximum of ten
minutes, and have enough build agents to run all the chunks in
parallel.
Put everything in a wiki. Yeah, they would say that, wouldn’t they?
:-)
“Dev speed posse” - Atlassian have a small team that spend a fixed
amount of time every week just focusing on removing things that
slow down development. This is a great idea (although not one
that’s unique to Atlassian), and something more organisations
should consider. One of the more interesting goals they have is
that the “checkout loop” (the time it takes a developer to go from
a clean machine to having a checked out app running locally and
ready to work on) should be no more than ten minutes. How many
large development shops can achieve that?
Josh Bloch - Effective Java
This was basically a summary of some of the new things in the second
edition of Effective Java. About a third of the talk was all about
generics. Good grief. Surely someone has noticed by now that this has
all gone horribly wrong.
“Concurrency is hard” - even if you use the right APIs (for example,
always use ConcurrentHashMap not Collections.synchronized*()) it’s
still easy to get it wrong. Read Brian Goetz’s Java Concurrency in Practice.
And finally: Serializable is bad, since it allows objects to be
created without using constructors. This can lead to invariants and
other assumptions being violated. Josh says to use serialization
proxies instead.
Doug Crockford on JavaScript
One of the classic Doug Crockford JavaScript talks. Probably nothing
new if you’d listened to his talks from Yahoo’s YUI Theater, but
still well worth spending 45 minutes listening to in person.
Some of Doug’s comments, observations and tips:
JavaScript has widest range of user programming skills of any
language, from computers scientist to cut-and-pasters
JavaScript has many influences, including: Self (prototypes,
dynamic typing), Scheme (lambda, loose typing), Java (syntax), Perl
(regexps)
it is commonly being used as a functional language—you’ll write
better JavaScript if you think functionally
eval is the most misused feature - just don’t do it!
always use ===. You’ll be tempted to use == instead, but it’s
broken—it causes type coercion, which leads to unexpected and
buggy results
manage the divide between client and server (don’t recreate the
server in the browser)
Software Visualization and Model Generation
Eric Doernenburg is a consultant at ThoughtWorks, and I’d heard him talk before
about some of the cool code visualisation tools he’s put together. The
basic idea is that by visualising certain attributes of a code base,
it’s much easier to focus on the trouble spots without getting lost in
the detail of thousands of lines of code.
Interestingly, Eric uses both common tools (e.g. CheckStyle) and the
more exotic (CodeCrawler, CodeCity). Those last two are more
or less self-contained, but Eric does really cool things with
CheckStyle and Graphviz, and a bit of XSL to glue them together.
As a general approach, use whatever analysis tool is closest to what
you need, then map the output into a format your visualisation tool
can read.
Smart Software with F#
An overview of, and small sample app, in F#, Microsoft’s functional
language for the CLR. The main message:
Both of which apply to any functional language of course.
You try to give Microsoft people the benefit of the doubt… but Joel Pobar,
despite obviously being very knowledgeable about F# and
functional programming, still managed a couple of clangers. Most
egregious: he called python an “elementary imperative language”. Fair
enough if your background is Visual Basic and you’d never heard of
functional programming… but this guy is the F# expert.
Anyway, it was good to see a bit of F# in action. If it gets more
people thinking about functional programming, great. But it doesn’t
offer anything you can’t get in Clojure, SmallTalk, Scheme, etc.,
unless you’re stuck in the Microsoft ecosystem.
Overall, a great couple of days. I learnt new things and expanded my
mind about things I already knew. I hope to go again next year, and
hopefully it will come to Melbourne!
When you’re writing or coding, you want to remove as many distractions
as possible. In addition to obvious things like shutting down you
email, IM and twitter clients, it can be helpful to put your editor in
full-screen mode. This way, the editor is the only thing visible, so
your attention isn’t drawn to menu bars, flashing notifications or
bouncing dock icons.
To create a shortcut for fullscreen mode in emacs, put this in your
~/.emacs file:
(defun toggle-fullscreen ()
(interactive)
(set-frame-parameter nil 'fullscreen (if (frame-parameter nil 'fullscreen)
nil
'fullboth)))
(global-set-key [(meta return)] 'toggle-fullscreen)
Now pressing M-return (usually alt + return on Windows/Linux or ⌘
+ return on a Mac) will toggle Emacs between normal and full screen
mode.
Thanks to Vebjorn Ljosa in this thread for this code snippet.
I have a new job, and contrary to what I’ve said previously, it’s
at a consulting company. With a differnce.
Cogent is a consulting company, but with ambitions to be a
product company. In fact, I’ve spent my first few weeks here working
on our first publicly available product, Runway. (Runway is a
task management app that supports the principals of Getting Things
Done®.)
I’m really excited to be here. Cogent has an explicit goal of treating
its employees and its customers humanely. It’s very open and free of
bureaucratic nonsense. And it’s full of really smart people—although
the average probably just went down bit… :-)