• Stars
    star
    193
  • Rank 194,628 (Top 4 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Package generics is the true way to program generically in golang

Generics

GoDoc Build Status

When writing golang code, there are a series of immutable, irrefutable laws that you're required to follow. One of these laws states the following:

interface{} says nothing

This is why you should avoid programming against it as a replacement for the lack of generics, as it's a meaningless crutch which tells you nothing about the behavior of the types underneath it.

I couldn't agree more.

That's why I've built package generics.

Say it with G

Package generics exposes a single, powerful interface, G. With G, a golang developer (or gopher, as they like to be called) can confidently and securely rely on the power and flexibility of the built-in interface{}, without risking a violation of the core laws and tenets all golang developing gophers are required to adhere to.

Getting G

First, fetch the code using one of the many different officially sanctioned options for retrieving go code. Find each of them documented below for your convenience:

go get

go get github.com/StabbyCutyou/generics

Using G

Once you've gotten the code, you can import it like so:

  import . "github.com/StabbyCutyou/generics"

While importing using the dot notation is optional, it is the officially supported method of using package generics, as requiring the developer to type out the word generics each time they wish to declare something as being generic is very un-golang. Golang is all about developer productivity, and you can't be productive if you're spending all your time typing out long type declarations.

G is for Generics

With G, you can take ugly code signatures like this:

func UglyUnIdiomaticQuoteGenericApproachUnquote(poorexcuse ...interface{}) []interface{}

And transform it into the embodiment of meaningful code for which there can be no ambiguity:

func Excellence(things ...G) []G

Clearly, the latter example is far superior, as it screams its intent loud and proud: I am G, and I am generic!

Backwards Compatibility

G meets the standard of golang by matching its stance on backwards compatibility. Until a 2.0 release of generics, which may never happen, G will always be 100% backwards compatible with it's initial 1.0 release.

On Law 8

One possible conflict golang gophers might have is reconciling the use of a small, but well-designed, library such as package generics with Law 8: A little copying is better than a little dependency.. So long as all licensing restrictions on the software are adhered to, I have no issue with anyone who wishes to copy, rather than import, the full weight of package generics and its revolutionary G type.

That said, the idea behind G is that it would be compatible across libraries. Until such time as the community-driven alias feature being added to an upcoming release of golang is available, packages which implement their own G type will find it incompatible with other packages using a different G.

With that in mind, until the much sought-after alias feature is added to golang, I would suggest individuals import the library at this time so as to maintain full compatibility across the golang universe. Until the alias syntax arrives, there simply is no clear way to maintain both universal compatibility, and follow Law 8.

It's my sincere hope that golanging gophers everywhere are willing to accept this temporary tradeoff. As soon as alias is delivered unto us, I will update this section with official guidelines and best practices on using alias with G.

Afterword

I hope you enjoy programming with generics as much as I do. The best part about golang is the involvement of the community in shaping the future of the language. Remember:

interface{} says nothing

Say it with G, instead!

License

Apache v2 - See LICENSE

More Repositories

1

buffstreams

A library to simplify writing applications using TCP sockets to stream protobuff messages
Go
254
star
2

moldova

A lightweight templating system for generating random data
Go
167
star
3

rapp

Rapp - A scaffolding gem for Ruby Apps
Ruby
35
star
4

slammer

A database load testing utility for MySQL, MemSQL, and Postgres
Go
35
star
5

embeddingtalk

Go
18
star
6

sqltocsv

Stream large SQL result sets into a local file
Go
8
star
7

spub

A simple, channel-based asynchronous broadcast publishing wrapper
Go
7
star
8

moldovan_slammer

A library in go to run large files of SQL statements against a database with a configurable throttle
5
star
9

chopped

Go
5
star
10

Logopher

Write to logstash from Go over UDP
Go
3
star
11

pinner

An experimental proof of concept version dependency pinning system for Applications and Libraries in Golang
Go
3
star
12

yarder

Tail logs, gzip those smaller logs, upload them to s3
Go
3
star
13

instructor

It's like `rails c` for go applications, except not nearly as good
Go
3
star
14

quiz

test stuff about go
Go
2
star
15

accumulator

A light wrapper around atomic, threadsafe counters
Go
2
star
16

0db

It is 0% a database
Go
2
star
17

bipolarkcombinatorkcombinator

It's exactly like it sounds, obviously
Go
1
star
18

gnirts

A repo of benchmarks for reversing a string in go
Go
1
star
19

StabbyCutyou.github.io

A repo to host the talks I write in reveal js
HTML
1
star
20

aimakeme

Little wrapper cli to call openapi to generate images, then save them locally with the prompt
Go
1
star
21

blunderbuss

It's a bus, for your blunders
Go
1
star
22

splitter

A stream processing thing written in go
Go
1
star
23

bilineator

Implementation of a Bilinear Interpolator in Go
Go
1
star