Dynamic object-oriented programming support for the Go language

Goop

GoDoc Go Report Card

Description

The Goop (Go Object-Oriented Programming) package provides support for dynamic object-oriented programming constructs in Go, much like those that appear in various scripting languages. The goal is to integrate fast, native-Go objects and slower but more flexible Goop objects within the same program.

Features

Goop provides the following features, which are borrowed from an assortment of object-oriented programming languages:

  • a prototype-based object model

  • support for both ex nihilo and constructor-based object creation

  • the ability to add, replace, and remove data fields and method functions at will

  • multiple inheritance

  • dynamically modifiable inheritance hierarchies (even on a per-object basis)

  • type-dependent dispatch (i.e., multiple methods with the same name but different argument types)

Installation

Install Goop with go get:

    go get github.com/lanl/goop

Documentation

Pre-built documentation for the Goop API is available online at http://godoc.org/github.com/lanl/goop, courtesy of GoDoc.

Once you install Goop, you can view the API locally with godoc, for example by running

    godoc github.com/lanl/goop

to display the Goop documentation on screen or by running

    godoc -http=:6060

to start a local Web server then viewing the HTML-formatted documentation at http://localhost:6060/pkg/github.com/lanl/goop/ in your favorite browser.

Performance

Goop is unfortunately extremely slow. Goop programs have to pay for their flexibility in terms of performance. To determine just how bad the performance is on your computer, you can run the microbenchmarks included in goop_test.go:

    go test -bench=. -benchtime=5s github.com/lanl/goop

On my computer, I get results like the following (reformatted for clarity):

    BenchmarkNativeFNV1             2000000000                 4.59 ns/op
    BenchmarkNativeFNV1Closure      2000000000                 4.59 ns/op
    BenchmarkGoopFNV1                100000000                70.5  ns/op
    BenchmarkMoreGoopFNV1             10000000               794    ns/op
    BenchmarkEvenMoreGoopFNV1          5000000              2517    ns/op

See goop_test.go for the complete source code for those benchmarks. Basically,

  • BenchmarkNativeFNV1 is native (i.e., non-Goop) Go code for computing a 64-bit FNV-1 hash on a sequence of 0xFF bytes. Each iteration ("op" in the performance results) comprises a nullary function call, a multiplication by a large prime number, and an exclusive or with an 0xFF byte.

  • BenchmarkNativeFNV1Closure is the same but instead of calling an ordinary function each iteration, it invokes a locally defined closure.

  • BenchmarkGoopFNV1 defines a Goop object that contains a single data field (the current hash value) and no methods. Each iteration performs one Get and one Set on the Goop object.

  • BenchmarkMoreGoopFNV1 replaces the hash function with an object method. Hence, each iteration performs one Get, one Set, and one Call on the Goop object.

  • BenchmarkEvenMoreGoopFNV1 adds support for type-dependent dispatch to the hash-function method. Although only one type signature is defined, Goop has to confirm at run time that the provided arguments do in fact match that signature.

Another way to interpret the data shown above is that, on my computer at least, a function closure is essentially free; Get and Set cost approximately 33 ns apiece; a Call of a nullary function costs about 724 ns; and type-dependent dispatch costs an additional 1723 ns.

How does Goop compare to various scripting languages? Not well, at least for BenchmarkMoreGoopFNV1 and its equivalents in other languages. The following table shows the cost in nanoseconds of an individual BenchmarkMoreGoopFNV1 operation (a function call, a read of a data field, a 64-bit multiply, an 8-bit exclusive or, and a write to a data field):

Language Run time (ns/op)
[Incr Tcl] 8.6.0 24490
Go 1.3.1 + Goop 794
JavaScript 1.7 (Rhino 1.7R4-2) 682
Perl 5.18.2 622
Python 2.7.6 604
Python 3.4.0 567
Ruby 1.9.3.4 513
Python 2.7.3 + PyPy 206

In short, you'll want to do most of your coding in native Go and use Goop only when your application requires the extra flexibility that Goop provides. Then, you should cache as many object members as possible in Go variables to reduce the number of Get and Set calls.

License

Goop is provided under a BSD-ish license with a "modifications must be indicated" clause. See http://github.com/lanl/goop/blob/master/LICENSE.md for the full text.

Triad National Security, LLC (Triad) owns the copyright to Goop, a component of the LANL Go Suite (identified internally as LA-CC-11-056).

Author

Scott Pakin, [email protected]

Owner
Los Alamos National Laboratory
Los Alamos National Laboratory
Similar Resources

Learning Golang Language In Clean Structure

Learning Golang Language In Clean Structure At this example project, I'm trying to learn Golang with Clean structure and come up with a reusable, nice

Sep 25, 2022

Dabulang is an interpreted object-oriented programming language aimed towards game development.

Dabulang (ダブ言語) Dabulang is an interpreted object-oriented programming language aimed towards game development. The language's standard library has a

Sep 14, 2022

T# Programming Language. Something like Porth, Forth but written in Go. Stack-oriented programming language.

The T# Programming Language WARNING! THIS LANGUAGE IS A WORK IN PROGRESS! ANYTHING CAN CHANGE AT ANY MOMENT WITHOUT ANY NOTICE! Something like Forth a

Jun 29, 2022

A cutting edge (haha), prototype, object-oriented and highly modular slash command handler for Discordgo.

A cutting edge (haha), prototype, object-oriented and highly modular slash command handler for Discordgo.

ken ⚠️ Disclaimer This package is still in a very early state of development and future updates might include breaking changes to the API until the fi

Dec 12, 2022

A stack oriented esoteric programming language inspired by poetry and forth

paperStack A stack oriented esoteric programming language inspired by poetry and forth What is paperStack A stack oriented language An esoteric progra

Nov 14, 2021

Stack-oriented programming language

aiur Stack-oriented programming language TODO Operators If statements Loops Procedures Include statements Package manager Syntax Conditional conditio

May 20, 2022

Floppa programming language inspired by the brainf*ck programming language. Created just for fun and you can convert your brainf*ck code to floppa code.

Floppa Programming Language Created just for fun. But if you want to contribute, why not? Floppa p.l. inspired by the brainf*ck programming language.

Oct 20, 2022

Yayx programming language is begginer friendly programming language.

Yayx programming language is begginer friendly programming language.

Yayx Yayx programming language is begginer friendly programming language. What have yayx: Easy syntax Dynamic types Can be compiled to outhers program

Dec 27, 2021

Yayx programming language is begginer friendly programming language.

Yayx Yayx programming language is begginer friendly programming language. What have yayx: Easy syntax Dynamic types Can be compiled to outhers program

May 20, 2022

Lithia is an experimental functional programming language with an implicit but strong and dynamic type system.

Lithia is an experimental functional programming language with an implicit but strong and dynamic type system. Lithia is designed around a few core concepts in mind all language features contribute to.

Dec 24, 2022

The Dual-Stack Dynamic DNS client, the world's first dynamic DNS client built for IPv6.

dsddns DsDDNS is the Dual-Stack Dynamic DNS client. A dynamic DNS client keeps your DNS records in sync with the IP addresses associated with your hom

Sep 27, 2022

Logger - Go language is interface-oriented to implement an asynchronous log writing program

logger日志库 1、安装 go get github.com/staryjie/logger@latest 2、使用 示例: package main import ( "github.com/staryjie/logger" "time" ) func initLogger(name,

Jan 4, 2022

Yay - Yet another stack-oriented toy language that transpiles to Go code. Heavily inspired by Tsoding's Porth YouTube series

yay Yet another stack-oriented toy language that transpiles to Go code. Heavily

Feb 12, 2022

Becca - A simple dynamic language for exploring language design

Becca A simple dynamic language for exploring language design What is Becca Becc

Aug 15, 2022

LevelDB style LRU cache for Go, support non GC object.

Go语言QQ群: 102319854, 1055927514 凹语言(凹读音“Wa”)(The Wa Programming Language): https://github.com/wa-lang/wa LRU Cache Install go get github.com/chai2010/c

Jul 5, 2020

QingStor Object Storage service support for go-storage

go-services-qingstor QingStor Object Storage service support for go-storage. Install go get github.com/minhjh/go-service-qingstor/v3 Usage import ( "

Dec 13, 2021

Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

Advent of Code 2021 Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved

Dec 2, 2021

Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like. This repository holds my submission/answers for these challenges.

Advent of Code - Zach Howell's Answers Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels

Jan 4, 2022
Related tags
Generates data structure definitions from JSON files for any kind of programming language

Overview Archivist generates data structure definitions from JSON files for any kind of programming language. It also provides a library for golang to

Jun 28, 2022
A serverless cluster computing system for the Go programming language

Bigslice Bigslice is a serverless cluster data processing system for Go. Bigslice exposes composable API that lets the user express data processing ta

Dec 14, 2022
Tutorial code for my video Beginner Programming with Golang - Conways Game of Life

Beginner Programming with Golang - Conways Game of Life Who is this tutorial for? Programming beginners and people with programming experience who wan

Jan 26, 2022
Solutions to AlgoExpert Problems in Six Programming Languages: Python, Java, Go, C++, C#, JavaScript/TypeScript
Solutions to AlgoExpert Problems in Six Programming Languages: Python, Java, Go, C++, C#, JavaScript/TypeScript

Solutions to AlgoExpert Problems in Six Programming Languages: Python, Java, Go, C++, C#, JavaScript/TypeScript Discover solutions to AlgoExpert probl

Dec 11, 2022
A codec for Go structs with support for chainable encoding/decoding hooks.

structool A codec for Go structs with support for chainable encoding/decoding hooks. Features Provide a uniform codec by combining mapstructure and st

Jan 15, 2022
Go strcut based enum, support all types.

go-ultra-enum go-ultra-enum is an enum generator for Go. It is inspired by the powerful enum types found in Java. go-ultra-enum has the following capa

Dec 21, 2021
A slice backed binary heap with support for generic type parameters.

go-binaryheap A slice backed binary heap where the order can be customized by a comparison function. The main branch now requires go 1.18 because the

Jun 13, 2022
A Go implementation of an in-memory bloom filter, with support for boltdb and badgerdb as optional data persistent storage.

Sprout A bloom filter is a probabilistic data structure that is used to determine if an element is present in a set. Bloom filters are fast and space

Jul 4, 2022
A simple set type for the Go language. Trusted by Docker, 1Password, Ethereum and Hashicorp.

golang-set The missing set collection for the Go language. Until Go has sets built-in...use this. Coming from Python one of the things I miss is the s

Jan 8, 2023
gtreap is an immutable treap implementation in the Go Language

gtreap gtreap is an immutable treap implementation in the Go Language Overview gtreap implements an immutable treap data structure in golang. By treap

Dec 11, 2022