<FromGitter>
<jwoertink> Anyone have a good blog post / tutorial on when to choose a struct vs class? I always feel like it's a crap shoot for me and never have a clear idea of when to use one over the other
<rkeene>
Traditionally structs only have data fields, and classes have methods
<FromGitter>
<dscottboggs_gitlab> that's not really so in crystal
<FromGitter>
<malkomalko> Pass by Value vs Pass by Reference is an important thing to understand. Structs are a Value type, so you can think of them as Immutable
<FromGitter>
<dscottboggs_gitlab> yes that
<mps>
rkeene: you take my words :) you were faster. that is clear and concise explanation
<FromGitter>
<malkomalko> I ruined your βοΈ sorry :)
<rkeene>
But apparently not Crystalized :-D
<FromGitter>
<dscottboggs_gitlab> haha no it's fine
<FromGitter>
<jwoertink> Ok, I guess that makes sense
<mps>
structures are data and classes are behavior
<FromGitter>
<dscottboggs_gitlab> Yeah, structs in crystal can have methods and are mutable so neither of those really make sense here. But you do need to take care of how you handle changes made to a struct. Classes are pointers, Structs are not
<FromGitter>
<jwoertink> So if I have an object where I need to do `thing.x = 123` at some point, then class is better since it's mutable. But if I only ever do `thing.x` then struct is better?
<FromGitter>
<dscottboggs_gitlab> also, you can define methods on structs in lots of other languages
<FromGitter>
<malkomalko> Yah, or if you have some data you don't want mutated when you are passing it in to some function.
<FromGitter>
<jwoertink> cool. Thanks all
<FromGitter>
<dscottboggs_gitlab> no, saying `thing.x = 123` is okay, it's when you do `thing.method_that_mutates` where internally `method_that_mutates` calls `@x = 123`. If that was the case you would need to call `thing = thing.method_that_mutates`
<FromGitter>
<dscottboggs_gitlab> actually, is `thing.x = 123` ok?
<robacarp>
jokke doesn't a protected method defeat the purpose of an abstract method?
<jokke>
no, why would it?
<robacarp>
an abstract method delares a signature so that other implementors can use it external to the class. protected methods can't be used outside the class.
moei has joined #crystal-lang
<jokke>
protected methods can be used in inheriting classes
<jokke>
private methods can't
<jokke>
also this wouldn't necessarily be a problem even if this was the case, if the super class is the one calling the method
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
rohitpaulk has joined #crystal-lang
DTZUZO has quit [Ping timeout: 264 seconds]
rohitpaulk has quit [Remote host closed the connection]
<FromGitter>
<jwoertink> @vladfaust in that example, you have `ENV["POST"]` where I'm sure you meant `ENV["PORT"]`
<FromGitter>
<jwoertink> but great post!
<FromGitter>
<vladfaust> Thank you, @jwoertink!
<FromGitter>
<vladfaust> I've fixed it, gracias
<FromGitter>
<jwoertink> de nada
<FromGitter>
<jwoertink> hmm... @vladfaust when I try to boot your example, I get `Unhandled exception: ERR Syntax error, try CLIENT (LIST | KILL | GETNAME | SETNAME | PAUSE | REPLY) (MiniRedis::Error)`
<FromGitter>
<vladfaust> You should have Redis version >= 5
<FromGitter>
<vladfaust> It require CLIENT ID command
<FromGitter>
<jwoertink> haha, and now I just read your post where you mention that :p Guess I should have kept reading
<FromGitter>
<vladfaust> No problem, will put it higher
<FromGitter>
<jwoertink> hmm... actually... Just upgraded to 5.0.3 and it's still doing it
<FromGitter>
<vladfaust> Make sure your REDIS_URL is pointing to the updated instance
<FromGitter>
<vladfaust> It can be clearly seen from the error that your redis instance is missing `ID` command
<FromGitter>
<jwoertink> yeah, something else must be up. I went in to the redis-cli and it fails there too every though it returns version 5
<FromGitter>
<vladfaust> Maybe you need to restart it?
<FromGitter>
<vladfaust> Also join gitter.im/onyxframework to not disturb other habitats here
<z64>
in C bindings, what is the difference between a struct with members written like `member : T` vs. `member: T`? if any?
<FromGitter>
<dscottboggs_gitlab> `member: T` is invalid syntax
<FromGitter>
<dscottboggs_gitlab> To specify type annotations, you have to put a space both before and after the colon, to differentiate it from a named argument and from a method call with a symbol as a parameter
<z64>
no, it is apparently valid for C bound structs
<FromGitter>
<dscottboggs_gitlab> The rule I mentioned above apparently only applies to type restrictions inside of method definitions
<z64>
yes im familiar with how type restrictions normally look; ive been using crystal for about 2 years :) however, my question is specifically about C structs in `lib` definitions. there are special ways some things translate to C when writing bindings and i wanted to check i wasnt missing something
<z64>
maybe it is the same and it doesnt matter.
hightower3 has joined #crystal-lang
<hightower3>
Hey, didn't check in a while, how's things on the threads support front?
return0e has joined #crystal-lang
return0__ has quit [Ping timeout: 255 seconds]
lucasb has quit [Quit: Connection closed for inactivity]