Sam Schlinkert is a user on octodon.social. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.

To stretch with my new and limited skills, I'm making a command line tic tac toe game.

Think I'm going to use the same logic I used when I did it one time in javascript four years ago octodon.social/media/Vn0CZwMtw

Alright well I hit a bit of a wall (compile error complaining about a variable that's either undeclared or unused), so I took a minute to push my progress to Github: github.com/sts10/tic-tac-go

Ah I got it. Was declaring a variable with `:=` when i meant to just re-assign it (`=`)

@schlink Rust has `into()`, that lets the compiler automatically convert an argument to the type needed by the function without you having to do it explicitly (assuming a type conversion has been defined)

@schlink it's hard to find linkable docs on it though...

@seanlinsley trade-offs!

I'm mostly going from Stack Overflow with my issues so far (e.g. stackoverflow.com/questions/10 )

But I'm planning on doing this same little game in both Rust and C++ and then maybe writing up the experience in a blog post.

@seanlinsley Started playing with Rust today. It's manageable so far!

Really enjoying these "rustlings" and the playground links in the readme github.com/carols10cents/rustl

@schlink It's picky yep, but that's par for the course for statically typed languages (of which golang is imo one of the best!). For a more relaxed experience try ruby or perl :) or to a slightly less extent python or javascript (nodejs is surprisingly fast and low-memory-overhead).

@ttk yeah coming from Ruby/Javascript/some Python-- I knew what I was getting in to to some extent. I was just surprised that Go made me define not only that a func's input was an array but also its size.

What do you like about Go? I'm casually poking around for _something new_. Watching a Rust tutorial right now to get an idea of what it's all about.

@schlink lol I didn't run into that b/c I've always preferred 🐍 case

@seanlinsley I usually do too but I was doing camel for Go for some reason... forgetting if that's their standard.

Fuck though, this is hard. My understanding of ownership and borrowing is... apparently not sufficient

man idk, Rust is putting up way more of a fight than Golang did for me... I guess that's kind of by design though. octodon.social/media/yjYuGa_nH

@schlink first image, slices and arrays are 2 different storage mediums, which is why it fails.

Don't know so much about rust though. I just stopped trying it after a while since the syntax, etc. is counter productive to me. Makes me get less work done.

@Clipsey Yeah I'm about ready to wave the white flag.

Here's that error, isolated in the playground if you want to beat your head against the wall: play.rust-lang.org/?gist=40257

Like, maybe I'll figure it out after an hour, but I feel like then it'll just be some other cryptic error

@schlink but yeah, golang if you want to stay sane.

Rust has only given me bs issues with confusing compiler errors and documentation.

@Clipsey Ah ok so I really just had to convert the i32 to usize with this cute-as-hell `as` function thing play.rust-lang.org/?gist=2e55c

But yeah, still rough

Alright I got tic-tac-toe working in both Go and (omg the struggle) Rust!

Here's my long blog post about it: sts10.github.io/2017/11/18/try (tl;dr Rust seems like a really cool idea, but Go seems more practical for most)

Golang repo: github.com/sts10/tic-tac-go

Rust repo: github.com/sts10/rusty-tac

@schlink Here's some nifty golang thing. structs can have attached functions.

So if i make a struct, called vector with 2 inputs of X and Y (int)

type Vector struct {
X int
Y int
}

i can attach a function, like "Add"

func (v *Vector) Add(other Vector) {
return Vector{v.X + other.X, v.Y + other.Y}
}

@schlink also, golang can run single-source .go files via the go run (file) command

@Clipsey yep, I used that constantly. Perhaps I should note it in the post...

@schlink oh wait, you already knew, i'm tired with an headache drinking way too much pear cider. Don't mind me.. xD

@Clipsey ah, I feel like that'll be the next thing for me to investigate (that or interfaces).

So this function is named "Add", the input is "other" of type Vector, and... there's no output?

@schlink You need structs before interfaces can be useful, unless you use interface{}, which is golang's form of OOP object class.

@schlink github.com/Member1221/mgj2017 Here's a small game i made in golang for a game jam, tried to make golang be quite OOP with interfaces, feel free to poke around with the code :D

@schlink also, you found a mistake in the code, there should be a return of Vector in the end

@Clipsey ha!

Tell me more about that asterisk though-- `(v *Vector)`. Is that a pointer to your defined type Vector? Why do you need as an asterisk there and I never needed one in my code? What's it called in the docs?

@schlink The asterisk, is indeed a pointer, as i prefer passing around references, also allows you to return nil on errors, and such.

@schlink
func (v *Vector) Add(other Vector) *Vector {
return &Vector{v.X + other.X, v.Y + other.Y}
}

@Clipsey ok, guess I'll have to think of a project where I'll need structs with functions!

@schlink nifty thing with pointers aswell, the inbuilt function new.

pos := new(Vector)
Will return a pointer to vector with default data. (X = 0, Y = 0) as far as i remember.

@schlink `match` in Rust is much more than a switch statement; it can be used for error handling, object destructuring, and custom pattern matching.

Rust's Iterator class is very advanced, providing functions similar to Ruby's Enumerable like `any`, `all`, `find`, `partition`, and for your blog post, `sum`: doc.rust-lang.org/std/iter/tra

@seanlinsley ha alright, alright I'll make an edit for `match`.

And dammmnnnn re: sum. That's slick. Did not see that.

@schlink I'm reaching out to see if we can get that error message improved. In my personal experience I've been impressed by the number of errors that included a suggested fix 😻 twitter.com/seanlinsley/status

@seanlinsley cool!

Sum seems to work just as advertised, but separately I'm running into some logic problems with the actual tic-tac-toe game, fyi

@schlink I forget if it was an issue that you ran into, but the just-released new version makes it so `*` (de-reference) isn't needed for `+=` blog.rust-lang.org/2017/11/22/