OLD | NEW |
1 <!-- Effective Go --> | 1 <!-- Effective Go --> |
2 | 2 |
3 <h2 id="introduction">Introduction</h2> | 3 <h2 id="introduction">Introduction</h2> |
4 | 4 |
5 <p> | 5 <p> |
6 Go is a new language. Although it borrows ideas from | 6 Go is a new language. Although it borrows ideas from |
7 existing languages, | 7 existing languages, |
8 it has unusual properties that make effective Go programs | 8 it has unusual properties that make effective Go programs |
9 different in character from programs written in its relatives. | 9 different in character from programs written in its relatives. |
10 A straightforward translation of a C++ or Java program into Go | 10 A straightforward translation of a C++ or Java program into Go |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 f, err := os.Open(filename, os.O_RDONLY, 0) | 787 f, err := os.Open(filename, os.O_RDONLY, 0) |
788 if err != nil { | 788 if err != nil { |
789 return "", err | 789 return "", err |
790 } | 790 } |
791 defer f.Close() // f.Close will run when we're finished. | 791 defer f.Close() // f.Close will run when we're finished. |
792 | 792 |
793 var result []byte | 793 var result []byte |
794 buf := make([]byte, 100) | 794 buf := make([]byte, 100) |
795 for { | 795 for { |
796 n, err := f.Read(buf[0:]) | 796 n, err := f.Read(buf[0:]) |
797 result = bytes.Add(result, buf[0:n]) | 797 result = append(result, buf[0:n]...) |
798 if err != nil { | 798 if err != nil { |
799 if err == os.EOF { | 799 if err == os.EOF { |
800 break | 800 break |
801 } | 801 } |
802 return "", err // f will be closed if we return here. | 802 return "", err // f will be closed if we return here. |
803 } | 803 } |
804 } | 804 } |
805 return string(result), nil // f will be closed if we return here. | 805 return string(result), nil // f will be closed if we return here. |
806 } | 806 } |
807 </pre> | 807 </pre> |
(...skipping 2132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2940 <pre> | 2940 <pre> |
2941 verifying implementation | 2941 verifying implementation |
2942 type Color uint32 | 2942 type Color uint32 |
2943 ···· | 2943 ···· |
2944 // Check that Color implements image.Color and image.Image | 2944 // Check that Color implements image.Color and image.Image |
2945 var _ image.Color = Black | 2945 var _ image.Color = Black |
2946 var _ image.Image = Black | 2946 var _ image.Image = Black |
2947 </pre> | 2947 </pre> |
2948 --> | 2948 --> |
2949 | 2949 |
OLD | NEW |