Erlang Error Messages

When a run-time error occurs,
that is an exception of class error,
the exit reason is a tuple {Reason,Stack}.
Reason is a term indicating the type of error:

Exit Reasons.
Reason Type of error
badarg Argument is of wrong type.

badarith

Argument is of wrong type in an arithmetic expression.

{badmatch,V}

Evaluation of a match expression failed.
The value V did not match.
function_clause

No matching function clause is found when evaluating a
function call.
{case_clause,V} No matching branch is found when evaluating a case
expression. The value V did not match.

if_clause

No true branch is found when evaluating an if
expression.
{try_clause,V} No matching branch is found when evaluating the
of-section of a a try
expression. The value V did not match.
undef The function cannot be found when evaluating a function
call.
{badfun,F} There is something wrong with a fun F.
{badarity,F} A fun is applied to the wrong number of arguments.
F describes the fun and the arguments.
timeout_value The timeout value in a receive..after expression is
evaluated to something else than an integer or
infinity.
noproc Trying to link to a non-existing process.
{nocatch,V} Trying to evaluate a throw outside a catch.
V is the throw term.

system_limit A system limit has been reached. See Efficiency Guide for
information about system limits.

Stack is the stack of function calls being evaluated
when the error occurred, given as a list of tuples
{Module,Name,Arity} with the most recent function call
first. The most recent function call tuple may in some
cases be {Module,Name,[Arg]}.

Digital Typography and @font-face

  • Typography (along with layout) is one of the two basic elements of design.
  • You currently cannot pick a typeface for your website without using graphics. Many excellent designs therefore use images for all headings.
  • Domestic broadband has reached up to 80% penetration in some countries. It is over 50% in many countries. In commercial organizations it has a much higher penetration. Jakob Nielsen says, “100KB is certainly a reasonable page weight for fast downloads” in ‘Proritizing Web Usability’ (p. 87).
  • TrueType fonts range in size from about 10KB to about 100KB (gzipped even smaller). Most web pages carry images that are of similar size.
  • CSS 2.0 defines the @font-face command that explains how a user agent should download a font where required.
  • @font-face was removed from CSS 2.1 because of a lack of support in existing user agents. (No major web browser implements it apart from support limited to .eot files in Internet Explorer). It is back in CSS 3.0.
  • It is a Mozilla FAQ to ask why Firefox doesn’t support downloadable fonts. But the reply concerns unicode and support for non-Latin characters rather than design/typographical issues. Nonetheless, support for @font-face does not seem to be on the Mozilla roadmap.
  • Support for downloadable fonts is not the only thing needed to bring print-like type to the web. Current screen resolutions of 72dpi are much less than the 300 dpi or much more of the printed page.

Does anyone know why implementing @font-face seems to be such a low priority for makers of web browsers?

Not So Popular

My experiment in thresholding del.icio.us has not proved entirely successful.

It turns out that the links that are really, really popular are actually the bad ones. So I’ve added a new feature to my del.icio.us RSS feed.

You can now add a parameter to the feed URL to put a maximum (instead of a minimum) on the number of votes for an item to be included like this:

http://bluebones.net/very-popular/rss/?threshold=50&minor=true

Meanwhile, Jon Aquino (who wrote the brilliant yubnub) has created descriptious which tries to give a bit more information about each link in the feed.

Stock Ticker Feed

Stock Ticker Feed Screenshot

A few years ago Yahoo created beta stock ticker RSS feeds. Then they withrdrew them and they haven’t been heard of since. They have provided CSVs of their data for a long time. So I’ve turned the CSVs into RSS feeds. The address is like this:

http://bluebones.net/ticker/feed/?s=SYMBOL

Where SYMBOL is something like KO (for Coca Cola).

One other minor feature is that you can get localised times by adding &n=uk (or es or fr or any other country code that has a Yahoo! Finance). So for example to get Vodafone’s share price with UK times use:

http://bluebones.net/ticker/feed/?s=VOD.L&n=uk

You might want Yahoo’s symbol lookup.

I just knocked this up very quickly so it may be buggy. If you use it, or find a problem, leave me a comment.

ssh – My Setup

This is the shell script I use as my alias for ssh:

#!/bin/bash
ssh-agent
ssh-add
case $1 in
    marge* ) SSHCOLOR=1 ;;
    bluebones.net ) SSHCOLOR=1 ;;
    barney* ) SSHCOLOR=7 ;;
    lisa* ) SSHCOLOR=6 ;;
    homer* ) SSHCOLOR=3 ;;
    * ) SSHCOLOR=5 ;;
esac
if [ $1 ] ; then
    tput setab $SSHCOLOR
    \ssh $*
    tput setab 9
else
    echo "Usage: $0 [HOST]"
fi

The background colour shows me at a glance which machine I am on.

Five Programming Languages You Really SHOULD Learn Right Now

eweek.com’s article on ten programming languages you should learn right now is the most ill-informed pieces I’ve read in a while. Here’s my (hopefully better) attempt.

Five Programming Languages

  1. Scheme. If you come from a “curly braces” background you should learn a functional language. As Eric Raymond says about the very similar Lisp:

    LISP is worth learning for a different reason — the profound enlightenment experience you will have when you finally get it. That experience will make you a better programmer for the rest of your days, even if you never actually use LISP itself a lot.

    I prefer Scheme because it is purer (no need for funcall).

  2. Erlang. Another functional language. Concurrency done right. In the multiprocessor future this could be very important indeed.

  3. Ruby. A conscious attempt to make a programming language that is a joy to use. String handling from Perl, OO from Smalltalk, closures from Lisp/Scheme.

  4. Javascript. The only way to create a rich UI in current web browsers.

  5. C. For when things must be fast. Use with Ruby, Python and many other languages when you need to optimize a section of your code for performance.

C, Ruby and Javascript are on the original eweek list. As for the other seven on there:

Maybe

PHP – Quick and dirty. Yes, it’s quick, but it’s dirty.

Python – Dynamic, fairly intuitive, list comprehensions are great. But explicit self? No ternary if? Significant whitespace? The OO feels tagged on.

No

VB.NET – Hidebound, moribund offering from equally hidebound and moribund company. Plus it is inferior to it’s sibling C# in every conceivable way.

C# – Java with a little extra syntactic sugar. Not worth paying the Microsoft price for.

Perl – Somewhat deserved reputation as “write only”. Other languages (Ruby) have absorbed the lessons of perl (mainly – have brilliant regex support) and moved on. Once important, but less so every day.

Java – Bruce Tate wrote “Bitter Java” (2002), then he wrote, “Better, Faster, Lighter Java” (2004), then he wrote, “Beyond Java” (2005). You get my point.

Agree? Disagree? Think I’m a lunatic? Make a comment!

PHP Google Site Search

Google’s free site search is better and easier to setup than anything you can host on your own server. However, the “branding” allowed doesn’t really go far enough. You want your search results to look like the rest of your site. And the search results URL should be on your server, not Google’s.

To solve this problem I have written a simple site search in PHP that uses the Google Search API behind the scenes to give you Google’s search, but your site’s look and feel.

Download PHP Google Site Search (165KB).

von Neumann on Programming

  1. Conceptualize the problem mathematically and physically and give a rigorous but perhaps implicit set of equations describing it.
  2. Select a numerical algorithm, that is, an explicit arithmetical procedure (which may be approximate) to replace these rigorous mathematical expressions.
  3. Do a numerical analysis to estimate the precision of the approximation process by means of an investigation of the role of errors introduced by the procedure (truncation errors) and by the machine (round-off errors).
  4. Determine the scale factors so that the mathematical expressions do not assume values that fall outside the fixed range of the computer at any time during the course of the computation.
  5. Do the dynamic analysis by drawing a flow diagram.
  6. Write the static code and enter it into the machine.

Description of programming from ‘Planning and Coding of Problems for an Electronic Computing Instrument’ by Goldstine and von Neumann, 1947-48. Quoted in ‘John von Neumann and the Origins of Modern Computing’ by William Aspray (MIT Press, 1990).

von Neumann on Software Patents

‘ … they are a commercial group with a commercial patent policy. On the basis of the information before me, I have to conclude that we cannot work with them directly or indirectly, in the same open manner in which we would work with an academic group which has no such interests. I certainly intend to do my part to keep as much of the field “in the public domain” (from the patent point of view) as I can. This is my own inclicnation … ‘

‘ … If you wish to maintain the same type of close contact with the [commercial] group – which is for you and you alone to decide – then you should not put yourself into an incompatible position by communicating with us too. I would apprecitate your making your choice in this respoect before we continue our discussions further.’

— John von Neumann to Frankel, 29 October 1946. Quoted in ‘John von Neumann and the Origins of Modern Computing’ by William Aspray (MIT Press, 1990)

Every command in /bin and /usr/bin

I read Stiff’s questions for great programmers. One of his interviewees was Steve Yegge.

I really like Steve’s blog and his earlier “rants”. One answer he gave included:

Every programmer should learn how to use every tool in /bin and /usr/bin.

As a fairly recent convert to desktop linux that sounded like a challenge to be met. A quick

ls -1 /usr/bin | wc -l

reveals that there are 1509 commands in my /usr/bin directory. Perhaps a bit much to take on all at once. /bin contains 102. That sounds like a more manageable number.

A bit of shell script magic later:

#!/bin/sh
for CMD in `ls -1 /bin`; do
    man $CMD 2>/dev/null | head -20 | grep " - "
done

and I have this list of commands and what they do:

arch - print machine architecture
bash - GNU Bourne-Again SHell
bzcat - decompresses files to stdout
bzcmp, bzdiff - compare bzip2 compressed files
bzexe - compress executable files in place
bzgrep, bzfgrep, bzegrep - search possibly bzip2 compressed files for a
bzip2, bunzip2 - a block-sorting file compressor, v1.0.3
bzip2recover - recovers data from damaged bzip2 files
bzmore, bzless - file perusal filter for crt viewing of bzip2 com