Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
cruft
Oct 25, 2007

gariig posted:

If you got with option 1 every time someone calls IsShiny a *rand.Rand() has to be passed in even if shiny has been set.

I would go with option 2 and I would have two constructors. One is internal that’s used by the tests where a rand.Rand can be passed in. The exported constructor would not take a rand.Rand, make one, and use the internal constructor. This keeps it so your test (if in the same package) can set a predetermined rand.Rand but the caller doesn’t get to set anything.

There’s no way to guarantee shiny isn’t changed in some code path internally. Go doesn’t have the concept of const or readonly. So basically you just have to make sure nothing sets it outside the constructor

Agree.

For bonus points, don't take rand.Rand but rather func() int. This will make the unit tests you are writing a lot more bearable.

Adbot
ADBOT LOVES YOU

cruft
Oct 25, 2007

30.5 Days posted:

go is fuckin good

:hmmyes:

cruft
Oct 25, 2007

The built in fully capable performant multi-threaded HTTP/2 server is a real selling point for me and the work I do.

I guess everybody already knows Go is good at this, but I feel like I need to jump on the bandwagon here.

cruft
Oct 25, 2007

Wow, I figured there were like zero people outside of Canonical who have ever read the MAAS code, but here we are. Sorry for your suffering, friend. We can all relate.

cruft
Oct 25, 2007

How come nobody told me Go has generics now?

cruft
Oct 25, 2007

Can anybody help me understand what I need to do in order to make "go get github.com/dirtbags/moth/pkg/jsend" work outside of that source tree?

Like, I thought I was setting things up so other software could use that library, but apparently I'm missing something, because it tells me:

code:
go: module github.com/dirtbags/moth@upgrade found (v3.6.3+incompatible), but does not contain package github.com/dirtbags/moth/pkg/jsend
:confused:

cruft
Oct 25, 2007

Pham Nuwen posted:

So you're trying to write software to use that jsend library? If you've done a `go mod init` in your code, you should be able to do `go get github.com/dirtbags/moth/pkg/jsend@v4.4.9` from within your code dir and it'll Just Work?

edit: oh, they've hosed up their versioning, poo poo, I forget how to fix this

edit 2: yeahhhh they haven't set up their go.mod correctly. They've tagged up through v4.x.x, which means go.mod should say "module github.com/dirtbags/moth/v4" but they didn't do that. See https://go.dev/doc/modules/major-version

edit 3: jsend is just a single small file so just copy it into your own tree, with correct attribution of course (these guys ALSO didn't bother to do copyright headers...)

Dirtbags is me. I'm trying to fix this :) Your link has me down some sort of path, maybe there's a working import at the end of it.

Regarding copyright headers, what's the preferred way to denote that? I thought you just dropped LICENSE.md in the top level?

cruft
Oct 25, 2007

Pham Nuwen posted:

lol sorry for ripping on your code

Ha. No worries, everything you said is true: I'm too battle-scarred to think my code is some paragon of design or anything.

I appreciate the pointers! This will save me hours of head scratching and reading unrelated documents.

cruft
Oct 25, 2007

DARPA posted:

When I first started Whispers of the dead it popped up some help text I accidentally closed. Anything to know besides run the dungeons highlighted with red stars?

edit: wrong thread.

Super curious about the answer now, op. Please keep us updated!

cruft
Oct 25, 2007

fletcher posted:

I have no idea what this go.senan.xyz host is, and wasn't sure about the security aspect of installing something from it. It seems somewhat like a "curl ... | bash" type of install that I'm not a fan of. Is that sort of recommendation typical for a go app?

You'd rather compile and install source code you can't/won't review from GitHub than from the author's server? That is an interesting threat model.

cruft
Oct 25, 2007

fletcher posted:

more eyeballs on it in general.

I just want to highlight that this has turned out to be one of the greatest fallacies about free software. Nothing against you in particular, OP: it's a commonly-held belief.

In fact, if any college goons want a good master's project, try bringing some code up on GitHub, have some cohorts download it, then insert some super-blatant remote shell capabilities into it and see if any automated systems flag that. Maybe they do! I sort of suspect they won't, though.

cruft fucked around with this message at 23:30 on Aug 31, 2023

cruft
Oct 25, 2007

Can some kind soul help me out here

code:
type Attendee struct {
	Email string
	Username string
}

type AttendeeList struct {
	Attendees []Attendee
	ByEmail map[string]Attendee
	ByUsername map[string]Attendee
}
Should I make the Attendee members of AttendeeList pointers?

I'm pretty sure the actual answer is "LOL it's not 1987 you have enough RAM to not care", but it's the principle of the thing, you see.

Adbot
ADBOT LOVES YOU

cruft
Oct 25, 2007

Pham Nuwen posted:

Speaking of that, I'd ask if you really expect to have so many attendees and do so many lookups by both email and by username that it makes sense to duplicate them 3 different ways. My first instinct would be to just hold the slice of Attendees, then iterate for lookups. Iteration is cheaper than you think (especially in this case which won't even have nested loops), and a lot easier than mucking around with 3 different stored representations of the same data.

Haha, great minds think alike, and so do ours! My Scheme training kicked in and I wound up doing exactly this: there's now a type AttendeeList []Attendee that provides some indexing functions by iterating over the slice.

Thanks, everyone. Your replies did steer me toward a nice solution.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply