<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Water-cooler talk</title>
	<atom:link href="http://aprogrammerslife.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://aprogrammerslife.wordpress.com</link>
	<description></description>
	<lastBuildDate>Thu, 19 Aug 2010 16:05:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='aprogrammerslife.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Water-cooler talk</title>
		<link>http://aprogrammerslife.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://aprogrammerslife.wordpress.com/osd.xml" title="Water-cooler talk" />
	<atom:link rel='hub' href='http://aprogrammerslife.wordpress.com/?pushpress=hub'/>
		<item>
		<title>How To Use Arrays and Slices in Google Go</title>
		<link>http://aprogrammerslife.wordpress.com/2010/08/05/how-to-use-arrays-and-slices-in-google-go/</link>
		<comments>http://aprogrammerslife.wordpress.com/2010/08/05/how-to-use-arrays-and-slices-in-google-go/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 17:03:50 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Go Programming]]></category>
		<category><![CDATA[google go]]></category>

		<guid isPermaLink="false">http://kevinrodrigues.com/blog/?p=990</guid>
		<description><![CDATA[Array An array is a collection of like objects. In Google Go programming, arrays are declared as, var arrayOfInt [10]int The length is part of the array&#8217;s type and must be a constant expression that evaluates to a non-negative integer value. The length of array a can be discovered using the built-in function len(a). The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=994&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Array</strong><br />
An array is a collection of like objects. In Google Go programming, arrays are declared as,</p>
<pre class="prettyprint">
var arrayOfInt [10]int
</pre>
<p>The length is part of the array&#8217;s type and must be a constant expression that evaluates to a non-negative integer value. The length of array a can be discovered using the built-in function len(a). The elements can be indexed by integer indices 0 through the len(a)-1. If the array is indexed beyond len(a)-1, then we get an out of bounds error.</p>
<p>In C, arrayOfInt would be usable as a pointer to int. In Go, since arrays are values, we have to use a pointer to an array. What this means is that in Google Go,</p>
<pre class="prettyprint">
var pArray *int = &amp;arrayOfInt //pArray is a pointer to an integer.
var pArray *[10]int = &amp;arrayOfInt //pArray is a pointer to an array of 10 integers.
</pre>
<p>In the declaration of the pointer to an array, the size of the array is mandatory. When assigning the address of an array to a pointer variable, the &amp; referencing is mandatory.</p>
<p>Arrays are values. Assigning one array to another copies all the elements. In particular, if you pass an array to a function, it will receive a copy of the array, not a pointer to it. The value property can be useful but also expensive; if you want C-like behavior and efficiency, you can pass a pointer to the array.</p>
<pre class="prettyprint">
package main

import "fmt"

func arrayLen (pArray *[5]int) int{
   return len(pArray)
}

func main(){
   var arrayOfInt [5]int

   arrayOfInt[0] = 0
   arrayOfInt[1] = 1
   arrayOfInt[2] = 2
   arrayOfInt[3] = 3
   arrayOfInt[4] = 4

   fmt.Println("Array Length = ", arrayLen(&amp;arrayOfInt))
}
</pre>
<p>If you are creating a regular array but want the compiler to count the elements for you, use &#8230; as the array size:</p>
<pre class="prettyprint">
s := sum(&amp;[...]int{1,2,3})
</pre>
<p>A type followed by a brace-bounded expression—is a constructor for a value, in this case an array of 3 ints.</p>
<p><strong>Slice</strong><br />
Slices wrap arrays to give a more general, powerful, and convenient interface to sequences of data. Slices can be considered as a sub-section of an array. Slices are reference types, which means that if you assign one slice to another, both refer to the same underlying array. For instance, if a function takes a slice argument, changes it makes to the elements of the slice will be visible to the caller, analogous to passing a pointer to the underlying array.</p>
<p>We can declare a slice variable, by assigning a pointer to any array with the same element type,</p>
<pre class="prettyprint">
var arrayOfInt [5]int
var slice []int = &amp;arrayOfInt
</pre>
<p>or by a slice expression of the form a[low : high], representing the subarray indexed by low through high-1.</p>
<pre class="prettyprint">
var arrayOfInt [5]int
slice = arrayOfInt[1:3]
</pre>
<p>Slices look a lot like arrays but have no explicit size ([] vs. [10]) and they reference a segment of an underlying, often anonymous, regular array. Multiple slices can share data if they represent pieces of the same array; multiple arrays can never share data.</p>
<p>When passing an array to a function, you almost always want to declare the formal parameter to be a slice. When you call the function, take the address of the array and Go will create (efficiently) a slice reference and pass that.</p>
<p>Using slices one can write the earlier program as:</p>
<pre class="prettyprint">
package main

import "fmt"

func arrayLen (slice []int) int{
   return len(slice)
}

func main(){
   var arrayOfInt [5]int

   arrayOfInt[0] = 0
   arrayOfInt[1] = 1
   arrayOfInt[2] = 2
   arrayOfInt[3] = 3
   arrayOfInt[4] = 4

   fmt.Println("Array Length = ", arrayLen(&amp;arrayOfInt))

}
</pre>
<p>We pass the pointer to arrayLen() by (implicitly) promoting it to a slice.</p>
<p>Like arrays, slices are indexable and have a length. The length of a slice s can be discovered by the built-in function len(s); unlike with arrays it may change during execution. The elements can be addressed by integer indices 0 through len(s)-1. The slice index of a given element may be less than the index of the same element in the underlying array.</p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aprogrammerslife.wordpress.com/994/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aprogrammerslife.wordpress.com/994/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aprogrammerslife.wordpress.com/994/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aprogrammerslife.wordpress.com/994/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aprogrammerslife.wordpress.com/994/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aprogrammerslife.wordpress.com/994/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aprogrammerslife.wordpress.com/994/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aprogrammerslife.wordpress.com/994/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aprogrammerslife.wordpress.com/994/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aprogrammerslife.wordpress.com/994/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aprogrammerslife.wordpress.com/994/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aprogrammerslife.wordpress.com/994/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aprogrammerslife.wordpress.com/994/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aprogrammerslife.wordpress.com/994/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=994&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aprogrammerslife.wordpress.com/2010/08/05/how-to-use-arrays-and-slices-in-google-go/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f9a708756f1960644f371d3706cde2b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kevin</media:title>
		</media:content>
	</item>
		<item>
		<title>How To Define Functions in Google Go</title>
		<link>http://aprogrammerslife.wordpress.com/2010/08/02/how-to-define-functions-in-google-go/</link>
		<comments>http://aprogrammerslife.wordpress.com/2010/08/02/how-to-define-functions-in-google-go/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 17:14:51 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Go Programming]]></category>
		<category><![CDATA[google go]]></category>

		<guid isPermaLink="false">http://kevinrodrigues.com/blog/?p=973</guid>
		<description><![CDATA[A program can be broken down into modules that each perform a specific function. These modules interact with each other to perform the entire functionality of the program. Functions are the basis of modular programming in Google Go. In Google Go, a function is declared using the keyword func as shown below, func [function name] [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=973&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A program can be broken down into modules that each perform a specific function. These modules interact with each other to perform the entire functionality of the program. Functions are the basis of modular programming in Google Go.</p>
<p>In Google Go, a function is declared using the keyword <em>func</em> as shown below,</p>
<pre class="prettyprint">func [function name] ([param1 declaration], [param2 declaration],...) (ret1 declaration, ret2 declaration, ...){
     //body of the function
}</pre>
<p>The function arguments declaration (param1) and return values declaration (ret1) is similar to variable declaration except the <em>var</em> keyword is not used. (See <a title="How To Define Variables In Google Go" href="http://kevinrodrigues.com/blog/2010/07/28/how-to-define-variables-in-google-go/" target="_blank">How To Define Variables In Google Go</a>)</p>
<pre class="prettyprint">func min(x int, y int) int {
        if x &lt; y {
             return x
        }
        return y
}</pre>
<p>In Google Go, it is necessary that the opening brace { of the scope should be placed on the same line as the function declaration else you will get a compilation error.</p>
<pre class="prettyprint">func main()
{                                          //Wrong
   fmt.Println("Hello World")
}

func main() {                         //Correct
   fmt.Println("Hello World")
}</pre>
<p>One of Go&#8217;s unusual features is that functions and methods can return multiple values. Multiple return values are declared after the argument list and separated by a comma as shown below.</p>
<pre class="prettyprint">package main

import "fmt"

func calc(a int, b int) (add int, sub int){
     add = a + b
     sub = a - b
     return
}

func main(){
     a := 100
     b := 50
     add, sub := calc(a, b)
     fmt.Println("Addition = ", add);
     fmt.Println("Subtraction = ", sub);
}</pre>
<p>The return or result &#8220;parameters&#8221; of a Go function can be given names and used as regular variables, just like the incoming parameters. When named, they are initialized to the zero values for their types when the function begins; if the function executes a return statement with no arguments, the current values of the result parameters are used as the returned values.</p>
<p><strong>Defer</strong><br />
Go&#8217;s defer statement schedules a function call to be run immediately before the function executing the defer returns. It&#8217;s an unusual but effective way to deal with situations such as resources that must be released regardless of which path a function takes to return. The canonical examples are unlocking a mutex or closing a file.</p>
<pre class="prettyprint">// Contents returns the file's contents as a string.
func Contents(filename string) (string, os.Error) {
    f, err := os.Open(filename, os.O_RDONLY, 0)
    if err != nil {
        return "", err
    }
    defer f.Close()  // f.Close will run when we're finished.

    var result []byte
    buf := make([]byte, 100)
    for {
        n, err := f.Read(buf[0:])
        result = bytes.Add(result, buf[0:n])
        if err != nil {
            if err == os.EOF {
                break
            }
            return "", err  // f will be closed if we return here.
        }
    }
    return string(result), nil // f will be closed if we return here.
}</pre>
<p>Deferring a function like this has two advantages. First, it guarantees that you will never forget to close the file, a mistake that&#8217;s easy to make if you later edit the function to add a new return path. Second, it means that the close sits near the open, which is much clearer than placing it at the end of the function.</p>
<p>The arguments to the deferred function are evaluated when the defer executes, not when the call executes. Besides avoiding worries about variables changing values as the function executes, this means that a single deferred call site can defer multiple function executions.</p>
<p>Here&#8217;s a silly example.</p>
<pre class="prettyprint">for i := 0; i &lt; 5; i++ {
    defer fmt.Printf("%d ", i)
}</pre>
<p>Deferred functions are executed in LIFO order, so this code will cause 4 3 2 1 0 to be printed when the function returns.</p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aprogrammerslife.wordpress.com/973/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aprogrammerslife.wordpress.com/973/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aprogrammerslife.wordpress.com/973/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aprogrammerslife.wordpress.com/973/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aprogrammerslife.wordpress.com/973/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aprogrammerslife.wordpress.com/973/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aprogrammerslife.wordpress.com/973/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aprogrammerslife.wordpress.com/973/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aprogrammerslife.wordpress.com/973/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aprogrammerslife.wordpress.com/973/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aprogrammerslife.wordpress.com/973/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aprogrammerslife.wordpress.com/973/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aprogrammerslife.wordpress.com/973/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aprogrammerslife.wordpress.com/973/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=973&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aprogrammerslife.wordpress.com/2010/08/02/how-to-define-functions-in-google-go/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f9a708756f1960644f371d3706cde2b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kevin</media:title>
		</media:content>
	</item>
		<item>
		<title>How To Use Strings In Google Go</title>
		<link>http://aprogrammerslife.wordpress.com/2010/07/31/how-to-use-strings-in-google-go/</link>
		<comments>http://aprogrammerslife.wordpress.com/2010/07/31/how-to-use-strings-in-google-go/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 09:48:45 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Go Programming]]></category>
		<category><![CDATA[google go]]></category>

		<guid isPermaLink="false">http://kevinrodrigues.com/blog/?p=967</guid>
		<description><![CDATA[In the earlier tutorials, we have seen how to define variables and how to define constants in Google Go. This tutorial explains how we can use strings in Google Go programming. Strings The predeclared string type is string. Unlike C/C++ programming, Strings are length-delimited not NUL-terminated. Strings behave like arrays of bytes but are immutable: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=967&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the earlier tutorials, we have seen <a href="http://kevinrodrigues.com/blog/2010/07/28/how-to-define-variables-in-google-go/">how to define variables</a> and <a href="http://kevinrodrigues.com/blog/2010/07/29/how-to-define-constants-in-google-go/">how to define constants</a> in Google Go. This tutorial explains how we can use strings in Google Go programming.</p>
<p><strong>Strings</strong><br />
The predeclared string type is <em>string</em>. Unlike C/C++ programming, Strings are length-delimited not NUL-terminated. Strings behave like arrays of bytes but are immutable: once created, it is impossible to change the contents of a string. In C++ terms, Go strings are a bit like <em>const</em> strings, while pointers to strings are analogous to <em>const</em> string references.  Once you&#8217;ve built a string value, you can&#8217;t change it, although of course you can change a string variable simply by reassigning it.</p>
<p>This snippet from strings.go is legal code:</p>
<pre class="prettyprint">s := "hello"
if s[1] != 'e' { os.Exit(1) }
s = "good bye"
var p *string = &amp;s
*p = "ciao"</pre>
<p>However the following statements are illegal because they would modify a string value:</p>
<pre class="prettyprint">s[0] = 'x'
(*p)[1] = 'y'</pre>
<p>The elements of strings have type <em>byte</em> and may be accessed using the usual indexing operations. It is illegal to take the address of such an element; if s[i] is theith <em>byte</em> of a string, &amp;s[i] is invalid.</p>
<p><strong>String literals</strong><br />
A string literal represents a string constant obtained from concatenating a sequence of characters. There are two forms: raw string literals and interpreted string literals.</p>
<p>Raw string literals are character sequences between back quotes ` `. Within the quotes, any character is legal except back quote. When using back quotes, backslashes have no special meaning and the string may span multiple lines.</p>
<p>Interpreted string literals are character sequences between double quotes &#8221; &#8220;. The text between the quotes, which may not span multiple lines, forms the value of the literal, with backslash escapes interpreted as they are in character literals.</p>
<p>Below are some examples of both types of string literals. Google Go also supports Unicode strings.</p>
<pre class="prettyprint">`abc`  // same as "abc"
`\n
\n`    // same as "\\n\n\\n"
"\n"
""
"Hello, world!\n"
"日本語"                                 // UTF-8 input text
`日本語`                                 // UTF-8 input text as a raw literal</pre>
<p>Strings can be concatenated using the &#8216;+&#8217; operator. The length of string s can be discovered using the built-in function len(). The length is a compile-time constant if s is a string literal.</p>
<pre class="prettyprint">var string1 = "Hello World "
var string2 = "This is Google Go"
string3 := string1 + string2	//string3 = "Hello World This is Google Go"
len_string3 := len(string3)	//len_string3 = 29</pre>
<p>Google Go provides a “strings” package that consists of several functions to manipulate strings. You can find more information at <a href="http://golang.org/pkg/strings/">http://golang.org/pkg/strings/</a>.</p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aprogrammerslife.wordpress.com/967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aprogrammerslife.wordpress.com/967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aprogrammerslife.wordpress.com/967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aprogrammerslife.wordpress.com/967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aprogrammerslife.wordpress.com/967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aprogrammerslife.wordpress.com/967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aprogrammerslife.wordpress.com/967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aprogrammerslife.wordpress.com/967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aprogrammerslife.wordpress.com/967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aprogrammerslife.wordpress.com/967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aprogrammerslife.wordpress.com/967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aprogrammerslife.wordpress.com/967/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aprogrammerslife.wordpress.com/967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aprogrammerslife.wordpress.com/967/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=967&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aprogrammerslife.wordpress.com/2010/07/31/how-to-use-strings-in-google-go/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f9a708756f1960644f371d3706cde2b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kevin</media:title>
		</media:content>
	</item>
		<item>
		<title>How To Define Constants in Google Go</title>
		<link>http://aprogrammerslife.wordpress.com/2010/07/29/how-to-define-constants-in-google-go/</link>
		<comments>http://aprogrammerslife.wordpress.com/2010/07/29/how-to-define-constants-in-google-go/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 17:05:35 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Go Programming]]></category>
		<category><![CDATA[google go]]></category>

		<guid isPermaLink="false">http://kevinrodrigues.com/blog/?p=958</guid>
		<description><![CDATA[In the previous tutorial, we saw how to define variables in Google Go. In today&#8217;s tutorial, we check out how we can declare constants and enumerated constants in Google Go. Constants The types of constants available in Go programming are boolean constants, integer constants, floating-point constants, complex constants, and string constants. Constants in Go are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=958&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the previous tutorial, we saw <a href="http://kevinrodrigues.com/blog/2010/07/28/how-to-define-variables-in-google-go/">how to define variables in Google Go</a>. In today&#8217;s tutorial, we check out how we can declare constants and enumerated constants in Google Go.</p>
<p><strong>Constants</strong><br />
The types of constants available in Go programming are boolean constants, integer constants, floating-point constants, complex constants, and string constants. Constants in Go are created at compile time, even when defined as locals in functions.</p>
<p>Constants are declared similar to variables except that the <em>const</em> keyword is used. Also we cannot use the idiom (using :=) as done for variable declaration.</p>
<p>Below are examples of declaring different types of constants in Go programming.</p>
<pre class="prettyprint">const Pi float64 = 3.14159265358979323846   //typed floating-point constant
const zero = 0.0             // untyped floating-point constant
const (
        size int64 = 1024   //typed integer constant
        eof = -1             // untyped integer constant
)
const a, b, c = 3, 4, "foo"  // a = 3, b = 4, c = "foo", untyped integer and string constants
const u, v float = 0, 3      // u = 0.0, v = 3.0
const sum = 1 – 0.707i   ///complex constant
const flag bool = true</pre>
<p><strong>Enumerated Constants</strong><br />
In Go, enumerated constants are created using the<em> iota</em> enumerator.  This can be considered similar to enumeration in C. It is reset to 0 whenever the reserved word <em>const</em> appears in the source and increments after each use of <em>iota</em> as shown below.</p>
<pre class="prettyprint">const (  // iota is reset to 0
        c0 = iota  // c0 == 0
        c1 = iota  // c1 == 1
        c2 = iota  // c2 == 2
)

const (
        a = 1 &lt;&lt; iota  // a == 1 (iota has been reset)
        b = 1 &lt;&lt; iota  // b == 2
        c = 1 &lt;&lt; iota  // c == 4
)

const (
        u       = iota * 42  // u == 0     (untyped integer constant)
        v float = iota * 42  // v == 42.0  (float constant)
        w       = iota * 42  // w == 84    (untyped integer constant)
)

const x = iota  // x == 0 (iota has been reset)
const y = iota  // y == 0 (iota has been reset)</pre><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aprogrammerslife.wordpress.com/958/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aprogrammerslife.wordpress.com/958/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aprogrammerslife.wordpress.com/958/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aprogrammerslife.wordpress.com/958/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aprogrammerslife.wordpress.com/958/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aprogrammerslife.wordpress.com/958/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aprogrammerslife.wordpress.com/958/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aprogrammerslife.wordpress.com/958/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aprogrammerslife.wordpress.com/958/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aprogrammerslife.wordpress.com/958/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aprogrammerslife.wordpress.com/958/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aprogrammerslife.wordpress.com/958/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aprogrammerslife.wordpress.com/958/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aprogrammerslife.wordpress.com/958/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=958&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aprogrammerslife.wordpress.com/2010/07/29/how-to-define-constants-in-google-go/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f9a708756f1960644f371d3706cde2b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kevin</media:title>
		</media:content>
	</item>
		<item>
		<title>How To Define Variables In Google Go</title>
		<link>http://aprogrammerslife.wordpress.com/2010/07/28/how-to-define-variables-in-google-go/</link>
		<comments>http://aprogrammerslife.wordpress.com/2010/07/28/how-to-define-variables-in-google-go/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 16:08:00 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Go Programming]]></category>
		<category><![CDATA[google go]]></category>

		<guid isPermaLink="false">http://kevinrodrigues.com/blog/?p=951</guid>
		<description><![CDATA[In the previous tutorial, we began by writing a Hello World program in Google Go. This tutorial will look into the available primitive data types and how to declare and define variables in Go programming. Basic Data Types The following are the basic data types that are available in the Google Go programming language. bool boolean truth [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=951&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the previous tutorial, we began by <a title="How To Write A Hello World Program In Google Go" href="http://kevinrodrigues.com/blog/2010/07/26/how-to-write-a-hello-world-program-in-google-go/" target="_blank">writing a Hello World program in Google Go</a>. This tutorial will look into the available primitive data types and how to declare and define variables in Go programming.</p>
<p><strong>Basic Data Types</strong><br />
The following are the basic data types that are available in the Google Go programming language.</p>
<pre class="prettyprint">bool          boolean truth values of either true or false
uint8         the set of all unsigned  8-bit integers (0 to 255)
uint16       the set of all unsigned 16-bit integers (0 to 65535)
uint32       the set of all unsigned 32-bit integers (0 to 4294967295)
uint64       the set of all unsigned 64-bit integers (0 to 18446744073709551615)

int8          the set of all signed  8-bit integers (-128 to 127)
int16        the set of all signed 16-bit integers (-32768 to 32767)
int32        the set of all signed 32-bit integers (-2147483648 to 2147483647)
int64        the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)

float32     the set of all IEEE-754 32-bit floating-point numbers
float64     the set of all IEEE-754 64-bit floating-point numbers

complex64   the set of all complex numbers with float32 real and imaginary parts
complex128  the set of all complex numbers with float64 real and imaginary parts

byte        familiar alias for uint8

uint         either 32 or 64 bits
int          either 32 or 64 bits
float       either 32 or 64 bits

string      represents the set of string values</pre>
<p>To avoid portability issues all numeric types are distinct except byte, which is an alias for uint8. Conversions are required when different numeric types are mixed in an expression or assignment. For instance, int32 and int are not the same type even though they may have the same size on a particular architecture.</p>
<p><strong>Variables</strong></p>
<p>A computer variable can represent any kind of data that can be stored in a computer system.<br />
Variables in the Go programming language can be declared as,</p>
<pre class="prettyprint">    var s string = ""</pre>
<p>This is the <em>var</em> keyword, followed by the name of the variable, followed by its type, followed by an equals sign and an initial value for the variable.<br />
Go tries to be terse, and this declaration could be shortened. Since the string constant is of type string, we don&#8217;t have to tell the compiler that. We could write</p>
<pre class="prettyprint">    var s = ""</pre>
<p>or we could go even shorter and write the idiom</p>
<pre class="prettyprint">    s := ""</pre>
<p>Following are several example of declaring different types of variables in Go.</p>
<pre class="prettyprint">var i int
var U, V, W float
var k = 0
var x, y float = -1, -2
var (
        i int
        u, v, s = 2.0, 3.0, "bar"
)</pre>
<p>If no initial value is given to a variable, then that variable is initialized to it&#8217;s zero value. False for booleans, 0 for integers, 0.0 for floats, &#8220;&#8221; for strings, and nil for pointers, functions, interfaces, slices, channels, and maps.</p>
<p><strong>Type Conversions</strong><br />
Go does not support implicit type conversion. To convert a numeric value from one type to another is a conversion, with syntax like a function call:</p>
<pre class="prettyprint">  uint8(int_var)     // truncate to size
  int(float_var)     // truncate fraction
  float64(int_var) // convert to float</pre>
<p>Also some conversions to string:</p>
<pre class="prettyprint">  string(0x1234)            // == "\u1234"
  string(array_of_bytes)    // bytes -&gt; bytes
  string(array_of_ints)     // ints -&gt; Unicode/UTF-8</pre><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aprogrammerslife.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aprogrammerslife.wordpress.com/951/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aprogrammerslife.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aprogrammerslife.wordpress.com/951/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aprogrammerslife.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aprogrammerslife.wordpress.com/951/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aprogrammerslife.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aprogrammerslife.wordpress.com/951/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aprogrammerslife.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aprogrammerslife.wordpress.com/951/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aprogrammerslife.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aprogrammerslife.wordpress.com/951/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aprogrammerslife.wordpress.com/951/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aprogrammerslife.wordpress.com/951/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=951&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aprogrammerslife.wordpress.com/2010/07/28/how-to-define-variables-in-google-go/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f9a708756f1960644f371d3706cde2b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kevin</media:title>
		</media:content>
	</item>
		<item>
		<title>How To Write A Hello World Program In Google Go</title>
		<link>http://aprogrammerslife.wordpress.com/2010/07/26/how-to-write-a-hello-world-program-in-google-go/</link>
		<comments>http://aprogrammerslife.wordpress.com/2010/07/26/how-to-write-a-hello-world-program-in-google-go/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 17:14:06 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Go Programming]]></category>
		<category><![CDATA[google go]]></category>

		<guid isPermaLink="false">http://kevinrodrigues.com/blog/?p=943</guid>
		<description><![CDATA[In the previous post, we saw how to install Google&#8217;s Go programming language. Learning any programming language begins with the “Hello World” program. So keeping with the tradition and assuming that you have some programming background, here is the program written in the Google Go programming language. Open your favorite text editor and type the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=943&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the previous post, we saw <a href="http://kevinrodrigues.com/blog/2010/07/24/how-to-install-googles-go-programming-language/">how to install Google&#8217;s Go programming language</a>.</p>
<p>Learning any programming language begins with the “Hello World” program. So keeping with the tradition and assuming that you have some programming background, here is the program written in the Google Go programming language.</p>
<p>Open your favorite text editor and type the following program in it.</p>
<pre class="prettyprint">package main

import "fmt"   //Package implementing formatted I/O

func main(){
   fmt.Printf("hello, world\n")
}</pre>
<p>Save the file as “hello.go”.</p>
<p>From the console, compile it using</p>
<pre class="prettyprint">$ 6g hello.go</pre>
<p>To link the file, use</p>
<pre class="prettyprint">$ 6l hello.6</pre>
<p>and to run it</p>
<pre class="prettyprint">$ ./6.out</pre>
<p>This will print,</p>
<pre class="prettyprint">hello, world</pre>
<p>The first line in the program</p>
<pre class="prettyprint">package main</pre>
<p>specifies the name of the package that the file “hello.go” belongs to. The package keyword is used to define the package.</p>
<p>This program imports the package &#8220;fmt&#8221; to gain access to fmt.Printf. We shall see more about packages in later tutorials.</p>
<pre class="prettyprint">import "fmt"</pre>
<p>Functions are introduced with the func keyword. The main package&#8217;s main function is where the program starts running (after any initialization). We shall learn more about functions in later tutorials.</p>
<pre class="prettyprint">func main()</pre>
<p>String constants can contain Unicode characters, encoded in UTF-8. The &#8216;\n&#8217; is the newline character as in C/C++.</p>
<p>The comment convention is the same as in C++:</p>
<pre class="prettyprint">/* ... */
// ...</pre>
<blockquote><p><strong>Did you find this tutorial on the Google Go programming language useful? Would you want more of such tutorials for learning about this great new programming language by Google?</strong></p></blockquote><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aprogrammerslife.wordpress.com/943/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aprogrammerslife.wordpress.com/943/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aprogrammerslife.wordpress.com/943/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aprogrammerslife.wordpress.com/943/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aprogrammerslife.wordpress.com/943/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aprogrammerslife.wordpress.com/943/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aprogrammerslife.wordpress.com/943/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aprogrammerslife.wordpress.com/943/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aprogrammerslife.wordpress.com/943/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aprogrammerslife.wordpress.com/943/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aprogrammerslife.wordpress.com/943/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aprogrammerslife.wordpress.com/943/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aprogrammerslife.wordpress.com/943/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aprogrammerslife.wordpress.com/943/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=943&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aprogrammerslife.wordpress.com/2010/07/26/how-to-write-a-hello-world-program-in-google-go/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f9a708756f1960644f371d3706cde2b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kevin</media:title>
		</media:content>
	</item>
		<item>
		<title>How To Install Google&#039;s Go Programming Language</title>
		<link>http://aprogrammerslife.wordpress.com/2010/07/24/how-to-install-googles-go-programming-language/</link>
		<comments>http://aprogrammerslife.wordpress.com/2010/07/24/how-to-install-googles-go-programming-language/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 05:30:32 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[Go Programming]]></category>
		<category><![CDATA[google go]]></category>

		<guid isPermaLink="false">http://kevinrodrigues.com/blog/?p=902</guid>
		<description><![CDATA[Introduction Go is a compiled, garbage-collected, concurrent programming language developed by Google. According to the Go website, Go is simple. Go is fast as typical builds take a fraction of a second and resulting programs run nearly as quickly as C or C++ code. Go is type safe and memory safe. Go promotes writing systems and servers as sets [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=902&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><!--OffDef--></p>
<h3>Introduction</h3>
<p><strong>Go</strong> is a compiled, garbage-collected, concurrent programming language developed by Google.</p>
<p>According to the <a title="Go Programming Language" href="http://golang.org/" target="_blank">Go website</a>,</p>
<ul>
<li>Go is simple.</li>
<li>Go is fast as typical builds take a fraction of a second and resulting programs run nearly as quickly as C or C++ code.</li>
<li>Go is type safe and memory safe.</li>
<li>Go promotes writing systems and servers as sets of lightweight communicating processes, called goroutines.</li>
<li>Go feels like a dynamic language but has the speed and safety of a static language.</li>
<li>Go is open source.</li>
</ul>
<p><a title="Go Language FAQ" href="http://golang.org/doc/go_faq.html#What_is_the_purpose_of_the_project" target="_blank">Google feels</a> that there is a need for another programming language because:</p>
<ul>
<li>Computers are enormously quicker but software development is not faster.</li>
<li>Dependency management is a big part of software development today but the “header files” of languages in the C tradition are antithetical to clean dependency analysis—and fast compilation.</li>
<li>There is a growing rebellion against cumbersome type systems like those of Java and C++, pushing people towards dynamically typed languages such as Python and JavaScript.</li>
<li>Some fundamental concepts such as garbage collection and parallel computation are not well supported by popular systems languages.</li>
<li>The emergence of multicore computers has generated worry and confusion.</li>
</ul>
<h3>Installation</h3>
<p>There are two Go compiler implementations, <code>6g</code> and friends, generically called <code>gc</code>, and <code>gccgo</code>. The <code>6g</code> (and <code>8g</code> and <code>5g</code>) compiler is named in the tradition of the Plan 9 C compilers, described in <a href="http://plan9.bell-labs.com/sys/doc/compiler.html">http://plan9.bell-labs.com/sys/doc/compiler.html</a>. <code>6</code> is the architecture letter for amd64 (or x86-64, if you prefer), while <code>g</code> stands for Go. gccgo is a more traditional compiler using the gcc back end.</p>
<p>Go implementations are currently available for the Linux and Mac OS X platforms. For Windows installation, you can try <a title="Go under MS Windows" href="http://code.google.com/p/go/wiki/WindowsPort" target="_blank">Go under MS Windows</a>.</p>
<p>This article focuses on installing the gc compiler for Ubuntu 10.04. However the steps should be similar for any Linux distribution.</p>
<p><strong>Installing the gc compiler:</strong></p>
<p><strong>1) Set up the environment variables</strong></p>
<p>Set these variables in your shell profile (<code>$HOME/.bashrc)</code></p>
<pre class="prettyprint">export GOROOT=$HOME/go #The root of the Go tree
export GOARCH=amd64 #The name of the target operating system (386, amd64, arm)
export GOOS=linux #The name of the compilation architecture (darwin, freebsd, linux, nacl)
export GOBIN=$HOME/go/bin #The location where binaries will be installed
export PATH=$PATH:$GOBIN</pre>
<p><strong>2) Install the C tools</strong></p>
<p>To build Go, you need to have GCC, the standard C libraries, the parser generator Bison, <tt>make</tt>, <tt>awk</tt>, and the text editor <tt>ed</tt> installed. On OS X, they can be installed as part of Xcode.</p>
<pre class="prettyprint">$ sudo apt-get install bison gcc libc6-dev ed gawk make</pre>
<p><strong>3) Fetch the repository</strong></p>
<p>You need Mercurial installed to get the Go repository. On Ubuntu, you can install this as:</p>
<pre class="prettyprint">$ sudo apt-get install mercurial</pre>
<p>Make sure the <code>$GOROOT</code> directory does not exist or is empty. Then check out the repository:</p>
<pre class="prettyprint">$ hg clone -r release <a href="https://go.googlecode.com/hg/" rel="nofollow">https://go.googlecode.com/hg/</a> $GOROOT</pre>
<p><!--Ads1--></p>
<p><strong>4) Install Go</strong></p>
<p>To build the Go distribution, run</p>
<pre class="prettyprint">$ cd $GOROOT/src
$ ./all.bash</pre>
<p>If all goes well, it will finish by printing</p>
<pre class="prettyprint">--- cd ../test
N known bugs; 0 unexpected bugs</pre>
<p>where <var>N</var> is a number that varies from release to release.</p>
<p><strong>5) Test the installation</strong></p>
<p>A sample program</p>
<pre class="prettyprint">package main

import "fmt"

func main()
{
   fmt.Printf("hello, world\n")
}</pre>
<p>Compile it using</p>
<pre class="prettyprint">$ 6g hello.go</pre>
<p>To link the file, use</p>
<pre class="prettyprint">$ 6l hello.6</pre>
<p>and to run it</p>
<pre class="prettyprint">$ ./6.out</pre>
<p>Now you should be able to compile and run programs written in the Go Programming language.</p>
<p><strong>6) Keeping up with releases</strong></p>
<p>New releases are announced on the <a href="http://groups.google.com/group/golang-nuts">Go Nuts</a> mailing list. To update an existing tree to the latest release, you can run:</p>
<pre class="prettyprint">$ cd $GOROOT/src
$ hg pull
$ hg update release
$ ./all.bash</pre>
<p>You can get more details about installing the Go gc compiler <a title="Installing Go gc" href="http://golang.org/doc/install.html" target="_blank">here</a>.</p>
<p><strong>Installing the gccgo compiler:</strong></p>
<p>You can get more details about installing the Go gccgo compiler <a title="Installing gccgo" href="http://golang.org/doc/gccgo_install.html" target="_blank">here</a>.</p>
<p><!--Ads4--></p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aprogrammerslife.wordpress.com/902/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aprogrammerslife.wordpress.com/902/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aprogrammerslife.wordpress.com/902/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aprogrammerslife.wordpress.com/902/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aprogrammerslife.wordpress.com/902/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aprogrammerslife.wordpress.com/902/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aprogrammerslife.wordpress.com/902/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aprogrammerslife.wordpress.com/902/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aprogrammerslife.wordpress.com/902/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aprogrammerslife.wordpress.com/902/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aprogrammerslife.wordpress.com/902/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aprogrammerslife.wordpress.com/902/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aprogrammerslife.wordpress.com/902/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aprogrammerslife.wordpress.com/902/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=902&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aprogrammerslife.wordpress.com/2010/07/24/how-to-install-googles-go-programming-language/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f9a708756f1960644f371d3706cde2b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kevin</media:title>
		</media:content>
	</item>
		<item>
		<title>The Ten Commandments for C++ Programmers</title>
		<link>http://aprogrammerslife.wordpress.com/2010/07/22/the-ten-commandments-for-c-programmers/</link>
		<comments>http://aprogrammerslife.wordpress.com/2010/07/22/the-ten-commandments-for-c-programmers/#comments</comments>
		<pubDate>Thu, 22 Jul 2010 14:40:25 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://kevinrodrigues.com/blog/?p=899</guid>
		<description><![CDATA[From the book &#8220;Practical C++ Programming&#8221; by Steve Oualline, The Ten Commandments for C++ Programmers written by Phin Straite. 1. Thou shalt not rely on the compiler default methods for construction, destruction, copy construction, or assignment for any but the simplest of classes. Thou shalt forget these &#8220;big four&#8221; methods for any nontrivial class. 2. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=899&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>From the book &#8220;Practical C++ Programming&#8221; by Steve Oualline, The Ten Commandments for C++ Programmers written by Phin Straite.</p>
<p>1. Thou shalt not rely on the compiler default methods for construction, destruction, copy construction, or assignment for any but the simplest of classes. Thou shalt forget these &#8220;big four&#8221; methods for any nontrivial class.</p>
<p>2. Thou shalt declare and define thy destructor as virtual such that others may become heir to the fruits of your labors.</p>
<p>3. Thou shalt not violate the &#8220;is-a&#8221; rule by abusing the inheritance mechanism for thine own twisted perversions.</p>
<p>4. Thou shalt not rely on any implementation-dependent behavior of a compiler, operating system, or hardware environment, lest thy code be forever caged within that dungeon.</p>
<p>5. Thou shalt not augment the interface of a class at the lowest level without most prudent deliberation. Such ill-begotten practices imprison thy clients unjustly into thy classes and create unrest when code maintenance and extension are required.</p>
<p>6. Thou shalt restrict thy friendship to truly worthy contemporaries. Beware, for thou art exposing thyself rudely as from a trenchcoat.</p>
<p>7. Thou shalt not abuse thy implementation data by making it public or static except in the rarest of circumstances. Thy data are thine own; share it not with others.</p>
<p>8. Thou shalt not suffer dangling pointers or references to be harbored within thy objects. They are nefarious and precarious agents of random and wanton destruction.</p>
<p>9. Thou shalt make use of available class libraries as conscientiously as possible. Code reuse, not just thine own but that of thy clients as well, is the Holy Grail of OO.</p>
<p>10. Thou shalt forever forswear the use of the vile printf/scanf, rather favoring the flowing streams. Cast off thy vile C cloak and partake of the wondrous fruit of flexible and extensible I/O.</p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aprogrammerslife.wordpress.com/899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aprogrammerslife.wordpress.com/899/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aprogrammerslife.wordpress.com/899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aprogrammerslife.wordpress.com/899/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aprogrammerslife.wordpress.com/899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aprogrammerslife.wordpress.com/899/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aprogrammerslife.wordpress.com/899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aprogrammerslife.wordpress.com/899/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aprogrammerslife.wordpress.com/899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aprogrammerslife.wordpress.com/899/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aprogrammerslife.wordpress.com/899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aprogrammerslife.wordpress.com/899/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aprogrammerslife.wordpress.com/899/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aprogrammerslife.wordpress.com/899/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=899&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aprogrammerslife.wordpress.com/2010/07/22/the-ten-commandments-for-c-programmers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f9a708756f1960644f371d3706cde2b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kevin</media:title>
		</media:content>
	</item>
		<item>
		<title>Today&#039;s Read: Four Ways To A Practical Code Review</title>
		<link>http://aprogrammerslife.wordpress.com/2010/07/20/todays-read-four-ways-to-a-practical-code-review/</link>
		<comments>http://aprogrammerslife.wordpress.com/2010/07/20/todays-read-four-ways-to-a-practical-code-review/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 15:57:40 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://kevinrodrigues.com/blog/?p=894</guid>
		<description><![CDATA[As per the definition of Wikipedia, Code review is systematic examination (often as peer review) of computer source code intended to find and fix mistakes overlooked in the initial development phase, improving both the overall quality of software and the developers&#8217; skills. In this article, Jason Cohen mentions that there exists a formalized system of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=894&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As per the definition of Wikipedia,</p>
<blockquote><p>Code review is systematic examination (often as peer review) of computer source code intended to find and fix mistakes overlooked in the initial development phase, improving both the overall quality of software and the developers&#8217; skills.</p></blockquote>
<p>In this article, Jason Cohen mentions that there exists a formalized system of code review developed by Micheal Fagan at IBM in the mid-1970s. However he points out that the software development process has come a long way since then and we can have process and metrics and measurement and improvement and happy developers all at the same time. The way to achieve this is by using a lightweight code review.</p>
<p>There are four types of lightweight code review techniques:</p>
<p><strong>1) Over-the-shoulder:</strong> One developer looks over the author&#8217;s shoulder as the latter walks through the code.<br />
This is the code review technique that we use in our organization and that I am familiar with. Once the implementation has reached a level of completion, we initiate such an over-the-shoulder code review process. One of the experienced peers working on the project acts as the reviewer and sits alongside the developer. The developer walksthrough the code implementation explaining why and how the implementation has been done. The reviewer can interrupt the review process to ask any queries and point out discrepancies in the implementation. Small changes can be fixed by the developer during the review process. Larger changes can be taken offline. Once the code review is complete, the developer can check in the changes to the SCM system.</p>
<p><strong>2) Email pass-around:</strong> The author (or SCM system) emails code to reviewers.<br />
This is the second-most common form of lightweight code review, and the technique preferred by most open-source projects. Here, whole files or changes are packaged up by the author and sent to reviewers via email. Reviewers examine the files, ask questions and discuss with the author and other developers, and suggest changes.</p>
<p><strong>3) Pair Programming:</strong> Two authors develop code together at the same workstation.<br />
Pair-programming is two developers writing code at a single workstation with only one developer typing at a time and continuous free-form discussion and review.</p>
<p>4<strong>) Tool-assisted:</strong> Authors and reviewers use specialized tools designed for peer code review.<br />
This refers to any process where specialized tools are used in all aspects of the review: collecting files, transmitting and displaying files, commentary, and defects among all participants, collecting metrics, and giving product managers and administrators some control over the workflow.</p>
<p>The complete article by Jason Cohen can be found at: <a href="http://www.methodsandtools.com/archive/archive.php?id=66">Four ways to a Practical Code Review</a>.</p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aprogrammerslife.wordpress.com/894/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aprogrammerslife.wordpress.com/894/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aprogrammerslife.wordpress.com/894/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aprogrammerslife.wordpress.com/894/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aprogrammerslife.wordpress.com/894/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aprogrammerslife.wordpress.com/894/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aprogrammerslife.wordpress.com/894/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aprogrammerslife.wordpress.com/894/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aprogrammerslife.wordpress.com/894/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aprogrammerslife.wordpress.com/894/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aprogrammerslife.wordpress.com/894/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aprogrammerslife.wordpress.com/894/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aprogrammerslife.wordpress.com/894/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aprogrammerslife.wordpress.com/894/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=894&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aprogrammerslife.wordpress.com/2010/07/20/todays-read-four-ways-to-a-practical-code-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f9a708756f1960644f371d3706cde2b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kevin</media:title>
		</media:content>
	</item>
		<item>
		<title>The History Of Carriage Return Line Feed</title>
		<link>http://aprogrammerslife.wordpress.com/2010/07/18/the-history-of-line-feed/</link>
		<comments>http://aprogrammerslife.wordpress.com/2010/07/18/the-history-of-line-feed/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 04:44:29 +0000</pubDate>
		<dc:creator>Kevin</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://kevinrodrigues.com/blog/?p=877</guid>
		<description><![CDATA[Most of us developers (especially Windows developers) wonder why an end-of-line is represented by &#60;carriage return&#62;&#60;line feed&#62; in Windows text files. What does &#60;carriage return&#62; or &#60;line feed&#62; exactly mean? In the early stages before computers, there existed a device known as the TeleType. The TeleType contained a keyboard, printer, and paper tape reader/punch. It could [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=877&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Most of us developers (especially Windows developers) wonder why an end-of-line is represented by &lt;carriage return&gt;&lt;line feed&gt; in Windows text files. What does &lt;carriage return&gt; or &lt;line feed&gt; exactly mean?</p>
<p>In the early stages before computers, there existed a device known as the TeleType. The TeleType contained a keyboard, printer, and paper tape reader/punch. It could transmit messages over telephones using a modem at a rate of 10 characters per second.</p>
<p><img class="aligncenter size-full wp-image-878" title="TeleType" src="http://aprogrammerslife.files.wordpress.com/2010/07/teletype1.jpg?w=632" alt="TeleType"   /></p>
<p>But TeleType had a problem. It took 0.2 seconds to move the printhead from the right side to the left. 0.2 seconds is two character times. If a second character came while the printhead was in the middle of a return, that character was lost.</p>
<p>The TeleType people solved this problem by making end-of-line two characters: &lt;carriage return&gt; to position the printhead at the left margin, and &lt;line feed&gt; to move the paper up one line. That way the &lt;line feed&gt; &#8220;printed&#8221; whilethe printhead was racing back to the left margin.</p>
<p>When the early computers came out, some designers realized that using two characters for end-of-line wasted storage. Some picked &lt;line feed&gt; for their end-of-line, and some chose &lt;carriage return&gt;. Some of the die-hards stayed with the two-character sequence.</p>
<p>Unix uses &lt;line feed&gt; for end-of-line. The newline character \n is code 0xA (LF or &lt;line feed&gt;). MS-DOS/Windows uses the two characters &lt;carriage return&gt;&lt;line feed&gt;. So if you are transferring text files from a Unix machine to Windows, you have to use some conversion utility eg. unix2dos for stripping the &lt;carriage return&gt; character from the files.</p>
<p><strong>Further reading:</strong><br />
<a href="http://kb.iu.edu/data/acux.html">How do I convert between Unix and Windows text files?</a><br />
<a href="http://en.wikipedia.org/wiki/Newline">Newline Character</a></p><br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/aprogrammerslife.wordpress.com/877/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/aprogrammerslife.wordpress.com/877/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/aprogrammerslife.wordpress.com/877/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/aprogrammerslife.wordpress.com/877/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/aprogrammerslife.wordpress.com/877/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/aprogrammerslife.wordpress.com/877/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/aprogrammerslife.wordpress.com/877/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/aprogrammerslife.wordpress.com/877/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/aprogrammerslife.wordpress.com/877/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/aprogrammerslife.wordpress.com/877/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/aprogrammerslife.wordpress.com/877/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/aprogrammerslife.wordpress.com/877/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/aprogrammerslife.wordpress.com/877/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/aprogrammerslife.wordpress.com/877/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=aprogrammerslife.wordpress.com&amp;blog=7251551&amp;post=877&amp;subd=aprogrammerslife&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://aprogrammerslife.wordpress.com/2010/07/18/the-history-of-line-feed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f9a708756f1960644f371d3706cde2b5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Kevin</media:title>
		</media:content>

		<media:content url="http://aprogrammerslife.files.wordpress.com/2010/07/teletype1.jpg" medium="image">
			<media:title type="html">TeleType</media:title>
		</media:content>
	</item>
	</channel>
</rss>
