An article about my initial experince with Google's new programming language "Go"!
This is probably a subject for the more nerdy of us ;-)
Google has finally had it, with centuries old programming languages and their cumbersome ways!
Anybody working with the technically side of the online industry, will know the names of at least the 10+ programming, scripting or markup languages.
Some of the more common are:
HTML, xHTML, CSS, PHP, ASP, JSP, Python, Ruby, Java, JavaScript, ActionScript, ECMAScript, C, C++, C#, Visual Basic, Bash, etc...
While some of the less common or less known are:
Lisp, Erlang, LUA, SmallTalk, Java (oops! dreaming...), Tcl, etc...
Then there is technologies, protocols and standard/typical ways of doing things, which then gets a name... Like AJAX...
Well... It looks like Google wants to clean up a bit...
So why not create a new programming language?!?! :-P
It's actually one of their "Innovation Time Off" a.k.a. "20% projects", but it's being evaluated along other technologies, for use in new systems and setups.
So... What is it? It's kind of a new programming language, but not really, but then again... :-P
It's a compiled language. The compiler is written in C, some C code can be linked with Go programs, making the language a little hard to define.
I think you can say, that Go is a new C++.
But why?.. WE NEED IT! As they state on their site (
http://golang.org/), we are using centuries old programming language, not designed to do what we need today.
Most languages has been "updated", hacked, expanded, call it what you like, to do what we need...
But doing what we need, is not the same as doing it good or easy.
I have created a higly scalable multiserver program in C/C++, where the servers know about each other - the core of the code, is very complicated, is held in many files and probably has a bug or two I haven't discovered yet.
With Googles Go language, I could have written it all in 1 (ONE!) file!!!
It would almost be hard to introduce a bug!
But how is that possible? Well... When working with multiple threads or forks, a lot of network connections, a bunch of files and a memory cache layer... You are in for a ride...
There is SO many things that can go run - so many things, that needs to be handled correctly, so many things that needs locks!
What Google has done with Go, is to encapsulate a lot! of these tasks.
More specifically, they have sncapsulated the parts that are hardest and yet most used.
When you need to have inter-process communication, you establish a channel and communicate!
In C/C++ this is done through either socket communication with all it's glory and weirdness - or through shared memory queues or variables, needing locks and unlocks on everything...
The last time, I wrote code for message queue, inter-process communication, I ended up with 500+ lines of code (if I remember correctly).
The basics of this, would in Go be a couple of lines of code, and with good error handling etc., it would probably be in the 10s!!!
But... Even better yet, is the threading handling... In Go a parallel process is called... a go process :-)
Whenever yo need to run a parallel process, you just write that!
What is interesting, is what happens in the background!
Go handles thread creation for you, but even better: it handles running you code in these threads!
Every system has a thread limit (and a fork limit), which limits you to a set amount of truly parallel processes.
But parallel processing acts as everything else on a computer - it waits... it waits A LOT! Mostly on resources being free'd and accessible.
I'll try to describe this, by giving a quick overview of an example webserver:
If you run a thread pr. connection AND lowers the default allocated memory pr. thread, you would normally get about 6-7000 threads on a typical webserver.
This means you can handle 6-7000 connections every second, as long as you can deliver the content within a second...
That a lot... If you have small commercial site, that tells a little about your company etc...
But let's say, you had a video delivery system...
If
YouTube were running on a single server, with this kind of setup, only 6-7000 people would be served over a minut or so.
6-7000 clients would connect, the same amount of threads would start - but then... the threads would spend most of it's time, just waiting for all kinds of things, like response from the client, when it has received a packet of data, etc.
So... When you create this kind of you server, you would look into letting one thread handle more than 1 client.
Go does this for you!
It even selects the thread to execute the code, based on whether it is in a blocking mode or not!
To make things even more beautiful, it encapsulates the network communication in the same way!
I mean it very seriously, when I claim, I would be able to melt down the core of my current C/C++ project to less than a 1/10th of the current, just by rewriting it in Go!!!
So... Why don't I? There is 2 simple reason:
1) Google discourage live use, just yet...
2) Go doesn't have a MySQL connector
To sum up, why I believe Go will be my preferred language in a year or two:
* Unlike Java, Erlang and the likes, it is a compiled language! (no buggy VMs!!!!)
* It encapsultes most of the absolutely most difficult stuff like threads, inter-process communication and network communication
* It's a new language for new problems, aiming at doing high load, online server stuff the right way, easily!
* It rides on the back of C, removing the needs for a completely rewritten compiler, etc.
* It's kinda C/C++, but less difficult - i.e. it has garbage collection, nicer pointers handling, etc.* Because it's the only compiled language, aiming at the online server market
I just want to make 1 thing extremely clear:
Go is a compiled language!
Like C/C++ you need a compiler on a (one) machine...
When you are done coding, compiling, testing - you just copy the final program to other machines!
You can cross-compile for other systems!
A lot of people, loves the "write once, run everywhere" of Java... I hate it!
It's a big fat lie!
There's like a million Java VMs (Virtual Machines) out there!
If you want to run your code on any machine, you need a VM for that OS and CPU.
When you have installed that - you need to test your code on that machine!!!
"But shouldn't it just run?" - Yeah... but it don't!
There is a different set of capabilities and incapabilities pr. OS+CPU and a different set of bugs.
If you have Java VM xxx.xx.01 on one machine and Java V; xxx.xx.02 on another... You need to test! Trust me!
I'd rather spend some extra time, coding and compiling for a couple of platforms, than testing and getting hit by weird bugs in live systems!
I hope this will entice others to give Go a go!..
I think it will be worth your time, to at least get into what this is all about...