Archive for October, 2013

environmentalism and car safety

October 4, 2013

It is taken for granted that use of hydrocarbon fuels are harmful to the climate and this has to be reduced.  However, it is very difficult to make a car which is not powered by hydrocarbons and still gives acceptable performance.  Tesla is a noticeable exception to this.  Recent crash tests have shown the incredibly good performance of the Tesla sedan.  Lacking the technology of Tesla, and with a desire to reduce the price point of the car, manufacturers have taken to reducing the weight of the car.  This would help the underpowered motor handle the everyday tasks expected of the car.  However, the weight reduction might come at the expense of structural safety.  Add to this the classification of quadricycles, which have no safety requirements whatsoever, and the well meaning environmentalist is in danger of going extinct.

google go

October 4, 2013

Google has released the Go programming language, which it had been using internally.  As you would expect from a new language, it contains many features found in many of the popular languages like Perl.  The syntax is designed to be close to C, but many of the conveniences found in Perl are also found here.  Some of the surprises are : Go does not support dynamic linking.  Go does not have a proper debugger.  There is some information on how to use gdb for go code, but it doesn’t look very mature.  The binaries seem to be optimized only for the AMD system for 64 bit, which is strange since AMD has all but lost the performance race with Intel.

I have installed go in both Linux and windows.  Don’t let the minimum (software) requirements worry you–it might still run on your system.  The go mode for emacs uses some packages that don’t come with the default install in Linux.  The go-mode .el file is already available in your go installation, at go/misc/emacs. I have gotten it to work in Windows, but many of the features don’t work.  However, it supports basic formatting in Windows, which is important since Go is somewhat strict about formatting.

The built in library is small compared with Java, and is focused on web development.  Access to clipboard in windows is provided by the w32 package, which is to be downloaded separately.

A password generator written in go is shown below. I apologize for the formatting: wordpress does not yet support go.

package main

import (
"fmt"
"math/rand"
"time"
)

func main () {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < 8; i++ {
switch r.Intn(3) {
case 0:
fmt.Printf("%c", byte (48 + r.Intn(10)))
case 1:
fmt.Printf("%c", byte (65 + r.Intn(26)))
case 2:
fmt.Printf("%c", byte (97 + r.Intn(26)))
}
}
}

Here is a program that shuffles the input.


package main

import (
"fmt"
"math/rand"
"time"
"io/ioutil"
"strings"
)

func main () {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
filename := "hello.go"
contents, err := ioutil.ReadFile(filename)
if err != nil {
return
}
s := strings.Split(string(contents), "\r\n")
for _,i:= range r.Perm(len(s)) {
fmt.Println(s[i])
}
}