@nicklockwood@mastodon.social avatar

nicklockwood

@nicklockwood@mastodon.social

iOS. 3D graphics. Retro games. He/Him.

This profile is from a federated server and may be incomplete. Browse more on the original instance.

chockenberry, to random
@chockenberry@mastodon.social avatar

Pro Tip: Get in the habit of annotating your tuples. In six months, you're not going to remember which string is which:

func apiKeys() -> (String?, String?)

You future self will be happier with:

func apiKeys() -> (clientId: String?, clientSecret: String?)

You can even annotate the return values if you have a lot of complex logic before the return:

return (clientId: “CHOCK”, clientSecret: “NOUNDIES”)

nicklockwood,
@nicklockwood@mastodon.social avatar

@chockenberry

Good: annotate the tuple arguments

Better: use typealiases for the key types:

typealias ClientID = String
typealias ClientSecret = String

Best: use unique type wrapper structs for each:

struct ClientID: RawRepresentable, Hashable {
var rawValue: String
}

struct ClientSecret: RawRepresentable, Hashable {
var rawValue: String
}

nicklockwood,
@nicklockwood@mastodon.social avatar

@jsq @chockenberry it depends what problem you are trying to solve. Using a struct to wrap both values is equivalent to labelling the tuple arguments, in that it ensures that at the point of access you won't get the clientid and secret mixed up.

What using separate struct wrappers solves is that when you pass your clientid and secret around as individual values you won't accidentally get them mixed up with some other string identifier in your application because the type system won't let you.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • megavids
  • rosin
  • thenastyranch
  • GTA5RPClips
  • tester
  • InstantRegret
  • DreamBathrooms
  • ngwrru68w68
  • magazineikmin
  • everett
  • Youngstown
  • mdbf
  • slotface
  • kavyap
  • JUstTest
  • cisconetworking
  • khanakhh
  • normalnudes
  • osvaldo12
  • cubers
  • tacticalgear
  • Durango
  • ethstaker
  • modclub
  • anitta
  • provamag3
  • Leos
  • lostlight
  • All magazines