Tuesday, November 30, 2010

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 { ... }
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 cmath, while some other packages like patch, ebnf, and tabwriter look more intriguing. The regexp and rand packages look to me a bit bloated and could stand to be pared down a bit, regexp especially since Go allows multiple return values from functions; maybe someone just got API happy.

There's also a utility named gofmt which is used to format Go code. It serves as the official style guidelines in an attempt to avoid code formatting wars. I don't agree with some of their choices, but that only highlights the usefulness of gofmt. More languages should ship with such a utility officially. gofmt can also be used as a sort of lint application since it can't properly format code with syntax errors.

The selection of library packages for Go will hopefully continue to grow over time, and a tool like gofmt is nice to have in your arsenal. I'm still thinking favorably of Go after the second day.

Feel free to share your impressions of Go in the comments below and come back tomorrow for day 3.

Monday, November 29, 2010

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 overall there's nothing earth shattering with Go's syntax.
  • Parentheses aren't used in constructs like if and for as they are in C, though braces are always required, and semicolons are used as separators-- not terminators. The resulting code looks nice and clean. The lack of terminators is a bit disconcerting, though... have we learned nothing from JavaScript?
  • := elides variable declarations and the compiler will deduce the variable's type, reminiscent of OCaml's type inference (though it doesn't extend to function declarations and the like). The more verbose way of declaring and assigning sum would be var sum int = 0. It's nice once you get the hang of it, but I think this might be a bit confusing for new programmers.

Problem 2
package main

import fmt "fmt"

func main() {
    a, b, c, sum := 0, 1, 0, 0
    for c < 4000000 {
        c = a + b
        a, b = b, c

        if c%2 == 0 {
            sum += c

    fmt.Printf("%d\n", sum)

Whoa, Go doesn't have a while loop? Surely this is madness!
  • The designers extended the minimal syntax philosophy to common language constructs as well. Different for variations are used to write not only your traditional for loops, but also while loops and foreach/for in loops. I think for c < 4000000 is a bit awkward to read but it becomes second nature to write in short order.
It's nice to have less keywords and the code looks clean and readable. Despite some hesitance, my opinion was favorable overall after the first day.

Feel free to share your impressions of Go in the comments below and come back tomorrow for day 2.

Tuesday, November 16, 2010

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 networking, JavaScript, Flash, and whatever comes out of the Facebook v. Google storm that's brewing. I may be wrong... but hindsight is 20/20 so I guess I'll just have to make a few of my own predictions here and see how on the mark I was come next November.

IPv6 hasn't seen widespread adoption despite being standardized for over 10 years. Supposedly Europe is running thin on the IPv4 front with something like 4% of the address-space left, and getting down to around 1-1.5% might be enough to force the ISPs and TELCOs to start investing more in their infrastructure. Either that, or perhaps someone will devise a creative way to prolong the inevitable either with some new NAT/routing extensions, or a new backwards-compatible protocol obsoleting IPv6 that would overlay nicely on IPv4 to allow backwards compatibility and future growth (along the lines of how 64-bit processor registers extended their 32-bit registers, which in turn extended their 16-bit registers, etc).

Developers are finally starting to fully explore JavaScript's capabilities, are becoming more comfortable with duck-typing, and Google's V8 engine has done pretty well in speeding up JavaScript's execution, to the point where I can see more and more programmers attempting serious server-side programming in JavaScript. Server-Side JavaScript is nothing new, but if one or two start-ups can make it big within the next year or so using a technology stack focused on server-side JavaScript, it may make others in the market comfortable enough to take the plunge themselves... if not in 2011, then possibly 2012. This would be thanks in no small part to ECMA-262's strict mode in an attempt to clean some cruft from the language, and projects like CommonJS and node.js. I only hope it doesn't get bastardized with Java-like public/private syntax in the process.

I think HTML5 is a lot of fluff-- the standard isn't expected to be completed until 2020ish, and technology moves so fast now that by then it'll be irrelevant. Browsers and developers are trying to be early adopters so they can be the cool kids on the block, but let's face it... the multimedia developer is going to prefer something like Flash to create their website experiences in than programing JavaScript code in an IDE; synchronizing timers to manipulate objects and sounds is easier with a click/drag-and-drop interface. JavaScript will be big with programmers/back-end developers, but if Adobe can re-align the Flash product and address some of the memory usage concerns, they can come out on top with the front-end/multimedia folks. Apple won't suffer, but people will see through their arguments for what they are-- self-preservation and vendor lock-in efforts.

Social Media
There's a turf war simmering between Facebook and Google that could have interesting repercussions for the rest of us. Facebook is rolling out new a new email-type feature to make communication with non-facebookers easier and to consolidate/streamline the social media experience, which looks similar to Google's failed Facebook-killer Wave product with a less-crappy interface. Google is suddenly concerned with defending our rights when it comes to our own content. I can imagine a spirited debate on privacy, ownership, and copyrights in the 21st century.

Then there's the question of how can a CEO take advantage of these changes in technology and the tech/social landscape to increase their company's profits. Since we're being honest with one another, I can say I don't know and not feel too bad about it. If I did know, I wouldn't be blogging about it here; I'd be out positioning myself to be the next Gates, Page, or Zuckerberg. Maybe there will be some new startup mash-up type service providers (like qwiki.com only not as annoying?) that will spring up which will eventually turn to targeted advertising for their revenue. Or, wouldn't it be nice if someone came up with a product/service to make parents be responsible and not raise douche-bag children, for it to be cool for kids to put down their cell phones and mp3 players and eat dinner at the table as a family, and maybe spread a little inter-office email etiquette just for good measure?

Just my thoughts...

Wednesday, November 10, 2010

"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

Interestingly enough, when the same is tried in PHP the results are slightly different...


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.