davecheney / gpio

GPIO for Go
BSD 2-Clause "Simplified" License
228 stars 52 forks source link

Wouldn't a boolean be better for the direction? #1

Closed AeroNotix closed 11 years ago

AeroNotix commented 11 years ago

Hi,

I was just looking over this and I thought that possibly a boolean value would be better for direction since you can easily toggle it:


package main

import "fmt"
type Direction bool

func main() {
    d := Direction(true)
    d = !d
    fmt.Println(d)
}

For me, string parameters like that can get annoying ("stringly typed"), though since there are only two, it's not so bad. However, you get a few syntactic niceties from using booleans.

My $0.02.

davecheney commented 11 years ago

Geese Aaron, hold your horses mate :)

Direction needs to be an enum because it's actually Mode, one of at least in, out, pwm.

Closes #1

On 22/07/2013, at 17:38, Aaron France notifications@github.com wrote:

Hi,

I was just looking over this and I thought that possibly a boolean value would be better for direction since you can easily toggle it:

package main

import "fmt" type Direction bool

func main() { d := Direction(true) d = !d fmt.Println(d) }```

For me, string parameters like that can get annoying ("stringly typed"), though since there are only two, it's not so bad. However, you get a few syntactic niceties from using booleans.

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

AeroNotix commented 11 years ago

Dave, it's too early friend. I'm having trouble parsing what you just wrote. Can you give me the decaffeinated version?

A boolean lets you do stuff like:


// Toggle pin
Pin.SetDirection(!Pin.Direction())
davecheney commented 11 years ago

It was a mistake to call this method Direction, it should be called Mode. There are least three modes that the RPi driver supports, and possibly more.

On 22/07/2013, at 17:50, Aaron France notifications@github.com wrote:

Dave, it's too early friend. I'm having trouble parsing what you just wrote. Can you give me the decaffeinated version?

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

AeroNotix commented 11 years ago

Oh I see! So you're going to need to add PWM and thus remove the opportunity for a binary state. Gotcha. Close.