Benutzer-Werkzeuge

Webseiten-Werkzeuge


becki:linux:golang

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
becki:linux:golang [2011-11-07 14:32]
becki
becki:linux:golang [2018-02-26 11:24] (aktuell)
becki
Zeile 142: Zeile 142:
   * Arrays are copied by value :!:   * Arrays are copied by value :!:
   * A Pointer to an array is possible (unlike in C where the pointer represents the array)   * A Pointer to an array is possible (unlike in C where the pointer represents the array)
 +
 </​note>​ </​note>​
  
Zeile 189: Zeile 190:
  
 <note tip> <note tip>
- 
   * Slices are copied //by value// but the internal arrays are copied //by reference// :!:   * Slices are copied //by value// but the internal arrays are copied //by reference// :!:
   * Slices have a length (number of items) and a capacity (length of underlying array(?))   * Slices have a length (number of items) and a capacity (length of underlying array(?))
 +
 </​note>​ </​note>​
 <note important>​Appending to a Slice results in a new slice. The new slice may point to a different array than the original slice.</​note>​ <note important>​Appending to a Slice results in a new slice. The new slice may point to a different array than the original slice.</​note>​
Zeile 259: Zeile 260:
   * In order to really work on the object, the receiver of the method must be a //pointer// to the object, otherwise the method operates ony on an (anonymous) copy.   * In order to really work on the object, the receiver of the method must be a //pointer// to the object, otherwise the method operates ony on an (anonymous) copy.
   * Invoking methods on //pointers to objects// has the same syntax and work the same as invoking the method directly on the object.   * Invoking methods on //pointers to objects// has the same syntax and work the same as invoking the method directly on the object.
 +
 </​note>​ </​note>​
  
Zeile 322: Zeile 324:
   * Implement the methods of the interface with an object //pointer// as receiver   * Implement the methods of the interface with an object //pointer// as receiver
   * Instantiate the interface with the //adress// of the object   * Instantiate the interface with the //adress// of the object
 +
 </​note>​ </​note>​
 <note important>​Some :?: library functions which return an interface in reality return a pointer to an implementation of the interface (see e.g. [[golang>​pkg/​net/#​Listener.Listen|net.Listen]])</​note>​ <note important>​Some :?: library functions which return an interface in reality return a pointer to an implementation of the interface (see e.g. [[golang>​pkg/​net/#​Listener.Listen|net.Listen]])</​note>​
Zeile 327: Zeile 330:
 ===== Handling Errors == ===== Handling Errors ==
  
-Defer, Panic, Recover: http://​blog.golang.org/​2010_08_01_archive.html ​=> The convention in the Go libraries is that even when a package uses panic internally, its external API still returns explicit ''​os.Error''​ values.+Defer, Panic, Recover: http://​blog.golang.org/​2010_08_01_archive.html ​⇒ The convention in the Go libraries is that even when a package uses panic internally, its external API still returns explicit ''​os.Error''​ values.
  
 [[golang>​pkg/​os/#​Error|os.Error]] is the same interface as [[golang>​pkg/​fmt/#​Stringer|fmt.Stringer]],​ i.e. it has a method called ''​String()''​ wich returns a ''​string''​. Thus an instance of os.Error can always be passed to the functions in ''​fmt''​ and ''​log''​ directly, without explicitely calling the ''​String()''​ method. E.g: [[golang>​pkg/​os/#​Error|os.Error]] is the same interface as [[golang>​pkg/​fmt/#​Stringer|fmt.Stringer]],​ i.e. it has a method called ''​String()''​ wich returns a ''​string''​. Thus an instance of os.Error can always be passed to the functions in ''​fmt''​ and ''​log''​ directly, without explicitely calling the ''​String()''​ method. E.g:
becki/linux/golang.1320676361.txt.gz · Zuletzt geändert: 2011-11-07 14:32 von becki

Impressum - Datenschutzerklärung