May 2, 2013

We are all polyglots

Posted in Software at 17:24 by graham

I used to know two programming languages at any one time; what I called a serious language and a what I called a scripting language. My initial serious language was C, my scripting language was Perl. The serious language was for client work, it paid the bills. The scripting language was for tools and toys (which is why many early web-apps were Perl CGI scripts).

We’ve been replacing C as our serious language since the 70s. C++ mostly succeeded, and became the official language of Microsoft Windows. Objective-C got a solid niche when Apple chose it for OSX, and later iOS. Java, became the serious language of web apps, and is now the language of Android. The two recent exciting developments here are Go and Rust.

In scripting-language world, Perl was largely replaced by Python and Ruby, and for web-app work by PHP.

So by now my serious language was Java, and my scripting language Python. But then three interesting things happened.

Read the rest of this entry »

April 26, 2013

Rust: What I learnt so far

Posted in Software at 22:58 by graham

Rust is an open-source programming language being developed mostly by Mozilla. It’s goal is the type of applications currently written in C++ (such as Firefox). Details at the Rust Wikipedia page.

I’ve been learning bits of it the past few days, and whilst Rust is still rough around the edges there’s a lot to enjoy. Rust is only at v0.7pre and changing daily, so you may have to adjust some of the code here.

Rust is a big language, and unless you come from C++ it will probably make your head hurt. In a good way :-)

The two most helpful introductions I have found so far are:

I’d encourage you to run through both of those, starting with Rust for Rubyists. When you get stuck reading one of them (and you will), switch back here.

Contents:

Install

At time of writing Rust is v0.7pre:

Read the rest of this entry »

March 26, 2013

PyCon 2013: My two favorite talks

Posted in Software at 16:41 by graham

PyCon is an annual gathering of Python programmers. All the talks are recorded and distributed freely on the web. My two favorite talks were:

January 15, 2013

Keyword arguments in C

Posted in Software at 06:03 by graham

This is valid C nowadays:

my_func(.username="Bob", .is_admin=true);

I found it in 21st Century C. It requires a macro and a structure, and relies on three features introduced in C99.

#include <stdio.h>      // printf
#include <stdbool.h>    // bool - there's a bool type now

// Macro that turns the kwargs into an struct
#define my_func(...) my_func_base(\
    (struct user){.is_admin=false, __VA_ARGS__});

struct user {
    char *username;
    bool is_admin;
};

// The actual function - and yes there's single line comments too
void my_func_base(struct user u) {
    printf("Hello %s\n", u.username);
}

int main(int argc, char *argv[]) {
    my_func(.username="Bob", .is_admin=true);
}

The three new features introduced in C99 that make this possible are:

  • Compound literals which allow my_user = (user) {"Bob", true}.
  • Designated initializers which give us struct user my_user = {.username="Test", .is_admin=true}
  • Variadic macros which allow #define‘s to take ... as a parameter and have it substituted wherever __VA_ARGS__ appears in that macro.

All the keyword arguments are optional, because compound literal rules state that any unspecified arguments are set to zero / null of the appropriate type.

We even have default arguments, like the .is_admin=false in the macro above, because designated initializer rules state that if the argument is repeated, the last argument wins.

December 31, 2012

Why I prefer Android to iOS

Posted in Software at 18:53 by graham

Our house has two iOS devices (an iPad and and iPod Touch), and two Android devices (Nexus 7 tablet, Samsung Galaxy phone). The Androids are newer than the iOS. So far, I prefer the Android devices for these reasons:

  • Android is multi-user. Just swipe down, select a different account. iOS seems designed for individuals living alone.
  • Widgets on the home screen. Just by glancing at my Nexus 7′s screen I can check my email, my calendar, and the weather. iOS’s home screen is just a list of all your apps.
  • AdBlock Plus. Android has an AdBlock app, which tries to block in-app adverts.
  • Internal access – Terminal, Disk usage, RAM usage, etc. I feel more comfortable with a device that gives me that level of knowledge. Android holds it’s users in higher regard than iOS.

October 3, 2012

Resident and Virtual memory on Linux: A short example

Posted in Software at 06:29 by graham

Tools like top show processes using two kinds of memory:

  • Resident memory, labelled RES: How much physical memory, how much RAM, your process is using. RES is the important number.
  • Virtual memory, labelled VIRT: How much memory your process thinks it’s using. Usually much bigger than RES, thanks to the Linux kernel’s clever memory management.

Here’s a short C program to illustrate the difference:

Read the rest of this entry »

September 12, 2012

What is WebRTC? Post on LincolnLoop’s blog

Posted in Software at 17:33 by graham

I blogged What is WebRTC over on Lincoln Loop’s blog:

WebRTC, short for Web Real Time Communications, is a specification and project adding JavaScript APIs in the browser to:

  1. Access a user’s webcam and microphone: getUserMedia.
  2. Connect directly to another browser: PeerConnection and DataChannel.

Being able to do video calling in the browser is exciting, but to me the most exciting part of WebRTC is the prospect of peer-to-peer apps in the browser, and server-less applications.

What is WebRTC – Read the full article

July 12, 2012

What is SPDY? Post on Lincoln Loop’s blog

Posted in Software at 21:00 by graham

I blogged an introduction to and explanation of SPDY, the next-gen HTTP. It should cover all the basics.

SPDY (pronounced speedy) is a replacement for HTTP, and feels like a wrapper for it. SPDY is a packet (frame) oriented binary protocol, usually wrapped in TLS (SSL), and as such a little harder to follow than HTTP. Our care free days in the jungle, surviving on the bare necessities and debugging connections with telnet, are coming to an end. In exchange, we get faster loading apps, which are secure by default.

The most important goal of SPDY is to transport web content using fewer TCP connections. It does this by multiplexing large numbers of transactions onto one TLS connection.

What is SPDY? – Read the rest

June 14, 2012

Go: Targeting a different architecture #golang

Posted in Software at 01:08 by graham

Problem: You’re on a i386 machine, and you need to build for amd64, or vice-versa.
Solution:

Get the libc for the other architecture. Get both, one of which you’ll already have:

# Debian / Ubuntu family
sudo apt-get install libc6-dev-amd64 libc6-dev-i386

Build the Go compiler for the other architecture:

cd $GOROOT/src
GOARCH=amd64 ./make.bash    # or GOARCH=386 for the other direction

Set the architecture before building your program:

GOARCH=amd64 go install <my_project>  # or GOARCH=386

The first two steps you only need to do once.

Thank you zephyrtronium in freenode#go-nuts for the help.

For other architectures, see Dave Cheney’s An introduction to cross compilation with Go

May 31, 2012

Finally understanding Unicode and UTF-8

Posted in Software at 23:25 by graham

Unicode maps 32-bit (4 byte) integers, also called code points or runes, to characters. UTF-8 is a way of storing those code points using less than 4 bytes per character.

61 is the Unicode code point for a, 229 is å and 5793 is . Unicode is how most modern programming languages represent strings: Java, .Net (C#, VB.Net), Go, and Python3, for example. Code points are usually written as two hexadecimal bytes prefixed by the letter u, or four prefixed by U. In python 3 this will display ᚡ:

print('\u16a1')

Read the rest of this entry »

« Previous entries Next Page » Next Page »