Skip to main content

Posts

Ubuntu Packages Please Get Your Act Together

I didn't intend to write another blog entry so close to the conclusion of my Week with Go series, but my experiences earlier today definitely warranted a rant. Installing the SpiderMonkey JavaScript engine for use as a stand-alone interpreter on Ubuntu 10.04 LTS doesn't sound like outlandish goal. After all, CouchDB ships by default as of 9.10 and it requires a JavaScript run-time. Technologies like node.js and v8 are pretty hot right now so there might even be a few alternatives to choose from, right? WRONG! sudo apt-get install spidermonkey-bin E: Couldn't find package spidermonkey-bin There used to be such a package but apparently SpiderMonkey is "unsupported" now and was removed from the Universe repository. Sorry Ubuntu. I'm not feeling the love for Rhino. It doesn't do JIT and runs slower than a one-legged sloth. Besides, I don't feel like installing ca-certificates-java , default-jre-headless , icedtea-6-jre-cacao , java-common , libavahi-...

A Week with Go, Day 5

Concurrent programming in Go makes use of coroutines, which are quaintly called "goroutines", and channels. Coroutines are functions executed asynchronously from the rest of your program, and channels are synchronous pipes through which the routines communicate. I had written a multi-threaded Kember Identity program in C a while back, and decided to rewrite it in Go to gain some exposure working with these features. The Effective Go primer gives a hint of what goes on under the hood with coroutines in Go. A goroutine has a simple model: it is a function executing in parallel with other goroutines in the same address space. It is lightweight, costing little more than the allocation of stack space. And the stacks start small, so they are cheap, and grow by allocating (and freeing) heap storage as required. Goroutines are multiplexed onto multiple OS threads so if one should block, such as while waiting for I/O, others continue to run. Their design hides many of the compl...

A Week with Go, Day 4

Day 4 was spent learning about Go's take on object oriented programming, which I found to be a refreshing change from the likes of Java and C#. It's not type-focused; instead of relying on an object's type to know whether or not it offer certain functionality, the object will generally implement an interface. This mindset is not dissimilar to good JavaScript programming where feature detection is preferred over browser sniffing. The code doesn't care what something is (browser/object), just what it can do (functionality/interface). The word "object" is probably a bit misleading since Go doesn't really have them in the traditional sense. There's no need to write a class definition as in Java, nor to instantiate an object literal like JavaScript. The programmer specifies a set of functions and Go's compiler deduces the relationships. type Rectangle struct { width float height float } func (r *Rectangle) Area() float { return r.widt...

A Week with Go, Day 3

The first two days of tinkering and scouring helped me form an opinion of Go based on its syntax. To form a more-informed opinion I would have to write some more code and see how much resistance I experienced along the way. What features were missing? How was typing applied? I wrote a rudimentary version of Deal or No Deal , and slowly some of those meaningless sections in the language spec started taking on more meaning. I decided to store the case amounts as an integer array (nobody likes the 0.01 anyway!) and came across my first bit of frustration and misunderstanding when it came time to shuffle the amounts. cases = []int{100, 200, 300, 400, 500, 750, 1000, 5000, 10000, 50000} shuffle(cases) func shuffle(arr []int) { rand.Seed(time.Nanoseconds()) for i := len(arr) - 1; i > 0; i-- { j := rand.Intn(i) arr[i], arr[j] = arr[j], arr[i] } } The language spec says arrays are value types and slices are reference types. shu...

A Week with Go, Day 2

After dabbling a little bit on day 1, I dedicated some time on day 2 to skim through Go's language spec and standard libraries . A lot of it didn't have much relevance to me yet because I hadn't begun to play with those parts of the language. What caught my eye though was that Go supports the \v escape (obviously no one at Google has read Stop the Vertical Tab Madness ). Welcome to 1963, folks. In addition to tweaking how loops are written, Go has augmented the traditional syntax of if and switch statements too. I don't see the enhancement providing as much benefit as I do with for . It's almost as if someone decided to let people move the placement of if up a statement earlier just to be different, and it certainly doesn't read well. x := recover() if x != nil { ... } vs if x := recover(); x != nil { ... } The list of available packages is rather impressive considering Go has been available for a year. Some packages are pretty standard, like math and...

A Week with Go, Day 1

Go is a general purpose systems programming language developed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. Go has been on my radar since it became publicly available a year ago as an open source project, and since then its documentation has been improving and a small community of users has been forming around the language. Last week I had some time off from work that coincided nicely with the Thanksgiving holiday and I thought it'd be fun to spend some of it looking at Go. Here's the first in a series of five posts that share my thoughts and experiences of spending a week with Go. My first Go programs were solutions to a couple Project Euler solutions. This was just to get a basic feel for its syntax. Problem 1 package main import fmt "fmt" func main() { sum := 0 for i := 0; i < 1000; i++ { if i%3 == 0 || i%5 == 0 { sum += i } } fmt.Printf("%d\n", sum) } There are a few oddities, but ove...

On Gartner's 2011 Top Technologies

A coworker stumbled across Gartner's top 10 technologies for 2011 and decided to share it with everyone in the office via email. Overlooking the need for a cluebat , and resisting the urge to similarly spam everyone with The Oatmeal's take on email etiquette , I think Gartner missed the mark on some things. Let's be honest for a moment. Cloud computing has been hyped since '08 when Eucalyptus and Amazon's EC2 Services came out. Social media has been on the radar since since blogs became popular (though admittedly Twitter and Facebook upped the ante). Mobile computing has been slowly making inroads but I think it's still too soon to claim "The PC era is over." All the technologies have been around for years in one form or another; they just happen to be "hot" right now... and by the time someone starts touting them they've probably peaked. In the next 12 months I predict there'll be a lot of potential for things like IPv4/6 netw...

"Inchworm on a Stick" in PHP

~- is known as the inchworm on a stick operator in Perl obfuscation circles. It isn't really an operator; it's a term coined to describe negating a value and then taking its compliment, the apparent effect of which is to decrement the value. (To understand why, you need to understand how negative numbers are represented in binary.) In Perl, ~- works for positive values: for ($i = 3; $i > -3; $i--) { print ~-$i . "\n"; } $ perl test.pl 2 1 0 4294967295 4294967294 4294967293 Interestingly enough, when the same is tried in PHP the results are slightly different... 2 1 0 -1 -2 -3 PHP treats the value as a signed integer where Perl treats it as an unsigned integer. I don't know which way is "better" or which is "more correct," but it is something I found interesting and I thought would be worth sharing.

8 Tips to Improve Your Golf Game

I wasted more time golfing this week than I should have. No, not real golf... code golf . Trying to write small programs in the least number of keystrokes can be fun, challenging, and sometimes even addicting. It's not about writing pretty code or code that's easily-understandable. It's all about cramming as much code as you can into the least number of characters. While some languages golf better than others, you can still write impressively small code in your language of choice if you're familiar enough with the intricacies of its behavior. Here are 8 tips to improve your golf score when golfing with PHP: Use short tags. Using <? instead of <?php and using <?= instead of <?echo will both save you 3 characters. Avoid initializing variables if possible. Uninitialized variables assume the value 0 , "" , or false depending on the context in which they're referenced. $x=0; is 5 characters too much! Know your function aliases. A few...

I Remember...

I remember when Java first came out surfing the Internet on my 28k dial-up connection and hitting a page with a Java applet ; either Netscape would come crashing down or my computer would lock up... I remember schoolmates telling me Java was "the future" because it ran on a virtual machine which meant it was cross platform, and then being ostracized by them when I pointed out that QBasic would be considered cross platform , too... I remember reading Java programming books before I understood OOP and wondering why I had to write a hundred lines of code just to output "Hello World" ... I remember reading Java programming books after I understood OOP and still wondering why I had to write a hundred lines of code just to output "Hello World"... I remember trying to convince myself every time I started Eclipse and watched my P4 run slower than a 486 that I just hadn't given Java a fair shake and I needed to embrace it with an open heart and mind....