Example: marketing

GoHotDraw: Evaluating the Go Programming Language with ...

gohotdraw : Evaluating the Go ProgrammingLanguage with design PatternsFrank SchmagerVictoria University of Wellington,New CameronVictoria University of Wellington,New NobleVictoria University of Wellington,New a new Programming Language backed by Google, has the po-tential for widespread use: it deserves an evaluation. design pat-terns are records of idiomatic Programming practice and informprogrammers about good program design . In this study, we evalu-ate Go by implementing design patterns , and porting the pattern-dense drawing framework HotDraw into Go, producing GoHot-Draw. We show how Go s Language features affect the implemen-tation of design patterns , identify some potential Go programmingpatterns, and demonstrate how studying design patterns can con-tribute to the evaluation of a Programming and Subject [ Programming Lan-guages]: GeneralGeneral TermsDesign, LanguagesKeywordsGo, design Patterns1.

GoHotDraw: Evaluating the Go Programming Language with Design Patterns Frank Schmager ... New Zealand ncameron@ecs.vuw.ac.nz James Noble Victoria University of Wellington, New Zealand kjx@ecs.vuw.ac.nz Abstract Go, a new programming language backed by Google, has the po-tential for widespread use: it deserves an evaluation. ... In this section ...

Tags:

  Programming, Language, With, Design, Evaluating, Patterns, Programming language, Gohotdraw, Evaluating the go programming language, Evaluating the go programming language with design patterns

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of GoHotDraw: Evaluating the Go Programming Language with ...

1 gohotdraw : Evaluating the Go ProgrammingLanguage with design PatternsFrank SchmagerVictoria University of Wellington,New CameronVictoria University of Wellington,New NobleVictoria University of Wellington,New a new Programming Language backed by Google, has the po-tential for widespread use: it deserves an evaluation. design pat-terns are records of idiomatic Programming practice and informprogrammers about good program design . In this study, we evalu-ate Go by implementing design patterns , and porting the pattern-dense drawing framework HotDraw into Go, producing GoHot-Draw. We show how Go s Language features affect the implemen-tation of design patterns , identify some potential Go programmingpatterns, and demonstrate how studying design patterns can con-tribute to the evaluation of a Programming and Subject [ Programming Lan-guages]: GeneralGeneral TermsDesign, LanguagesKeywordsGo, design Patterns1.

2 IntroductionGo is a new object-oriented Programming Language , developed atGoogle by Rob Pike and others. Go is used internally at Googlefor some production stuff [18] and has found an active communitysince its publication in November 2009 [1]. This paper describesour experiences implementing the patterns fromDesign patterns [9], and the HotDraw drawing editor framework in Go. We discussthe differences between our implementations of design patternsin Go and in other Programming languages (primarily Java) andsuggest Programming idioms in Go that may develop into researchers have proposed methods and criteria for eval-uating Programming languages [26, 22]. Direct comparisons ofprogramming languages have been conducted: a comparison ofJava with C][5]; a comparison of FORTRAN-77, C, Pascal andModula-2 [13].

3 Others investigated suitability as a first program-ming Language : Parker et al. compiled a list of criteria for introduc-tory Programming courses at universities [20]; McIver proposedevaluating languages together with IDEs [16]; Hadjerrouit exam-ined Java s suitability as a first Programming Language [11]; Clarkeused questionnaires to evaluate a Programming Language [6]; GuptaCopyright is held by the author/owner(s). This paper was published in the proceed-ings of the Workshop on Evaluation and Usability of Programming Languages andTools (PLATEAU) at the ACM Onward! and SPLASH Conferences. October, , Nevada, requirements for Programming languages for beginners[10]. The methods and criteria proposed in the literature are usu-ally hard to measure and are prone to be this paper, we use design patterns to evaluate a programminglanguage.

4 There are a number of books describing the GoF designpatterns in different Programming languages (Smalltalk [4], Java[17], JavaScript [12], Ruby [19]). Implementations of design pat-terns differ due to specifics of the Language used. There is a needfor Programming Language specific pattern descriptions. Our useof patterns should give programmers insight into how Go-specificlanguage features are used in everyday Programming , and how gapscompared with other languages can be have implemented all 23 patterns fromDesign PatternsinGo: for space reasons we discuss only the Singleton, Adapter, andTemplate Method patterns in this paper. The implementations ofthese patterns illuminate specific Go Language features: Singletondemonstrates how Go s source code is structured in packages ratherthan classes, and Go s visibility rules; Adapter allows us to com-pare embedding with composition in Go; and Template Method il-lustrates the flow of control between embedding and embedded ob-jects.

5 To investigate how design patterns integrate in Go, we portedthe core of the well-known drawing frameworkHotDrawinto Go, paper is organised as follows: in Sect. 2 we give a briefoverview of Go; in Sect. 3 we present case studies implementingthree design patterns and JHotDraw in Go; in Sect. 4 we discussour experience using Go, with a focus on design patterns ; in Sect. 5we discuss future work; in Sect. 6 we BackgroundIn this section we introduce the Go Programming The Go Programming LanguageGo is an object-oriented Programming Language with a C-like syn-tax. Go is designed as a systems Language and has a focus on con-currency; it is expressive, concurrent, garbage-collected [3]. Itsupports a mixture of static and dynamic typing, and is designed tobe safe and efficient.

6 A primary motivation seems to be compilationspeed (and indeed, Go programs compile blazingly fast).Go has objects, and structs rather than classes. Go has no con-cept of inheritance, reuse is supported byembedding. There are noexplicit subtype declarations, but in some cases, structural subtypesare inferred. Pointers are explicit and indicated by an asterisk be-fore the type. Unlike C, however, pointer arithmetic is not and methodsThe following code example defines thetypeCarwith a single fieldaffordablewith typebool:type Car struct {affordable bool}Following C++ rather than Java, methods in Go are definedoutside struct declarations. Multiple return values are allowed andmay be named; the receiver must be explicitly named. Go does notsupport overloading or following listing defines the methodRefuelforCarob-jects:func (this *Car) Refuel(liter int) (price float) {.}

7 }EmbeddingReuse in Go is supported by embedding. If a methodor field cannot be found in an object s type definition, then em-bedded types are searched, and method calls are forwarded to theembedded object. This is similar to subclassing, the difference insemantics is that an embedded object is a distinct object, and fur-ther dispatch operates on the embedded object, not the embeddingone. For example, the following code shows aTrucktype whichembeds theCartype and, therefore, gains the methodRefuel:type Truck struct {Caraffordable bool}Objects can be deeply embedded and multiply embedded. Nameconflicts are only a problem if the ambiguous element is in Go are abstract representations of be-haviour sets of methods. The Go compiler infers if an objectsatisfies an interface.

8 This part of the type system is structural: ifan object implements the methods of an interface, then it has thatinterface as a type. No annotation by the programmer is are allowed to embed other interfaces: the embeddinginterface will contain all the methods of the embedded is no explicit subtyping between interfaces, but since typechecking for interfaces is structural and implicit, if an object im-plements an embedding interface, then it will always implementany embedded interfaces. Every object implements the empty in-terfaceinterface; other, user-defined empty interfaces may alsobe defined. The listing below definesRefuelableas an interfacewith a single methodRefuel().type Refuelable interface {Refuel(int) float}BothCarandTruckimplement this interface, even though itis not listed in their definitions (and indeed,Refuelablemayhave been defined long afterwards).

9 Type checking of non-interfacetypes is not structural: aTruckcannot be used where and goroutinesGo supports functions (methods withno receiver) as well as function pointers and functions that execute in parallel with other goroutines. Gorou-tines are designed to be lightweight and to hide many of the com-plexities of thread creation and management. The keyword go infront of a function call executes the function in its own can communicate (asynchronously) with other gorou-tines initialisationGo objects can be created from struct defini-tions with or without thenewkeyword. Fields can be initialised bythe user when the object is initialised, but there are no created objects in Go are always initialised with a defaultvalue (nil,0,false,"", etc.). There are multiple ways to createobjects.

10 On each line in the following listing, anExampleobjectis created and a pointer to the new object stored inanExample. Ineach case the fields have the following == "" == anExample *Example2anExample = new(Example)3anExample = &Example {}4anExample = &Example {"",0}5anExample = &Example{Name:"", aField :0}PackagesGo source code is structured in packages. Go providestwo scopes of visibility: members beginning with a lower caseletter ( ,affordable) are only accessible inside their package;members beginning with an upper case letter ( ,Car,Refuel())are publicly Case StudiesWe have implemented all 23 GoF design patterns in Go. In thissection, we describe our experience in implementing three of them:Singleton, Adaptor, and Template SingletonThe Singleton design pattern [9] ensures that only a single instanceof a type exists in a program, and provides a global access point tothat Java, Singletons are implemented with static fields.


Related search queries