RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
qard has joined #crystal-lang
qard has quit [Client Quit]
relyks has joined #crystal-lang
<jnyw> Hi, I'm having some trouble with writing C bindings. Say I have a c file with some functions that take arguments of type 'struct sockaddr' for example. In my crystal file how do I specify that the function's argument is a struct sockaddr?
cremes has joined #crystal-lang
relyks has quit [Quit: relyks]
wontruefree has joined #crystal-lang
jnyw has quit [Quit: WeeChat 2.0.1]
jnyw has joined #crystal-lang
faustinoaq has joined #crystal-lang
faustinoaq has quit [Quit: IRC client terminated!]
jnyw has quit [Quit: WeeChat 2.0.1]
relyks has joined #crystal-lang
lvmbdv has quit [Quit: WeeChat 1.9.1]
hightower4 has quit [Ping timeout: 248 seconds]
<FromGitter> <Dillybob1992> im creating a little crystal TCP connection project with Godot
cremes has quit [Quit: cremes]
jnyw has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
<jnyw> is there a built in method to get the string from a char* returned from some c code?
greengriminal has joined #crystal-lang
jnyw has quit [Quit: WeeChat 2.0.1]
<FromGitter> <bew> jnyw: just create one: `String.new(your_char_pointer)`
<FromGitter> <bew> And if you know the size you can pass it as 2nd parameter
[spoiler] has quit [Quit: Cheers!]
<FromGitter> <bew> For your `struct sockaddr`problem, you should look at what's available in the current LibC bindings, I think there's something like `LibC::SockAddr` type
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
wontruefree has quit [Quit: The Internet needs a break and I need a cookie]
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
mark_66 has joined #crystal-lang
aroaminggeek has joined #crystal-lang
dannyAAM has joined #crystal-lang
<FromGitter> <Qwerp-Derp> Is it possible in Crystal to change JSON to be able to do this: `json["foo"]["bar"]["baz"]` by possibly overloading the `[]` operator?
jnyw has joined #crystal-lang
<FromGitter> <yxhuvud> @Qwerp-Derp: that question does not make sense. There is nothing that stops you from doing that right now
<FromGitter> <Qwerp-Derp> @yxhuvud You can't do that with Crystal JSON right now - whenever you do `[]`, it turns into JSON::Any, which doesn't have `[]` attached to it.
<FromGitter> <Qwerp-Derp> And even when you do something like `.as_a` or `.as_h`, it further turns into JSON::Type, which is just an alias of all possible JSON types. When you try to do `[]` on that, the compiler doesn't allow it, since `[]` isn't implemented for `Nil`, `Int32` etc.
flaviodesousa has joined #crystal-lang
alex`` has joined #crystal-lang
lvmbdv has joined #crystal-lang
aroaminggeek has quit [Ping timeout: 276 seconds]
hightower4 has joined #crystal-lang
jnyw has quit [Quit: WeeChat 2.0.1]
faustinoaq has joined #crystal-lang
<FromGitter> <greenbigfrog> Is it possible, that returns on command calls for this get mixed up (in theory)? eg. I have `@rpc = BitcoinRpc.new(...)` and then do multiple calls on it. https://github.com/greenbigfrog/bitcoin_rpc/blob/master/src/bitcoin_rpc.cr
snsei has joined #crystal-lang
<vegai> do you have multiple threads going on?
<FromGitter> <bararchy> @Dillybob1992 are you adding Crystal support to Godot ? As in making games in Godot using Crystal ?
<FromGitter> <yxhuvud> What is godot?
<FromGitter> <Dillybob1992> @bararchy Nah i'm not that advanced yet hehe :) im just doing a simple game server example on how u can connect with godot to a crystal tcp server and send messages/etc
<FromGitter> <Dillybob1992> @yxhuvud very libre / open source Game Engine that's gaining a lot of light lately
snsei has quit [Remote host closed the connection]
<greenbigfrog> not sure if I've found a solution yet, but I have a other question. Can I disable the `error while loading shared libraries ...` message in emacs? I'm developing on a remote system, because my local system is bleeding edge
<txdv> why is this channel being flooded
<txdv> together with the libuv channel
<txdv> wtf?!
faustinoaq has quit [Ping timeout: 268 seconds]
faustinoaq has joined #crystal-lang
hightower4 has quit [Ping timeout: 256 seconds]
hightower2 has joined #crystal-lang
hightower3 has quit [Ping timeout: 256 seconds]
<Papierkorb> greenbigfrog: "Bleeding edge"? Arch? Many dev Crystal on Arch just fine
<greenbigfrog> I run llvm 6
faustinoaq has quit [Quit: IRC client terminated!]
<FromGitter> <yxhuvud> How do you get that message in emacs?
<FromGitter> <asterite> Hanyuan li: there's a pending PR for that, search the repo. It will probably get merged.
faustinoaq has joined #crystal-lang
<greenbigfrog> Yxhuvud: I get it as a extra window across the bottom
<FromGitter> <mjago> @greenbigfrog I’ve never seen that on Emacs ~ are there any clues in *Messages buffer?
faustinoaq has quit [Remote host closed the connection]
<greenbigfrog> nope
cremes has joined #crystal-lang
linuksz has joined #crystal-lang
linuksz has quit [Client Quit]
notramo has joined #crystal-lang
<greenbigfrog> I'm really starting to think that somehow the returns are getting mixed up...
<vegai> greenbigfrog: so are threads involved?
<greenbigfrog> if spawning sth is a thread, yes
<RX14> @greenbigfrog you havent really explained your problem or the symptoms
<greenbigfrog> I have before. gimme a minute
<FromGitter> <Qwerp-Derp> @asterite Is it the one removing recursive aliases in JSON::Any? I saw it, gave it a 👍
<FromGitter> <Qwerp-Derp> Ah, now that I see the documentation for JSON, I feel stupid that I didn't know that, sorry @yxhuvud
<greenbigfrog> Using the exact same call outside the context of a spawn and other parralel calls for https://github.com/greenbigfrog/bitcoin_rpc/blob/master/src/bitcoin_rpc.cr don't give any error
<RX14> where's this spawn?
<RX14> HTTP::Client isn't concurrency safe
<RX14> you can only use it in one fiber at the same time
<greenbigfrog> that might explain it...
<RX14> the stacktrace you sent me immediately looks like a malformed HTTP request
<RX14> since it's in HTTP::Response.from_io
<RX14> and inside that there's an invalid int32
<RX14> (status code)
<RX14> and the invalid itn32 is "for"
<RX14> no, where's the client used
<RX14> the bitcoinrpc
<RX14> I can't debug your code without understanding your codebase
<RX14> unless you bring me a reproducible self-contained snippet all I can do is postulate
<greenbigfrog> eg here https://github.com/greenbigfrog/discordtipbot/blob/master/src/discordtipbot/tipbot.cr#L153 (it forwards it through coin_api. it's the same as if rpc directly called)
<RX14> well
<RX14> I suggest you just try using HTTP::Client.posty
<RX14> I suggest you just try using HTTP::Client.post
<RX14> and don't store the client in the rpc class
<greenbigfrog> I've seen @coin_api.get_transaction mixed with @coin_api.get_info
<greenbigfrog> Can I do basic_auth without storing a client?
<RX14> well, yeah
<RX14> you just create a new one each call
<RX14> you have to use .new then client.post
<RX14> but that doesn't mean you need to store it
<greenbigfrog> ah. ok
<greenbigfrog> now I get it
<greenbigfrog> I think I got it from here :) thanks
<RX14> it's just so that you're sure one fiber only has the HTTP::Client
<greenbigfrog> yep
<RX14> if it's in a local variable and the object could be called from multiple fibers it could happen that multiple fibers have .post calls which coincide
<greenbigfrog> yep
<RX14> we should probably prevent this
<RX14> just raise something like a CME from java
<greenbigfrog> this look correct?
<greenbigfrog> RX14: ?
<RX14> well
<RX14> remove getter client
<greenbigfrog> true
<RX14> also it's not as nice looking when you use symbols for getters
<RX14> just use getter headers and I suggest typing it explicitly most of the time
<RX14> especially for public ones
<RX14> but thats just style
<RX14> it should be fine
<greenbigfrog> can you tell me why citizen428 had getter's there in the first place?
<RX14> no
<RX14> i'm not other people
<greenbigfrog> true :)
<greenbigfrog> but you've got more experience then me
<FromGitter> <l3kn> I think the operator precedence would be `... if (query == [0] || query.empty?`
<FromGitter> <l3kn> `next unless update.nil?` would skip to the next iteration of the loop if `update` is not nil
<crystal-gh> [crystal] asterite closed pull request #5183: Implement JSON::Any and YAML::Any without recursive aliases (master...refactor/no-recursive-aliases) https://git.io/vFvGP
<greenbigfrog> the `()` are not neccesary. stil get the same error
<greenbigfrog> ``` next if update.rows_affected > 0
<greenbigfrog> ^~~~~~~~~~~~~
<greenbigfrog> undefined method 'rows_affected' for Nil
<FromGitter> <l3kn> yeah, the precedence stuff was an mistake on my side
<FromGitter> <l3kn> line 4 will only be reached if update is nil
<greenbigfrog> oh. now I see
<greenbigfrog> thanks
<RX14> @greenbigfrog next isn't next line lol
<RX14> it's next loop
<greenbigfrog> I know
LastWhisper____ has joined #crystal-lang
notramo has quit [Quit: WeeChat 2.0.1]
greengriminal has quit [Quit: This computer has gone to sleep]
moei has joined #crystal-lang
<FromGitter> <eliasjpr> Hello, just want to point out a small typo on crystal-lang.org ⏎ ⏎ > Crystal libraries are packed as Shards, and distributed via Git without needing a centralised repository. ⏎ centralised => centralized [https://gitter.im/crystal-lang/crystal?at=5a5ccd4751915d962afe04c6]
<FromGitter> <straight-shoota> @eliasjpr "centralised" is perfectly valid British English
greengriminal has joined #crystal-lang
<FromGitter> <eliasjpr> Oh okay. I am gussing that the site uses British English consistently throughout.
<FromGitter> <eliasjpr> Sorry did knew
<FromGitter> <eliasjpr> Is that the case @straight-shoota, the site uses British English dialect consistently throuhout the site?
<FromGitter> <straight-shoota> I don't think so.
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
Poeticure has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
<crystal-gh> [crystal] asterite closed pull request #5585: Compiler: emit `.o` file to a temporary location and then atomically rename it (master...refactor/improved-cache) https://git.io/vNctC
greengriminal has joined #crystal-lang
greengriminal has quit [Read error: Connection reset by peer]
greengriminal has joined #crystal-lang
vivus has joined #crystal-lang
<FromGitter> <asterite> We use those words interchangeably. I never remember which one is British
<FromGitter> <asterite> Plus none of us are native English speakers, so...
<jokke> is this the same with authorised vs authorized?
<jokke> or any *ised *ized
<jokke> except for sized :P
mark_66 has quit [Remote host closed the connection]
<FromGitter> <eliasjpr> 👍
qard has joined #crystal-lang
<travis-ci> crystal-lang/crystal#80cbe66 (master - Compiler: emit `.o` file to a temporary location and then atomically rename it): The build was broken. https://travis-ci.org/crystal-lang/crystal/builds/329127869
<FromGitter> <asterite> I think so, yes
<FromGitter> <asterite> Also color vs colour
<FromGitter> <asterite> And many other things. In my mind, it doesn't matter. Language stuff. As long as you can understand it...
flaviodesousa has quit [Quit: KVIrc 4.2.0 Equilibrium http://www.kvirc.net/]
<jokke> sure
<jokke> asterite: when are you guys coming to the Chaos Communication Congress? :) I was very sad when i saw that there was no crystal assembly :(
<RX14> @asterite we need to support both initialize and initialise lol
<jokke> RX14: :D
<RX14> it's hard to stick to one spelling though, even as a brit
<RX14> so many words i've been trained by programming to spell the american way
<Yxhuvud> not to mention words like referer
<Vexatos> actually, I checked a few dictionaries for both, US dictionaries only contain the -ize but British dictionaries contain both, even very old ones
<Vexatos> so it really doesn't matter
<RX14> Vexatos, do you just have 10 disctionaries on your desk?
<Vexatos> ...maybe
<RX14> ready to go on the fly?
<RX14> lol
<Vexatos> There is a rather big bookshelf to my right
<Vexatos> ...and behind me
<Vexatos> as a rule of thumb is seems that the Oxford Dict prefers the -ize spelling
<Vexatos> while other British dictionaries don't care
<RX14> my muscle memory is for ize because of crystal
<Vexatos> The Oxford Dict is the one I learnt the language with, so it is like that for me
<RX14> well, at least you learnt the correct spelling of colour
<Vexatos> and of "learnt"...
<RX14> lol
<crystal-gh> [crystal] Sija opened pull request #5589: Allow leading '+' in number strings (master...allow-leading-plus-in-number-strings) https://git.io/vNWLb
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
faustinoaq has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
qard has joined #crystal-lang
<FromGitter> <eliasjpr> I think it would nice to have it read consistently. I understand that English is not the primary language but consistency is ke
<FromGitter> <eliasjpr> Keyz
<FromGitter> <eliasjpr> 😊
<FromGitter> <Dillybob1992> Obligatory video (https://www.youtube.com/watch?v=mOw7CdpK44w) 😄
faustinoaq has quit [Ping timeout: 256 seconds]
aroaminggeek has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Poeticure is now known as Poeticode
hightower4 has joined #crystal-lang
<FromGitter> <Dillybob1992> here is my GameServer class i've been working on https://play.crystal-lang.org/#/r/3dz2. ⏎ Everything is working great so far. I'm just curious on the method parameter passing. For example, I made a new method called `send` however, it's fine that I need to pass in the socket in the parameter right?
greengriminal has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
qard has joined #crystal-lang
<Papierkorb> Dillybob1992, that looks like imperative code, and not OOP. Create a Client class, which you pass the TCPClient.
Ven`` has joined #crystal-lang
dhk has joined #crystal-lang
<FromGitter> <Dillybob1992> I see, thanks gonna try that out
wontruefree has joined #crystal-lang
dhk has quit [Quit: Leaving]
<Papierkorb> Dillybob1992, general advice while starting out on that is: After you wrote a piece of code, take a step back. Maybe take a short break too. And then, look at the structure of the code (and not the code itself). It can help to think how a user (a coder but not yourself) may use it, what their goals are (-> identifying common use-cases), and then checking if your structure makes this as easy as possible to do (without being brittle),
<Papierkorb> while still allowing more advanced usage (without being too generic)
<Papierkorb> Do that a few times over the course of the project. If you find something that you think you can improve, then improve it right now. Don't simply say "Next time", cause knowing how to efficiently refactor code is also useful. Later (in the project, or time-wise) try to do it the other way around, think about the structure first, and code second
<FromGitter> <Dillybob1992> yah that's why i posted here because i think if someone else were to look, they'd be like "wtf, why do i have to pass socket in the send method all over the place?". imo, i think that could annoy someone. and if it annoys someone else,most likely it'll be annoying for me too i think
<Papierkorb> If you want a quick second opinion, fake it: Just start a new file, require in your code, and try to use it.
<FromGitter> <Dillybob1992> the problem i have is, i like to just code stuff so it works and i completely am void of the inner workings and aesthetics. but it's bad because when something bad happens like an error, it takes me forever to figure out wtf went wrong, lol
snsei has joined #crystal-lang
<Papierkorb> If you need some inspiration, check out popular programming patterns and paradigms. OOP has a billion or so, mainly from Java. Some are language specific, but most have a "true core" that's generally applicable. One such pattern is "SOLID".
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
snsei has quit [Remote host closed the connection]
<FromGitter> <Dillybob1992> will do
<Papierkorb> Afaik, there's no Crystal SOLID resource yet. There should be plenty for any language you know besides Crystal. You can also search for "SOLID ruby", and basically copy that code over to Crystal with (almost?) no changes.
<FromGitter> <Dillybob1992> alhough, using classes in crystal have been immensely helpful in learning good design to me anyway
<FromGitter> <Dillybob1992> okay, awesome ya will watch a few videos
<Papierkorb> Didn't you mention you used JS? JS isn't pure OOP, but "close enough" in that you can also use classes for your objects
<Papierkorb> For all defects that JS has, creating "classes" in ES6+ is finally easy
<FromGitter> <Dillybob1992> yeah, i love that
<Yxhuvud> The keyword is "can" - react etc seems to throw that away.
snsei has joined #crystal-lang
<FromGitter> <Dillybob1992> okay, so i made a new class, called Client, and she has her own `send method`, and now i can just call `send("msg")` instead of passing my own socket all the time in parameter like I was doing before
<FromGitter> <Dillybob1992> this loooks more cleaner to me
<Papierkorb> You know that Car analogy people use to teach OOP?
<FromGitter> <Dillybob1992> nope
<Papierkorb> TL;DR: Car has Wheels (Composition). A Car is a Vehicle (Inheritance).
<FromGitter> <Dillybob1992> the engine of the car, could be a method?
<Papierkorb> However, there's one thing those explanations are usually lacking. One major point when designing classes isn't about inheritance or whatever you use.
<FromGitter> <Dillybob1992> the muffler, could be another method?
<Papierkorb> It's that you have a Car, and that Car has wheels, but the Car doesn't care a single bit how a Wheel actually works. It can use one, and that's good enough
<FromGitter> <Dillybob1992> i see
LastWhisper____ has joined #crystal-lang
<Papierkorb> in the Car analogy, all components that make a car would be (at least one) class. Engine would be one. And that thing probably has a Gearbox. And so on
<Papierkorb> Experience will tell you when it's a good idea to break something down, or if it's better not to
faustinoaq has joined #crystal-lang
davic has quit [Read error: Connection reset by peer]
<FromGitter> <Dillybob1992> is it possible to spawn a class? `spawn Client.new(socket)` , i get a unidentified error `new`. however, if i do `spawn handle_connection(socket)`, then do`Client.new(socket)` inside there, it works fines. that's ok right?
<RX14> it should work
<RX14> .new is just another method
<RX14> but if it doesn't, just use spawn { Client.new(socket) }
<RX14> spawn is mostly used with a do/end or {} block actually
<RX14> it just has a shorthand
faustinoaq has quit [Ping timeout: 256 seconds]
wontruefree has quit [Quit: The Internet needs a break and I need a cookie]
aroaminggeek has left #crystal-lang ["Textual IRC Client: www.textualapp.com"]
<FromGitter> <Dillybob1992> hmm, `{ Client.new(socket) } `in GameServer.cr:19: no overload matches 'Client.new' with type (TCPSocket | Nil)`
<FromGitter> <Dillybob1992> ``` while socket = server.accept? ⏎ spawn { Client.new(socket) } ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5a5d2497ba39a53f1a1c4258]
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
qard has joined #crystal-lang
snsei has quit [Remote host closed the connection]
dhk has joined #crystal-lang
<FromGitter> <l3kn> @Dillybob1992 I'm not sure what is happening there, as a quick fix you can put a `socket_ = socket` above the line with the `spawn` and then do `Client.new(socket_)`
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <l3kn> maybe someone with some knowledge of the internals of crystal can explain what is going on later
<RX14> it's because that code scopes socket outside of the while
<FromGitter> <Dillybob1992> wow, that seemed to work
qard has joined #crystal-lang
<RX14> so the next while loop iteration will just change socket before it's used
<RX14> since blocks are closures and they close on the variables
<RX14> not copy the variables
wontruefree has joined #crystal-lang
<FromGitter> <l3kn> Interesting, thanks!
<FromGitter> <Dillybob1992> im going to do handle_connection(socket) then just do client.new(socket) for now, looks less hacky ithink
<RX14> yeah
<RX14> thats the "right way" to do things
<FromGitter> <Dillybob1992> ok, well fine by me i need standards on what wrong or not bcz now i end up with weird code all over the place haha
<FromGitter> <Dillybob1992> looks cooler, GameServer says hey, you, handle this connection, create the Class and go do your thing. Client is okay sir, let's roll
Ven`` has quit [Ping timeout: 265 seconds]
Ven`` has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 256 seconds]
sz0 has joined #crystal-lang
<FromGitter> <jwaldrip> @RX14 are we getting another crystal release this month?
<RX14> who knows
<FromGitter> <jwaldrip> Just curious as I saw the 0.24.2 milestone is empty.
<RX14> it's not empty?
<RX14> it has 8 closed issues in it
<FromGitter> <jwaldrip> I mean all closed
<FromGitter> <jwaldrip> Empty as in nothing in flight.
<RX14> yeah...
<RX14> thats normal
Ven`` has quit [Ping timeout: 264 seconds]
<RX14> we don't use milestones as todos
<FromGitter> <jwaldrip> Sorry, didn't mean to conflate terms.
<FromGitter> <jwaldrip> Ah gotcha.
<RX14> we use them as lists of stuff that's merged
Ven`` has joined #crystal-lang
<FromGitter> <jwaldrip> ah gotcha
moei has quit [Quit: Leaving...]
<RX14> just so we can bind together all the PRs merged for a release
<RX14> so we can write a changelog
<FromGitter> <jwaldrip> Gotcha
<FromGitter> <jwaldrip> I wish there was more communication/transparency on releases.
<RX14> if we need to make sure we absolutely don't forget something before the next release we'll use them
<RX14> but stuff is done "when it's done"
<FromGitter> <jwaldrip> 👍
<RX14> we don't plan ahead what should be merged for when
<RX14> plans just get broken anyway
<FromGitter> <jwaldrip> Gotcha
<OceannBoy> Hi
<FromGitter> <Dillybob1992> Hi
<OceannBoy> Is there an IRB equivalent for Crystal ?
<RX14> no
<RX14> and there's unlikely to be one any time soon
<OceannBoy> Due to the compiled vs interpreted language ?
snsei has joined #crystal-lang
<FromGitter> <jwaldrip> closest thing
<RX14> it's not an irb equivalent
<RX14> don't get confused by the name
<RX14> I wish that project didn't exist
<RX14> OceannBoy, because of the type system actually
<OceannBoy> I see.
<RX14> you can have compiled languages with repls, see haskell for example
<OceannBoy> Well, I'd like to say greetings to all as I am new.
<RX14> it's just that the way crystal's type system currently works, one new piece of code can affect every other piece of running code's behaviour
<RX14> so it's impractical to create a repl
<RX14> however, there is `crystal play`
<RX14> it's a nice web tool to try out code
<RX14> if you want somewhere to just play with crystal
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<OceannBoy> I'll look at it. Thanks for the tip
dhk has quit [Quit: Leaving]
<FromGitter> <Dillybob1992> i love crystal play
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter> <jwaldrip> icr just recompiles on each line.
greengriminal has joined #crystal-lang
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<crystal-gh> [crystal] txe opened pull request #5591: [WIP] Win exceptions (master...win-exceptions) https://git.io/vNWXX
<FromGitter> <jwaldrip> Okay y'all, if you are in here and haven't starred Crystal on github, DO SO. We are almost at 10k stars.
alex`` has quit [Ping timeout: 256 seconds]
<FromGitter> <Dillybob1992> if i am extending a class with `class Client < GameServer` and use the word `self` inside, is it referring to my GameServer, or Client?
<FromGitter> <Dillybob1992> hmm, I think its my client because when i do puts self, it shows Client. however, im adding that client to an array called `players` on each connections and some reason dosn't seem like it's getting populated. i've connected two connections and the size of `players` is still 1
<FromGitter> <Dillybob1992> however, the memory block is different so it should be appended right
<Papierkorb> Dillybob1992, is a Client a GameServer?
<FromGitter> <Dillybob1992> nope, it's a seperate class
<Papierkorb> Then why is Client inheriting GameServer?
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <Dillybob1992> well, my GameServer has an array called `players` and want to use inside my Client clas
<Papierkorb> Please explain what "Inheritance" means
<Papierkorb> in the OOP sene
<Papierkorb> sense*
<FromGitter> <Dillybob1992> something that is a child of a master
<RX14> that would be composition not inheritance
<RX14> typically
<Papierkorb> That's neither
<Papierkorb> Dillybob1992, Inheritance is like a parent giving everything they know to a child. The child can then improve/add upon that.
<Papierkorb> Dillybob1992, You meant to pass the GameServer instance into the Client instance upon creating the Client in the GameServer (like `clients << Client.new(self, tcp_client)`)
<Papierkorb> Dillybob1992, I recommend you read some short introduction page to skim over OOP terminology
txdv has quit [Ping timeout: 264 seconds]
<FromGitter> <Dillybob1992> so, when i am calling `self` inside `class Client < GameServer`, it's actually the Client class, and GameServer`, not just the Client itself. Why does it puts `#<Client:0x7ab660>`? it technically `GameServer->#<Client:0x7ab660>` right?
<Papierkorb> No, it's a client
DTZUZU has quit [Quit: WeeChat 1.9]
<Papierkorb> Dillybob1992, You want to access some variable from GameServer in Client, right? So you chose inheritance, correct? Open a new file (or use `crystal play`), and write a short snippet of code trying your assumption
<FromGitter> <Dillybob1992> yes, 1 sec
<Papierkorb> some GameServer class having a @clients array of Client, and a method to 1) create a new client 2) put that client into @clients 3) return that client. Second, the Client class, with a method to access that @clients (a getter method, really). Then create a GameServer, add one or two Clients, and call Clients getter method on both to verify
<FromGitter> <Dillybob1992> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a5d3d3bae53c15903f06cf8]
<FromGitter> <Dillybob1992> what is self referring to here?
<Papierkorb> Dillybob1992, You'll want to read up on what Inheritance does (and doesn't), you'll want to know what OOP terminology does or you'll end up completely confused on the long run. There's plenty (free) material on it, much better than what I'd be able to write in a few lines on IRC
txdv has joined #crystal-lang
<Papierkorb> Crystal+OOP beginner material is lacking, though what you can find on the same topic for (modern) JS should mostly translate over. The concepts are the same everywhere. If you then have questions, sure ask
<FromGitter> <Dillybob1992> maybe i should have stayed with my imperative code lol
<RX14> depends if you want to learn, or get something working quickly
<RX14> learning OOP is pretty important, it's used extremely widely in practice
qard has joined #crystal-lang
<Papierkorb> "Widely in practice" in the sense of, everywhere, not only in Crystal.
<RX14> almost everywhere*
<Papierkorb> It'll really help you on the long run, I mean like all of your life time as developer
<Papierkorb> Imperative code quickly ends up as object oriented in thought too
<FromGitter> <Dillybob1992> that's how i see that code
<FromGitter> <l3kn> What you want to say is “There is something named GameServer that has a list of Clients”
<RX14> @Dillybob1992 yeah, there is a link between clients and gameservers
<FromGitter> <l3kn> Your code above says “There is something named GameServer and a special version of it named Client”
<RX14> the gameserver should know of all clients
<RX14> and clients need to know about the gamesense
<RX14> and clients need to know about the gameserver
<RX14> that doesn't mean a Client *is* a gameserver