<FromGitter>
<Dillybob1992> @l3kn this is more in line of my image i showed right?
<FromGitter>
<l3kn> This is better, but there is one thing I would change
<FromGitter>
<l3kn> In OOP there is the concept of “separation of concerns”
<FromGitter>
<l3kn> which of your classes should be concerned with adding stuff to the game servers players?
greengriminal has joined #crystal-lang
<FromGitter>
<l3kn> think about what would happen if you renamed `players` inside the `GameServer` class, the code of how many classes would you need to change?
greengriminal has quit [Client Quit]
<FromGitter>
<Dillybob1992> im not too sure honestly :P but those are good questions..
<FromGitter>
<Dillybob1992> i mean, this is a good step / better than what i had before right
<Papierkorb>
Dillybob1992, it is better (or actually, it's "correct"). But the client shouldn't add itself, the server should add the client to its own list.
<Papierkorb>
In the general case, a child shouldn't change the state of a parent.
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
<FromGitter>
<Dillybob1992> well, sweet i did it then!
<FromGitter>
<Dillybob1992> thank you all, very helpful <3
<FromGitter>
<l3kn> `args = nil` sets the default value of `args`
<FromGitter>
<l3kn> if you do something like `run(foo, [1,2,3])` args will be `[1,2,3]`, if you do `run(foo)`, args will be `nil`
<FromGitter>
<watzon> But doesn't it need a type assigned to it? I thought if you assigned a default value of `nil` the compiler had to know what other type it should be expecting
<FromGitter>
<l3kn> If the compiler has enough information to infer it by itself, you don't need to add the type
<oprypin>
watzon, apparently it's still duck typing
<FromGitter>
<watzon> Interesting. I was under the impression that a type was needed
<FromGitter>
<watzon> Nice haha
<oprypin>
have you tried a default of a string and passing it an integer?
<FromGitter>
<watzon> I have not
<FromGitter>
<watzon> Does that work?
<oprypin>
that's one way to confirm it. because i was also under the impression that it sets the type with that
<oprypin>
pls try and let me know :p
<FromGitter>
<watzon> I'm wondering if it's a recent addition
<FromGitter>
<watzon> I just tried with a default of `nil` and no type and it worked
<oprypin>
I'm saying a default of "some string"
<oprypin>
just to make sure nil isn't a special case
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<watzon> I could swear it did not do that before
<oprypin>
try it on old versions in carc.in
<FromGitter>
<watzon> Hahaha well good job
<oprypin>
that one i definitely don't wanna do in mobile
<FromGitter>
<watzon> Hmm it looks like it still works clear back to 0.19
<FromGitter>
<watzon> Prior to that other things break
DTZUZU has joined #crystal-lang
greengriminal has quit [Ping timeout: 256 seconds]
greengriminal has joined #crystal-lang
wontruefree has quit [Ping timeout: 255 seconds]
wontruefree has joined #crystal-lang
wontruef_ has joined #crystal-lang
<FromGitter>
<bew> @watzon maybe you were confused with how default value of args are important for the initialize, so when you do `def initialize(@a = true); end`, `@a` will be of type `Bool`, and would have default value to `true`.
wontruefree has quit [Ping timeout: 255 seconds]
<hightower4>
When I am using HTTP::Server and get the handler invoked, where is the IP of the client?
wontruef_ has quit [Ping timeout: 255 seconds]
wontruefree has joined #crystal-lang
<FromGitter>
<bew> hightower4: this is an open issue #453
<FromGitter>
<Dillybob1992> so when you do type: Location, you don't need to initialize the class or call .new?
wontruefree has quit [Quit: The Internet needs a break and I need a cookie]
notdaniel has joined #crystal-lang
wontruefree has joined #crystal-lang
notdaniel has quit [Ping timeout: 276 seconds]
wontruefree has quit [Quit: The Internet needs a break and I need a cookie]
wontruefree has joined #crystal-lang
hightower4 has quit [Ping timeout: 248 seconds]
davic has joined #crystal-lang
faustinoaq has joined #crystal-lang
<FromGitter>
<Dillybob1992> Wow, `NamedTuple` are awesome..
<FromGitter>
<Dillybob1992> Wait, I mean Hash :D
wontruefree has quit [Quit: The Internet needs a break and I need a cookie]
wontruefree has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
kosmonaut has quit [Remote host closed the connection]
Liothen has quit [Remote host closed the connection]
Liothen has joined #crystal-lang
Liothen has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
snsei has quit [Remote host closed the connection]
<FromGitter>
<Dillybob1992> hey guys, here is some json code https://carc.in/#/r/3e55 -- is it possible to convert all json datatypes to string, after doing JSON.parse(rawJSON)?
<FromGitter>
<bararchy> ^ @asterite that's a cool trick
faustinoaq has joined #crystal-lang
<FromGitter>
<Dillybob1992> hey guys, im trying to get the sha1 from a string ⏎ ⏎ ```password = "mike" ⏎ ⏎ puts Digest::SHA1.digest(password).hash``` ⏎ ⏎ this gives me `7517718617175827401`, but i need the hash of it , which is `a17fed27eaa842282862ff7c1b9c8395a26ac320` am i doing it right? [https://gitter.im/crystal-lang/crystal?at=5a5dd1aa290a1f456194778e]
jnyw has quit [Quit: WeeChat 2.0.1]
Hates_ has joined #crystal-lang
Hates_ has left #crystal-lang [#crystal-lang]
<crystal-gh>
[crystal] straight-shoota opened pull request #5594: Fix offset handling of String#rindex with Regex (master...jm/fix/5590) https://git.io/vNlnM
<FromGitter>
<bmulvihill> Whats the best way to do a recursive type for JSON::Mapping?
andrewzah has quit [Ping timeout: 255 seconds]
<FromGitter>
<bmulvihill> Basically if I have arbitrarily nested arrays with integers is there an easy way to map that? i.e.: `[1,2,[[3]],[4,5,[[[6]]]]`
<FromGitter>
<asterite> No way to do that. But why do you need that?
<FromGitter>
<asterite> Or just parse into JSON::Any
snsei has quit [Ping timeout: 255 seconds]
andrewzah has joined #crystal-lang
snsei has joined #crystal-lang
andrewzah has quit [Ping timeout: 248 seconds]
andrewzah has joined #crystal-lang
<FromGitter>
<bmulvihill> I was trying to map the values to Int32 instead of Int64
<RX14>
@asterite the thing about lcoal variable type restrictions in crystal vs other languages is that it doesn't *add* any new information
<RX14>
it only creates more errors and strictness
snsei has joined #crystal-lang
<RX14>
other then scoping (where you can use `foo = nil` to set scoping anyway), removing the type restrictions on any compiling piece of code won't change the type
<RX14>
So there's little usecase in the first place
LastWhisper____ has joined #crystal-lang
<RX14>
restricting the size of numbers is a fairly good point, where you can accidentally generate a (UInt8 | Int32) and not realise it, but i'm not sure of where that would be a problem?
<RX14>
if you're assigning that union to an ivar, you get an error
<RX14>
if you're passing it to a lib function, you get an automatic cast
<FromGitter>
<bararchy> RX14 seems like Manas are pushing GSOC :)
<RX14>
yes
<FromGitter>
<bararchy> I really hope we make it
<FromGitter>
<asterite> RX14 it means invisible slower code
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter>
<asterite> I hope they push GSOC but hopefuly they don't spend their time in that instead of doing stuff that people want
<RX14>
@asterite if gsoc means I can work on crystal full-time for 3 months in the summer then it's probably worth it...
<FromGitter>
<asterite> probably yes
<RX14>
@asterite yeah there is that...
<RX14>
but there is the method argument type restriction thing
<RX14>
inconsistency
<FromGitter>
<asterite> I guess the language will always remain inconsistent if we want it to work like that
<RX14>
for the rare performance-critical places where this is needed, it'd be ideal to have a method which is clearly an assertion, not a restriction
<RX14>
because local variables can't be restricted, they're already the smallest type the compiler can infer
<RX14>
so a local variable type restriction is just a local variable type assertion
<RX14>
ideally you could just do {% raise unless typeof(foo) == Int32 %} but that's a whole new can of worms
greengriminal has joined #crystal-lang
<FromGitter>
<asterite> Another thing is that you could probably spot the performance problem with a profiler, so it's not a real issue
<FromGitter>
<asterite> and if it happens and you can't stop it... then it's not an issue :-P
<RX14>
I do see people try and misuse local variable type restrictions ocasionally but it's rare
<RX14>
so perhaps not worth thinking about too hard
<RX14>
@asterite well it'd be pretty hard to spot with a profiler
<RX14>
at least not without completely understanding the assembly
<RX14>
which is beyond me
<RX14>
I think it's better to just leave it as-is if anything
<RX14>
introducing a special {% assert_type(foo) %} could happen but... ugly
<FromGitter>
<jwaldrip> I wish you could type restrict in macros with the macro types.
<RX14>
hmm?
<FromGitter>
<jwaldrip> Be nice to have a more aligned language set in macros... You can write the signatures in such a way to hack around it, but sometimes things don't work the way you expect them to.
<FromGitter>
<jwaldrip> RX14: (hates macros) I know, I know...
<RX14>
I don't understand your issue
<FromGitter>
<jwaldrip> Just saying, where I use them I wish I could use more crystal syntax than macro syntax.
<FromGitter>
<jwaldrip> Without using `run()`
<RX14>
well crystal isn't a templating language
<FromGitter>
<asterite> We need a full interpreter for that
<FromGitter>
<jwaldrip> i didn't say it was...
<FromGitter>
<asterite> It might not be hard
<FromGitter>
<asterite> Nim has one
<FromGitter>
<asterite> Jai has one too
<RX14>
I reckon it's not worth it
<FromGitter>
<asterite> (or so it seems... though the one in Jai seems to be able to do everything)
<FromGitter>
<jwaldrip> What would be the drawbacks?
<RX14>
maintaining a whole interpreter for crystal
<RX14>
and a compiler
<RX14>
at the same time
<FromGitter>
<straight-shoota> add interpreter to the GSOC projects xD
<FromGitter>
<bmulvihill> would allow for a true REPL as well, no?
<RX14>
we're still left with the maint burden
<FromGitter>
<asterite> with that reasoning, let's remove type inference... it's honestly a pain to maintain
<RX14>
@bmulvihill unlikely
<FromGitter>
<jwaldrip> Just because it’s hard doesn’t make it useful or make the language better.
<RX14>
@asterite I don't think thinking binarily like that is a good idea
<FromGitter>
<jwaldrip> Hard is not a reason to not do something...
<RX14>
it's certainly a point against it
<FromGitter>
<jwaldrip> Great features drive people to the language.
<FromGitter>
<jwaldrip> And an interpreter Would potentially allow for REPL
<RX14>
unlikely
<FromGitter>
<jwaldrip> Y
<FromGitter>
<jwaldrip> Why?
<RX14>
because as I explain, the type system is the problem not being compiled
<RX14>
LLVM has a jit just fine
<RX14>
you can create a compiled repl with LLVM
<RX14>
julia has one
<RX14>
but they have explicit types
<FromGitter>
<jwaldrip> So force typing in the interpreter
<FromGitter>
<jwaldrip> Only allow inference in the compiler
<Vexatos>
(types in Julia are optional too)
<RX14>
so you can't run any existing code?
<RX14>
Vexatos, no they're not
<RX14>
they're just inferred
<Vexatos>
Worst case anything has a type of Any
<RX14>
@jwaldrip it's useless to have a repl that can't interpret your code
<FromGitter>
<jwaldrip> Fair...
<FromGitter>
<jwaldrip> So how does the macro system work today?
<FromGitter>
<asterite> (but calls are everything in the language)
<RX14>
@asterite btw string header is 3*4 bytes not 2*4 bytes
<RX14>
you need bytesize and codepoint size
<FromGitter>
<asterite> ah, right
<RX14>
not that it matters
kosmonaut has joined #crystal-lang
kosmonaut has quit [Client Quit]
mark_66 has quit [Remote host closed the connection]
kosmonaut has joined #crystal-lang
kosmonaut has quit [Remote host closed the connection]
kosmonaut has joined #crystal-lang
kosmonaut has quit [Remote host closed the connection]
greengriminal has quit [Quit: This computer has gone to sleep]
kosmonaut has joined #crystal-lang
kosmonaut has quit [Remote host closed the connection]
kosmonaut has joined #crystal-lang
kosmonaut has quit [Remote host closed the connection]
greengriminal has joined #crystal-lang
kosmonaut has joined #crystal-lang
alex`` has quit [Ping timeout: 255 seconds]
faustinoaq has joined #crystal-lang
faustinoaq has quit [Changing host]
faustinoaq has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
qard has joined #crystal-lang
faustinoaq has quit [Ping timeout: 268 seconds]
greengriminal has quit [Client Quit]
greengriminal has joined #crystal-lang
kosmonaut has quit [Remote host closed the connection]
kosmonaut has joined #crystal-lang
kosmonaut has quit [Remote host closed the connection]
kosmonaut has joined #crystal-lang
snsei has quit [Ping timeout: 276 seconds]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 255 seconds]
flaviodesousa has quit [Ping timeout: 260 seconds]
<crystal-gh>
[crystal] asterite closed pull request #5589: Allow leading '+' in number strings (master...allow-leading-plus-in-number-strings) https://git.io/vNWLb
snsei has joined #crystal-lang
<FromGitter>
<bararchy> Does C/C++ has a REPL ?
<Yxhuvud>
there is an interpreted version of C, yes. I don't know if it is good.
Ven`` has joined #crystal-lang
<FromGitter>
<drosehn> I can tell you that back in the 1970's the mainframe computer that I worked on had a "REPL version" of Fortran, which was called InteractiveFortran. However, it was a whole project unto itself. It didn't share any code with any of the fortran compilers that we had.
snsei has quit [Ping timeout: 276 seconds]
<FromGitter>
<drosehn> It was very very useful (at the time!), but it was also a lot of work to implement. I'd love to have something similar for crystal, but I would want crystal to be a good stable 1.0-release (or beyond) before starting on an interactive version. The `crystal play` environment is fairly nice for testing small things.
snsei has joined #crystal-lang
ua has quit [Ping timeout: 240 seconds]
Ven`` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
greengriminal has quit [Quit: This computer has gone to sleep]
ua has joined #crystal-lang
greengriminal has joined #crystal-lang
<FromGitter>
<Dillybob1992> hi all :)
<FromGitter>
<drosehn> 👋
wontruefree has quit [Quit: The Internet needs a break and I need a cookie]
snsei has quit [Ping timeout: 256 seconds]
snsei has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<Dillybob1992> i have something like this ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ and it works great. however, is no mysql server is running. it just hangs there. is there a way to raise an error if let's say, no connection in 3-5 seconds? should i use spawn and sleep to check, or? [https://gitter.im/crystal-lang/crystal?at=5a5e55e65ade18be398392fc]
qard has joined #crystal-lang
kosmonaut has quit [Remote host closed the connection]
Ven`` has joined #crystal-lang
Ven`` has quit [Read error: Connection reset by peer]
Ven`` has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<asterite> you could try passing `connect_timeout=3` in the query string
<FromGitter>
<laginha87> hi all, does anyone know how to put a breakpoint and run the specs ? ⏎ Right now when I add a debugger and run crystal spec I get this: ⏎ "Program received and didn't handle signal TRAP (5)"
<FromGitter>
<asterite> I think you need to compile with `--debug`
<FromGitter>
<asterite> but note that the debugger is very limited... I'd say you can't use it for anything yet
<FromGitter>
<laginha87> I saw that, tried running crystal spec --debug and didn't make a difference :( ⏎ Oh well I guess I'll just start printing a bunch of stuff
<FromGitter>
<asterite> You need to compile it with --debug
<FromGitter>
<asterite> like `crystal build spec/some_spec.cr --debug`
<FromGitter>
<asterite> then run it with `gdb` or `lldb`
<FromGitter>
<asterite> it doesn't work out of the box
wontruefree has joined #crystal-lang
<FromGitter>
<asterite> And then, once you fire up `gdb`, it should break at that point... but then there's not much you can do. Maybe inspect the value of some numeric variables, but that's it
<FromGitter>
<laginha87> I'll give that a shot, thanks
kosmonaut has joined #crystal-lang
<FromGitter>
<laginha87> didn't think to build the spec
qard has joined #crystal-lang
<FromGitter>
<asterite> (though for building all specs you'll probably need a file to require them all...)
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: https://git.io/vN8Vl
<crystal-gh>
crystal/master 295ddc3 Johannes Müller: Add overload to String.from_utf16 with pointer
kosmonaut has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
lacour has joined #crystal-lang
kosmonaut has quit [Remote host closed the connection]
kosmonaut has joined #crystal-lang
kosmonaut has quit [Remote host closed the connection]
greengriminal has joined #crystal-lang
kosmonaut has joined #crystal-lang
kosmonaut has quit [Remote host closed the connection]
kosmonaut has joined #crystal-lang
snsei has quit [Ping timeout: 276 seconds]
<FromGitter>
<Dillybob1992> hey, so in this example code. if let's say I append a Client to users_in_chat (ChatRoom), that's just a reference to it, it won't create a copy right?
<FromGitter>
<Dillybob1992> actually, i just puts both out, they both have `Client:0x1dd37c0`
<FromGitter>
<watzon> @Dillybob1992 I believe so
<FromGitter>
<Dillybob1992> thx, is memory references expensive to store in array?
<FromGitter>
<watzon> @Dillybob1992 wym?
<FromGitter>
<watzon> I don't think so
<FromGitter>
<Dillybob1992> nvm, overthinking it :) i think i'll be fine
snsei has quit [Ping timeout: 255 seconds]
<FromGitter>
<Dillybob1992> i really love how we can do array.each do |value|... reminds me of js for var i in looping. gives good nostalgic feeling because such short / clean syntax. but at the same time knowing it's being done way faster in crystal. hard feeling to explain, i might be the only one :O
<FromGitter>
<watzon> What's the best way to get the current platform?
snsei has joined #crystal-lang
alex`` has joined #crystal-lang
<FromGitter>
<asterite> maybe `uname` or something like that... at least if you are on ilnux/mac
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
<FromGitter>
<watzon> Yeah that's what I decided on. And then I put windows support as well with `wmic OS get OSArchitecture`
<RX14>
@watzon what part of the current platform do you need to know?
<RX14>
since compile-time flags are typically what you want
<FromGitter>
<asterite> @watzon that snippet works, like in Ruby
<FromGitter>
<watzon> @FromIRC I guess that's true huh. I just need to know the platform and the architecture. So linux, darwin, or windows and for windows I need to know if it's 32 or 64 bit
<FromGitter>
<watzon> @asterite Ok perfect. I haven't gotten to test it yet
<RX14>
what's the usecase
<FromGitter>
<watzon> @FromIRC Downloading a specific version of another program, in this case chromium
<RX14>
well
<RX14>
i'd still use flags for that actually
<crystal-gh>
[crystal] asterite opened pull request #5597: Compiler :add more locations (master...bug/5593-no-debug-info) https://git.io/vN8SM
<FromGitter>
<watzon> Flags would work. Are all of them documented somewhere?
<RX14>
even though it's not required
<RX14>
@watzon they're pieces of the target triple
sz0_ has joined #crystal-lang
<RX14>
so x86_64-linux-gnu has x86_64 linux and gnu glags set
<FromGitter>
<watzon> Is there an easy way set up to create file pemissions? Or do I have to do it in the same wat as `DEFAULT_CREATE_MODE` with a bunch of Bitwise OR's?
greengriminal has quit [Quit: This computer has gone to sleep]