stretchr / sdk-go

Go SDK for Stretchr platform
7 stars 1 forks source link

Typed Getters and Setters in Resource #21

Closed matryer closed 11 years ago

matryer commented 11 years ago

Add some common type getters and setters in Resource.

Examples include:

tylerstillwater commented 11 years ago

The Sets are unnecessary because of interface{}. The Gets would be helpful, though.

On Jan 21, 2013, at 9:22 AM, matryer notifications@github.com wrote:

Add some common type getters and setters in Resource.

Examples include:

• GetTime(key) • SetTime(key, time) • GetNumber(key) • SetNumber(key, float64) • GetBool(key) • SetBool(key, bool) • GetString(key) • SetString(key, string) — Reply to this email directly or view it on GitHub.

matryer commented 11 years ago

I think the sets are worth including, they ensure type safety in code.

Imagine this:

resource.Set("ishappy", 50)
resource.GetBool("ishappy")
matryer commented 11 years ago

... of course, that's their fault. But SetBool("ishappy", 50) wouldn't even compile.

tylerstillwater commented 11 years ago

That's a programmer error and it will panic when it tries to do a type conversion.

Your example could just as easily be:

resource.SetInt("ishappy",50) resource.GetBool("ishappy")

On Jan 21, 2013, at 9:25 AM, matryer notifications@github.com wrote:

I think the sets are worth including, they ensure type safety in code.

Imagine this:

resource.Set("ishappy", 50) resource.GetBool("ishappy")

— Reply to this email directly or view it on GitHub.

matryer commented 11 years ago

OK well let's do the getters first and we can always add setters later if there's apatite

tylerstillwater commented 11 years ago

Sounds good

On Jan 21, 2013, at 9:29 AM, matryer notifications@github.com wrote:

OK well let's do the getters first and we can always add setters later if there's apatite

— Reply to this email directly or view it on GitHub.