{"id":22668630,"url":"https://github.com/lanl/goop","last_synced_at":"2025-04-12T11:08:55.861Z","repository":{"id":1647470,"uuid":"2373100","full_name":"lanl/goop","owner":"lanl","description":"Dynamic object-oriented programming support for the Go language","archived":false,"fork":false,"pushed_at":"2022-08-17T00:21:36.000Z","size":38,"stargazers_count":111,"open_issues_count":0,"forks_count":18,"subscribers_count":25,"default_branch":"master","last_synced_at":"2024-06-27T00:19:01.295Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lanl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-09-12T18:19:30.000Z","updated_at":"2024-02-18T09:00:14.000Z","dependencies_parsed_at":"2022-07-12T14:56:29.616Z","dependency_job_id":null,"html_url":"https://github.com/lanl/goop","commit_stats":null,"previous_names":["losalamos/goop"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lanl%2Fgoop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lanl%2Fgoop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lanl%2Fgoop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lanl%2Fgoop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lanl","download_url":"https://codeload.github.com/lanl/goop/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228911888,"owners_count":17990774,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-09T15:16:02.155Z","updated_at":"2024-12-09T15:16:02.940Z","avatar_url":"https://github.com/lanl.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"Goop\n====\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/lanl/goop.svg)](https://pkg.go.dev/github.com/lanl/goop) [![Go Report Card](https://goreportcard.com/badge/github.com/lanl/goop)](https://goreportcard.com/report/github.com/lanl/goop)\n\nDescription\n-----------\n\nThe 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.\n\nFeatures\n--------\n\nGoop provides the following features, which are borrowed from an assortment of object-oriented programming languages:\n\n* a [prototype-based object model](http://en.wikipedia.org/wiki/Prototype-based_programming)\n\n* support for both *ex nihilo* and constructor-based object creation\n\n* the ability to add, replace, and remove data fields and method functions at will\n\n* multiple inheritance\n\n* dynamically modifiable inheritance hierarchies (even on a per-object basis)\n\n* type-dependent dispatch (i.e., multiple methods with the same name but different argument types)\n\nInstallation\n------------\n\nGoop is a Go module and therefore does not need to be installed manually.  Simply import it as `github.com/lanl/goop`, and `go build` should download and install the code automatically.\n\nDocumentation\n-------------\n\nPre-built documentation for the Goop API is available online at \u003chttps://pkg.go.dev/github.com/lanl/goop\u003e.\n\nPerformance\n-----------\n\nGoop is unfortunately extremely slow.  Goop programs have to pay for\ntheir flexibility in terms of performance.  To determine just how bad\nthe performance is on your computer, you can run the microbenchmarks\nincluded in\n[`goop_test.go`](http://github.com/lanl/goop/blob/master/goop_test.go):\n\n\u003cpre\u003e\n    go test -bench=. -benchtime=5s github.com/lanl/goop\n\u003c/pre\u003e\n\nOn my computer, I get results like the following (reformatted for\nclarity):\n\n\u003cpre\u003e\n    BenchmarkNativeFNV1             2000000000                 4.59 ns/op\n    BenchmarkNativeFNV1Closure      2000000000                 4.59 ns/op\n    BenchmarkGoopFNV1                100000000                70.5  ns/op\n    BenchmarkMoreGoopFNV1             10000000               794    ns/op\n    BenchmarkEvenMoreGoopFNV1          5000000              2517    ns/op\n\u003c/pre\u003e\n\nSee [`goop_test.go`](http://github.com/lanl/goop/blob/master/goop_test.go) for the complete source code for those benchmarks.  Basically,\n\n* `BenchmarkNativeFNV1` is native (i.e., non-Goop) Go code for computing a 64-bit [FNV-1 hash](http://isthe.com/chongo/tech/comp/fnv/) 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.\n\n* `BenchmarkNativeFNV1Closure` is the same but instead of calling an ordinary function each iteration, it invokes a locally defined closure.\n\n* `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.\n\n* `BenchmarkMoreGoopFNV1` replaces the hash function with an object method.  Hence, each iteration performs one `Get`, one `Set`, and one `Call` on the Goop object.\n\n* `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.\n\nAnother 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\u0026nbsp;ns apiece; a `Call` of a nullary function costs about 724\u0026nbsp;ns; and type-dependent dispatch costs an additional 1723\u0026nbsp;ns.\n\nHow 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\u0026nbsp;or, and a write to a data field):\n\n\u003ctable style=\"border-collapse: collapse; margin-left: auto; margin-right: auto\"\u003e\n  \u003ctr\u003e\n    \u003cth style=\"text-align: left; border-top: solid medium; border-bottom: solid thin\"\u003eLanguage\u003c/th\u003e\n    \u003cth style=\"text-align: right; border-top: solid medium; border-bottom: solid thin\"\u003eRun time (ns/op)\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e[Incr Tcl] 8.6.0\u003c/td\u003e\n    \u003ctd style=\"text-align: right\"\u003e24490\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr style=\"background-color: yellow\"\u003e\n    \u003ctd\u003eGo 1.3.1 + Goop\u003c/td\u003e\n    \u003ctd style=\"text-align: right\"\u003e794\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eJavaScript 1.7 (Rhino 1.7R4-2)\u003c/td\u003e\n    \u003ctd style=\"text-align: right\"\u003e682\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ePerl 5.18.2\u003c/td\u003e\n    \u003ctd style=\"text-align: right\"\u003e622\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ePython 2.7.6\u003c/td\u003e\n    \u003ctd style=\"text-align: right\"\u003e604\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003ePython 3.4.0\u003c/td\u003e\n    \u003ctd style=\"text-align: right\"\u003e567\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003eRuby 1.9.3.4\u003c/td\u003e\n    \u003ctd style=\"text-align: right\"\u003e513\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd style=\"border-bottom: solid medium\"\u003ePython 2.7.3 + PyPy \u003c/td\u003e\n    \u003ctd style=\"border-bottom: solid medium; text-align: right\"\u003e206\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\nIn 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.\n\nLegal statement\n---------------\n\nCopyright © 2011, Triad National Security, LLC.  All rights reserved.\n\nThis software was produced under U.S. Government contract 89233218CNA000001 for Los Alamos National Laboratory (LANL), which is operated by Triad National Security, LLC for the U.S. Department of Energy/National Nuclear Security Administration.  All rights in the program are reserved by Triad National Security, LLC, and the U.S. Department of Energy/National Nuclear Security Administration. The Government is granted for itself and others acting on its behalf a nonexclusive, paid-up, irrevocable worldwide license in this material to reproduce, prepare derivative works, distribute copies to the public, perform publicly and display publicly, and to permit others to do so.  NEITHER THE GOVERNMENT NOR TRIAD NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE.  If software is modified to produce derivative works, such modified software should be clearly marked, so as not to confuse it with the version available from LANL.\n\nGoop is provided under a BSD 3-clause license.  See [the LICENSE file](http://github.com/lanl/goop/blob/master/LICENSE.md) for the full text.\n\nTriad National Security, LLC (Triad) owns the copyright to Goop, a component of the LANL Go Suite (identified internally as LA-CC-11-056).\n\nAuthor\n------\n\nScott Pakin, \u003cpakin@lanl.gov\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flanl%2Fgoop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flanl%2Fgoop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flanl%2Fgoop/lists"}