ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.2 | 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
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
hgost has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<travis-ci> crystal-lang/crystal#6717e0b (master - Update distribution scripts (#6015)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/371812755
<DeBot> https://github.com/crystal-lang/crystal/pull/6015 (Update distribution scripts)
Yxhuvud has joined #crystal-lang
kurko_ has quit [Ping timeout: 256 seconds]
<FromGitter> <bew> I'm not sure I understand, from what I see the each_use method will block the fiber and call the block indefinitely with the last cpu (which one?) used percentage
<FromGitter> <bew> But it will not return
<FromGitter> <asterite> Literal regex is compiled and stored in a constant, so more efficient than Regex.new. It's a secret only I know, bwa ha ha
<FromGitter> <bew> (so the doc doesn't seems to match what it actually do)
<FromGitter> <bew> Ahah @asterite I was wondering about that possibility, but never actually asked :P nice!!
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
__mwalsh__ has joined #crystal-lang
Yxhuvud has joined #crystal-lang
__mwalsh__ has quit [Client Quit]
__marty__ has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
__marty__ has quit []
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
__marty__ has joined #crystal-lang
__marty__ has left #crystal-lang [#crystal-lang]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 264 seconds]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Nathanaelle has joined #crystal-lang
Nathanaelle has quit [Read error: Connection reset by peer]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Nathanaelle has joined #crystal-lang
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Client Quit]
greengriminal has joined #crystal-lang
Yxhuvud has joined #crystal-lang
Nathanaelle has quit [Ping timeout: 240 seconds]
qard has joined #crystal-lang
qard has quit [Quit: qard]
qard has joined #crystal-lang
Nathanaelle has joined #crystal-lang
Nathanaelle has quit [Read error: Connection reset by peer]
Nathanaelle has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
hgost has quit [Quit: Lost terminal]
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter> <girng> 8:43 pm here, hello
qard has quit [Quit: qard]
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
<FromGitter> <kimvex> Hi
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
<FromGitter> <kimvex> Does anyone know how to get the path of the file from the code? something like example js ⏎ ⏎ `console.log(__dirname)`
<FromGitter> <kimvex> is displayed with Process.exec ("pwd")
<FromGitter> <kimvex> Is it a good practice to do that?
<FromGitter> <bew> No
<FromGitter> <bew> Just do `Dir.current`
<FromGitter> <bew> This will get the current working directory
<FromGitter> <bew> There is also `__DIR__` for the directory where the current source file is
<FromGitter> <kimvex> ooh thank you very much
alex`` has joined #crystal-lang
sagax has joined #crystal-lang
__marty__ has joined #crystal-lang
<Majost> Does anyone have an example of PrettyPrint?
<Majost> Seems to be different enough from the ruby version that I am not getting it right
<Majost> heh
<FromGitter> <bew> `pp some_things`
<FromGitter> <girng> don't get me started on `p`
Nathanaelle has quit [Read error: Connection reset by peer]
Nathanaelle has joined #crystal-lang
qard has quit [Quit: qard]
qard has joined #crystal-lang
Nathanaelle has quit [Ping timeout: 256 seconds]
Nathanaelle has joined #crystal-lang
qard has quit [Quit: qard]
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
qard has quit [Remote host closed the connection]
qard has joined #crystal-lang
DTZUZO has quit [Ping timeout: 260 seconds]
__marty__ has quit [Remote host closed the connection]
ua_ has joined #crystal-lang
ua has quit [Ping timeout: 256 seconds]
ua_ has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
That_Guy_Anon has joined #crystal-lang
txdv has quit [Ping timeout: 255 seconds]
alex`` has quit [Ping timeout: 240 seconds]
alex`` has joined #crystal-lang
qard has quit [Quit: qard]
qard has joined #crystal-lang
qard has quit [Ping timeout: 264 seconds]
ua has quit [Ping timeout: 240 seconds]
txdv has joined #crystal-lang
ua has joined #crystal-lang
<FromGitter> <yxhuvud> What is wrong with p? It does what it should, for the intended purpose (debug printing)
That_Guy_Anon has quit [Ping timeout: 240 seconds]
rumenzu has joined #crystal-lang
rumenzu has quit [Client Quit]
<crystal-gh> [crystal] sdogruyol pushed 1 new commit to master: https://git.io/vplds
<crystal-gh> crystal/master d3be42e Johannes Müller: Improve WebSocket handshake validation (#5327)
rumenzu has joined #crystal-lang
<travis-ci> crystal-lang/crystal#d3be42e (master - Improve WebSocket handshake validation (#5327)): The build was broken. https://travis-ci.org/crystal-lang/crystal/builds/371932396
<DeBot> https://github.com/crystal-lang/crystal/pull/5327 (Improve WebSocket handshake validation)
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 264 seconds]
Raimondii is now known as Raimondi
rohitpaulk has joined #crystal-lang
guilleiguaran has quit [Quit: Connection closed for inactivity]
Nathanaelle has quit [Read error: Connection reset by peer]
That_Guy_Anon has joined #crystal-lang
Nathanaelle has joined #crystal-lang
Nathanaelle has quit [Ping timeout: 256 seconds]
Nathanaelle has joined #crystal-lang
<FromGitter> <drum445> to_json returns a String type right?
Nathanaelle has quit [Read error: Connection reset by peer]
mps has joined #crystal-lang
sagax has quit [Ping timeout: 248 seconds]
Nathanaelle has joined #crystal-lang
Nathanaelle has quit [Read error: Connection reset by peer]
Nathanaelle has joined #crystal-lang
That_Guy_Anon has quit [Ping timeout: 264 seconds]
Nathanaelle has quit [Ping timeout: 256 seconds]
Nathanaelle has joined #crystal-lang
<FromGitter> <sdogruyol> @straight-shoota we broke it :) https://travis-ci.org/crystal-lang/crystal/builds/371932396
greengriminal has joined #crystal-lang
Nathanaelle has quit [Ping timeout: 264 seconds]
Nathanaelle has joined #crystal-lang
<FromGitter> <straight-shoota> @sdogruyol I'll fix it.
<FromGitter> <straight-shoota> That sort of error happens because PRs are pending for to long... =/
kurko_ has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter> <DRVTiny> Hello4all! Have anybody succesfully create "*.so" with Crystal?
<FromGitter> <DRVTiny> Or "did anybody create"...
<FromGitter> <asterite> Not possible for the moment, and possibly never
<FromGitter> <asterite> wow, I just downloaded SushiCoin to see how are compile times. It's about ~4600 lines of code, plus the same amount for specs. It takes about 1~2 seconds to compile. I don't know why I'm always worrying about compile times. I think the only slow one is the compiler, and there must be some special reason for that...
<FromGitter> <asterite> @DRVTiny think of Crystal as like Ruby: can you create "*.so" with Ruby? No. So you can't with Crystal either
<FromGitter> <DRVTiny> But... there is such compiler option!
greengriminal has joined #crystal-lang
<crystal-gh> [crystal] asterite reopened pull request #6007: Don't leak variable name when assining to ivar/cvar in method signature (master...feature/no-implicit-instance-var) https://git.io/vpc87
<FromGitter> <DRVTiny> With "*.so" creation support we can make it possible to write binary modules for interpreted languages such as perl, php, python
<FromGitter> <DRVTiny> This is very promising usage area for crystal
kurko_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <DRVTiny> (because lower potential barrier between compiled and interpreted languages)
<FromGitter> <DRVTiny> > With "*.so" creation support we can make it possible to write binary modules for interpreted languages such as perl, php, python ⏎ Yes, binary extensions for Ruby/MRI too :)
<txdv> write extension with the nice ruby for the shitty ruby
<FromGitter> <asterite> Yeah, it's not possible because every compilation is different. In every compilation every type gets a different ID, every symbol gets a different integer value, etc.
<FromGitter> <asterite> It's simply not possible unless we start changing a loooot of things, so I wouldn't hold my hopes up for the moment
<FromGitter> <asterite> Crystal was created to write user-facing apps, not intermediate libraries (or, well, not intermediate libraries meant to be used in languages other than Crystal). So make the best out of that single use case :-)
faustinoaq has quit [Quit: IRC client terminated!]
<FromGitter> <DRVTiny> @asterite Thank you for reply! Ok
<FromGitter> <asterite> @DRVTiny glad to help
<FromGitter> <bararchy> @asterite I thogut the only reason .so libs are not supported is that you can't disable GC, which means .so lib will GC its own memory while it should not
<FromGitter> <bararchy> Basically compile without main means .so lib
<FromGitter> <asterite> That's *another* reason why it can't be done :-)
<FromGitter> <bararchy> Here its being done ;)
<FromGitter> <bararchy> POC crystal .so
<FromGitter> <bararchy> You just need to create header, disable GC, and write fun instead of def
<FromGitter> <asterite> What does it mean "disable GC"?
<FromGitter> <asterite> you can't use the GC if you are going to do this?
<FromGitter> <bararchy> You can, but need to call it from outside
<FromGitter> <bararchy> See #3 point in the repo
<FromGitter> <DRVTiny> Oh
<FromGitter> <bararchy> I mean in the README
<FromGitter> <DRVTiny> ```fun counter_free(obj : Void*) : Void ⏎ GC.free(obj) ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5ae322861130fe3d36227cf8]
mps has left #crystal-lang [#crystal-lang]
<FromGitter> <asterite> Ah, I see. Well, it could work, I don't know. It's definitely not something "out of the box" and the repo has "proof of concept" in it and "hack" a couple of times :-D
<FromGitter> <DRVTiny> HEREDOC excelently works in macroses. Wow! Thank you, developers, its really amazing!
<FromGitter> <bararchy> @asterite yeha I wouldn't actually use this for prod or something, but it could be done, I would argue that we need to take steps to mainline this ability but its not really high priority
kurko_ has joined #crystal-lang
DTZUZO has joined #crystal-lang
<FromGitter> <girng> what is sushicoin, is it like enjin coin?
<FromGitter> <alehander42> what a great name :D
<FromGitter> <yxhuvud> @asterite would it be possible to make a solution where all exported functions to an SO is explicitly declared, ie like how we bind to c functions but backwards? Would that be simpler?
<FromGitter> <j8r> Apparently Go can do it, but have a GC - why?
<FromGitter> <yxhuvud> go have built their own GC and have people to maintain stuff like that
<FromGitter> <j8r> Having a "built-in" GC (in the same language) at the compiler will permit to create .so?! No very sure
<FromGitter> <j8r> BTW if Go can do it, Crystal can too (backed with plenty of $$$ of course)
<FromGitter> <j8r> This isn't and shouldn't be a priority though
<FromGitter> <j8r> Just see https://github.com/ysbaddaden/crystal_library . Nice work of @ysbaddaden
<FromGitter> <DRVTiny> What is a better way to recursively call closure? ⏎ ⏎ ```cl : Proc ⏎ cl = ->() { do_something; cl.call() }``` ⏎ ⏎ ? ... [https://gitter.im/crystal-lang/crystal?at=5ae32e286d7e07082b3e34a6]
<RX14> why are you trying to do that?
<RX14> why not just make a recursive method, then refer to it as a closure
<FromGitter> <bew> Shared libraries are possible and work (I did a mpv plugin once!) but iirc you can't use 2 crystal .so at the same time, as some things will conflict
<RX14> the crystal compiler can do shared libraries with some hacking
<RX14> the crystal stdlib cannot
<FromGitter> <bew> Ya
<RX14> and the effort to make that happen would come far down the line if ever
<FromGitter> <sherjilozair> def f(foo) ⏎ ⏎ ```h = g(foo)``` ⏎ ⏎ end ... [https://gitter.im/crystal-lang/crystal?at=5ae32f372b9dfdbc3ad670c9]
<RX14> it's hardly work talking about unless you want to send some PRs
<RX14> @sherjilozair because thats not how crystal's type inference works
<RX14> it doesn't matter though
<RX14> because passing Int32 to f will get you an error
<RX14> and it will show you the problem is passing the Int32 to g
<RX14> instead of just saying f is typed Int32
<RX14> when it's not explicitly done so
<FromGitter> <DRVTiny> I have a case such as ⏎ ⏎ ```How to use method in this case``` [https://gitter.im/crystal-lang/crystal?at=5ae32f8d270d7d37081183dd]
<FromGitter> <girng> foo : Int32 fix it?
<RX14> @girng for some definitions of fix
<RX14> @DRVTiny just make a private method?
<FromGitter> <sherjilozair> @RX14 in principle, is it not possible to infer the type? Would that lead to problems elsewhere? Is the algorithm really hard?
<RX14> but you don't want to infer the type
<RX14> because you might not *mean* for f to be Int32
<RX14> if you do mean for foo to be Int32 then you can be explicit about that
<RX14> you get a compile error either way
<FromGitter> <girng> @sherjilozair crystal is a statically typed i belive, it's always best to be explicit i think
<RX14> if it was always best to be explicit we wouldn't allow you to not specify type args
<RX14> also gitter bot died
<RX14> rip in peperonis
<RX14> @DRVTiny pass them in as args...
<FromGitter> <sherjilozair> But why be explicit when it's possible to infer. I don't get it.
<FromGitter> <DRVTiny> recurse_get fills data structures that exists only inside the get_tree_branch. How can private method knows about that structures??
<RX14> there we go gitter bot's back
<FromGitter> <girng> what does gitter bot do? irc bridge bot u mean? i can still ur messages
<FromGitter> <DRVTiny> Hmm. Why to use the stack if i can avoid this?
<RX14> @sherjilozair if you pass a string into f, it's better that crystal tells you that g doesn't accept strings than telling you that f doesn't accept strings
<FromGitter> <sherjilozair> @RX14 Why is it better to be explicit? I thought the whole point of Crystal was that it's smart enough to figure out what I want.
<FromGitter> <sherjilozair> Okay, let me think about this.
<RX14> if you tell the user that f doesn't accept strings you're assuming that the person who wrote function f *meant* to call g
<RX14> and that's not always true
<RX14> best to show more information
<RX14> and as I explained, either way you get the same error
<FromGitter> <DRVTiny> @sherjilozair You believe in this, really? ⏎ ⏎ ```x : UInt16 ⏎ x = 1``` ⏎ ⏎ and get your exception 😄 ) [https://gitter.im/crystal-lang/crystal?at=5ae330db270d7d3708118c47]
<RX14> and @sherjilozair I didn't say that you should be more explicit
<RX14> i said exactly the opposite
<FromGitter> <sherjilozair> oh okay
<RX14> <RX14> if it was always best to be explicit we wouldn't allow you to not specify type args
<FromGitter> <girng> well, what i do is sherjilozair, is i think of crystal as a statically typed language (it really is I think), and then use I union types whenever my nasty dynamic language ways are haunting me
<RX14> well it is a statically typed language
<RX14> and no unnions don't make it dynamic
<RX14> it just adds more power to your static types
<FromGitter> <girng> how is it a static type if it has a union
<FromGitter> <girng> tjhat means it has multiple types
<RX14> no, it has one type
<RX14> the union of both
<FromGitter> <girng> well, the types are separated by |'s
<RX14> unions ARE types
<FromGitter> <girng> i have tons of em
<FromGitter> <sherjilozair> I'm still not convinced by your example. We could tell the user that "f does not accept strings, because g does not accept string, because and so on". That is, we could actually show the type inference logic why a particular user-defined function cannot take a certain type.
<FromGitter> <girng> yes, the union types assigned to the variable
<RX14> @sherjilozair the crystal type inference doesn't work like that
<RX14> we never grow types out of methods
<RX14> we always grow types from literals
<RX14> the type arguments to methods are always checks
<RX14> they never tell the compiler anything
<RX14> except when to throw an error
<FromGitter> <sherjilozair> @RX14 Sure. That's how the current system works. I'm asking whether there's any problem with growing types out of function types.
<FromGitter> <sherjilozair> Could, say, Crystal 2.0 support types grown out of function types.
<FromGitter> <girng> 1) 0 LOL
<FromGitter> <sherjilozair> Would it make the language inconsistent or something?
<RX14> @sherjilozair i don't know
<FromGitter> <bew> Time will tell
<RX14> but I do know it's not going to happen any time soon
<FromGitter> <sherjilozair> @bew You misunderstand. I'm not asking whether the devs would want that.
<FromGitter> <sherjilozair> I'm asking if it's technically possible.
<RX14> and the answer is I havent thought about it
<RX14> i'm not sure what it'd gain you though
<FromGitter> <sherjilozair> @RX14 would make crystal be closer to dynamic typing? fewer types to specify, etc.
<RX14> in crystal you know the types of the arguments of the function always before you type the body
<FromGitter> <sherjilozair> more like ruby and python.
<RX14> no?
<RX14> where do you have to specify types in the first place?
<FromGitter> <girng> in a union
<FromGitter> <sherjilozair> the point is just laziness. I know the types, but I don't want to type it.
<FromGitter> <girng> use a union
<FromGitter> <sherjilozair> esp when I'm using the variable in a function which makes it completely unambiguous what the type is.
<FromGitter> <girng> alias
<RX14> @girng you don't have to specify types of unions
<FromGitter> <sherjilozair> union's still a type.
<FromGitter> <girng> it ACCEPTS multiple types
<RX14> they just happen
<RX14> because of flow typing
<FromGitter> <DRVTiny> Arrrgh. I cant call fng closure recursively because i must assign the variable something before read it :(
<FromGitter> <girng> to a variable, which is a solution to your "lazyness"
<RX14> @sherjilozair I'm not sure it'd get you any kind of extra power at all
<RX14> crystal used to be able to infer the types of generics classes from just their usages
<RX14> we removed it because it destroyed compilation speed
<RX14> crystal used to be able to infer the types of ivars
<RX14> we removed it because it destroyed compilation speed
<FromGitter> <DRVTiny> Again, can i (in theory) call any closure recursively in Crystal? ^)
<RX14> i told you
<FromGitter> <yxhuvud> Sigh. I so wish ruby adopted the &. syntax for block methods.
<RX14> go make a method
rohitpaulk has quit [Ping timeout: 265 seconds]
<FromGitter> <girng> https://crystal-lang.org/docs/syntax_and_semantics/c_bindings/alias.html look here: ⏎ now instead of `alias MyCustomType = Int32`, do `alias MyCustomType = Int32 | String | Int16 | Int8 | Int64 | Nil, <addmore if u need>`. ⏎ ⏎ now your MyCustomType can be casted as a String, Int32, Int16, Int64, or nil [https://gitter.im/crystal-lang/crystal?at=5ae3338a15c9b0311441382d]
<RX14> uhh ok
<FromGitter> <bew> ...
<FromGitter> <girng> am i wrong?
<RX14> no
<RX14> but it's just not relevant
<FromGitter> <girng> that's exaclty his issue
<FromGitter> <DRVTiny> Heh, i finally CAN call closure recursively, so i can avoid stupid OOP patterns here. ⏎ Uhhu!!!
<RX14> @DRVTiny how
<FromGitter> <DRVTiny> Declare empty prototype for function
<RX14> yes
<FromGitter> <asterite> RX14: actually, we added explicit types so we could eventually compile it incrementally or modularly. I'm not sure it affected compile times, probably yes. But now that I'm not sure about improving compile time speed, maybe we can just let the compiler infer everything from usage :-P
<RX14> but it's just easier to write a private function
<RX14> @asterite at least the generic args speeded stuff up
<FromGitter> <asterite> Hm, actually, the other reason was better error messages. Having something being inferred to some types and not understanding why was a big problem
<FromGitter> <DRVTiny> First, i declare empty proto ant then create function that do what i need and calls itself recursively
<FromGitter> <asterite> Ah, yes, without generic args it was exponentially slow
<RX14> I ended up liking typed ivars @asterite
<FromGitter> <girng> he wants a more "dynamic type" his parameter (`foo`). If he's using this, he doesn't have to worry about explicitness stuff. he the union will take care of it for him. that's what i got out of it anyway
<RX14> even though i was on the other side
<FromGitter> <asterite> I think me too. It's give a solid anchor in all the untyped sea
<FromGitter> <sherjilozair> @asterite What do you think about inferring types from function types?
<RX14> @girng no, @sherjilozair is asking about the compiler internals
<RX14> nothing to do with expressability
<FromGitter> <asterite> @sherjilozair what do you mean?
<FromGitter> <yxhuvud> yeah it is nice to type the structures, whereas the nitty gritty details about method arguments are often uninteresting
<FromGitter> <girng> because now he can do foo : MyCustomType (that he created from the alias)
<FromGitter> <asterite> Ah, no, function types are generics, so we can't infer types there
<RX14> well yeah thats one hurdle
<FromGitter> <sherjilozair> @asterite If I have a variable which is being used as an input to a method whose signature is known, then Crystal should be able to figure out the variable's type, but right now, it doesn't.
<FromGitter> <sherjilozair> @asterite This struck me as odd. I thought Crystal wanted to minimize the number of types the programmer has to add.
<RX14> @sherjilozair but crystal can already figure out the variable's type from where it was assigned
<FromGitter> <girng> omg
<RX14> so what does it gain you
<RX14> I'm asking around the motivation for the question
<FromGitter> <asterite> @sherjilozair what's an example? I can't understand without code
<RX14> because I see no example where what you're proposing adds expresiveness @sherjilozair
<FromGitter> <DRVTiny> > but crystal can already figure out the variable's type from where it was assigned ⏎ Why it infere type of var "x" in x = 1 as Int32, but not UInt8? :)
<RX14> because 1 is an Int32
<RX14> thats just how it works
<FromGitter> <sherjilozair> ```def foo(x) ⏎ bar(x) ⏎ end``` ⏎ ⏎ Here, `bar` is known to accept only `Int32`. So, `x`'s type should be Int32, but right now I have to add it in myself. [https://gitter.im/crystal-lang/crystal?at=5ae3351a7c3a01610d293767]
<RX14> @sherjilozair but you don't have to add it in yourself
<FromGitter> <asterite> what do you mean "I have to add it"? It works if you don't add it
<RX14> ^
<FromGitter> <sherjilozair> I have to do this: ⏎ ⏎ ```def foo(x : Int32) ⏎ bar(x) ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5ae3353a6d7e07082b3e6307]
<FromGitter> <asterite> No, you don't have to do it
<FromGitter> <DRVTiny> No, it is 1 byte long UInt8: where is the sign? 1 is less than 256 and have not the sign so it is 1 byte UInt8 😄
<FromGitter> <sherjilozair> Maybe for instance vars I have to.
<FromGitter> <asterite> 1 could be Int8, Int16, Int32. By Crystal chooses Int32 because it's the most common int type
<FromGitter> <asterite> For instance vars you have to. That's the only thing
<FromGitter> <bew> @asterite how are you doing about the meta attributes? Did you started a poc?
<FromGitter> <sherjilozair> @asterite @RX14 Here's a complete example: https://play.crystal-lang.org/#/r/3ym5
<FromGitter> <sherjilozair> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ae336767c3a01610d293da7]
<RX14> well, first of all, I don't think you're understanding what instance variables are
<FromGitter> <sherjilozair> Math.cos only accepts `Float64`, so `@x` should be typed as `Float64`, but Crystal gives me compiler error.
<RX14> because you don't need one there
<FromGitter> <sherjilozair> :/
<FromGitter> <sherjilozair> This is an example.
<FromGitter> <sherjilozair> I might need @x for something latter. :|
<RX14> @sherjilozair then write a good example :P https://play.crystal-lang.org/#/r/3ymb
<RX14> but you're right, that exact example used to work
<RX14> we didn't infer the type of @x from the Math.cos though
<RX14> we always infered the type of `@x` from the type of `2`
rumenzu has quit []
<RX14> how it was inferred doesn't matter
<FromGitter> <sherjilozair> Right. Now it doesn't infer from the literal or the function signature.
<RX14> we removed type inference for ivars because it leads to confusing code#
<FromGitter> <girng> crystal is a statically typed language............. why try to make "automatically" infer types?!
<FromGitter> <girng> must explicitly define types...
<FromGitter> <sherjilozair> @girng to me that's the whole point of crystal.
<RX14> @girng it does already automatically infer types lol
<FromGitter> <sherjilozair> Static power but dynamic-seeming syntax.
<RX14> being explicit about your ivar types is such a small burden
<RX14> and it makes errors a lot better
<FromGitter> <sherjilozair> @RX14 It is. But it's still annoying.
<FromGitter> <asterite> bew: I have a conflict implement meta attribute. The attributes can be used inside methods, but not outside them because instance vars are not yet defined them. So this is another confusing thing about the language, I don't know if it'll be okay, maybe yes. But I didn't start implementing anything yet
<RX14> @sherjilozair it's less annoying than debugging the messes it makes
<RX14> trust me
<RX14> I used crystal when it did work
That_Guy_Anon has joined #crystal-lang
<FromGitter> <asterite> @sherjilozair sorry, that's not how it works. Crystal won't infer instance vars from (complex) usage
<FromGitter> <girng> @sherjilozair i feel you, that's why i like the union stuff. because i am lazy.
<FromGitter> <asterite> how hard is it to type `@x : Float64?`?
<FromGitter> <sherjilozair> @asterite That's a very weird counter-argument. How hard is it to use a statically-typed language? Why am I not just using C# or C++ or C?
<FromGitter> <asterite> Why you are not using Ruby, where you don't need to type anything?
<RX14> @sherjilozair, because the frequency of types is reduced from one every 5 lines of code to maybe 1 every 500
<FromGitter> <sherjilozair> I primarily do use Python for my work. I started looking into Crystal because I was hooked by the advertisements.
<FromGitter> <j8r> I dunno maybe I'm saying something idiot, but what about a type inferer that adds the types directly in the code. Once added, no more performance/debbuging mess penality
<FromGitter> <sherjilozair> @j8r Yeah, maybe an IDE could do that.
<FromGitter> <sherjilozair> @j8r Or better, preprocessing.
<RX14> @sherjilozair crystal is between dynamic and static typed languages
<RX14> it's a tradeoff
<RX14> this is just one tradeoff we had to do
<FromGitter> <j8r> Or https://github.com/veelenga/ameba maybe?
<RX14> and I think we explained that tradeoff pretty well:
<RX14> typing ivars gains you a lot better error messages for very little work
<FromGitter> <sherjilozair> Is there an example you could give which demonstrates why not typing ivars is a bad idea? I can't really think why ivars are special here.
<RX14> and the same is *not* true for method args or method bodies
<FromGitter> <asterite> @sherjilozair you'll be surprised then to know that I (and waj) wouldn't mind having crystal be typed in even more places. To us not typing stuff was a nice experiment, that will probably go on, but we are more inclined now to type more and more stuff
<RX14> @sherjilozair because "instantiating" a class is additive
<FromGitter> <asterite> @sherjilozair it's easy, try to implement such language and you'll understand why it's not a good idea
<RX14> instantiating a method is seperate
<FromGitter> <DRVTiny> I dont know ANY statically typed language without any type inference, that produces an exception when assigning number 45 to variable declared as UInt16 ⏎ Crystal is unique language that forces me to write something strange like 45_u16
<FromGitter> <picatz> I got hooked on types pretty fast. ✨
<FromGitter> <sherjilozair> @asterite That is very surprising. I thought that that is Crystal's USP>
<RX14> @asterite from the compiler authors side of course you want us to ass more types
<RX14> from a lamguage users point of view they want types to always be optional
<FromGitter> <asterite> @DRVTiny yes, there's an issue for that, it might be fixed one day
<FromGitter> <yxhuvud> @DRVTiny Ada doesn't do automatic type coersions.
<RX14> @sherjilozair to be fair @asterite
<RX14> s view isn't shared among the userbase
<FromGitter> <sherjilozair> @asterite As @RX14 says, maybe this is your bias as a compiler designer? I think I'd happy to lose some performance if I don't have to add types at all.
<FromGitter> <sherjilozair> And I'd be happy to add types in if I wanted to improve performance later in the development.
<FromGitter> <asterite> @sherjilozair you mean, you'll have happy to wait 30 minutes to compile a "hello world"?
<FromGitter> <yxhuvud> otoh, it is pretty nice when the compiler designers are happy with their languages :P
<RX14> @sherjilozair let me explain how ivars and normal vars are different
<FromGitter> <sherjilozair> @asterite I'm sure that's an exaggeration.
<FromGitter> <asterite> @sherjilozair I *know* it's not
<FromGitter> <girng> @sherjilozair please don't be put off just by this silly infer type thing man. i am a testament at how fun and easy this language is to learn (if you see chat history logs, i don't have python or ruby background at ALL, i'm from nodejs). i'm still learning massively and converting my gameserver and crystal has been a godsend, really. it's super fast and syntaxically pleasing. ⏎ ⏎ please don't judge the
<FromGitter> ... entire potential of the language over one little issue. if I did that, i would have stopped LONG ago.but you don't know how happy I am to of stayed
<RX14> in crystal when you call a method, it is templated out into many instantiations of the method
<RX14> each instantiation has a specific set of types for it's arguments
<FromGitter> <sherjilozair> @girng Don't misunderstand me. I'm loving Crystal, and I will continue to use it, and participate in the ecosystem.
<RX14> for an instance var, you cannot template the types
<RX14> unless your class is specifically generic
<FromGitter> <sherjilozair> @girng As we speak, I am working on CUDA wrappers for crystal.
<FromGitter> <picatz> @asterite @sherjilozair RX14 I love the conversation ❤️
<FromGitter> <j8r> And type in argument adds documentation, neat!
<RX14> because you have to have all classes have the same binary layout
<FromGitter> <yxhuvud> TBH I didn't like declaring ivars when that change was made, but it has convinced me over time.
<RX14> all methods don't have to have the same binary layout
<RX14> so in ivars, some code that's entirely UNRELATED to the error trace can change the type if an ivar
<FromGitter> <DRVTiny> "end" is very annoying in languages like ruby, crystal, python ⏎ Neraly always i have to write some comment right after "end" such as ⏎ ⏎ ```end some_function``` [https://gitter.im/crystal-lang/crystal?at=5ae33997270d7d370811bc53]
<RX14> but the same is absolutely not true for local vars and method args
<FromGitter> <girng> @sherjilozair ok, i am sorry for misunderstanding, just the vibe i felt (it was kinda strong so i thoguht it'd be worth it to tell you)
<RX14> and thats why we have the distinction
<FromGitter> <DRVTiny> I mean, use it will be very good to make it possible to insert some_optional_text after "end" without a pound sign
<RX14> @DRVTiny if you can't see what end matches to what start, then your methods are too complex
<dom96> @DRVTiny Python?
<FromGitter> <DRVTiny> Python not uses "end"?
<FromGitter> <sherjilozair> @RX14 Could you elaborate on "some code that's entirely UNRELATED to the error trace can change the type if an ivar" ? Why not just consider the code which caused the type of the ivar to change as part of the message being shown to the user when there is an error.
<dom96> indeed it doesn't
<dom96> One of the great things about Python IMO ;)
<FromGitter> <sherjilozair> @asterite Are you really saying that inferring ivar types made compilation take 30 minutes for a program as big as "hello world"?
<FromGitter> <DRVTiny> Ah, yes, python uses indents! My primary language is perl, sorry
<FromGitter> <sherjilozair> Yeah optional `end` might be another good thing for Crystal. (but I don't care about this too much)
<RX14> @sherjilozair https://carc.in/#/r/3ymt
<RX14> look at that error
<FromGitter> <fridgerator> optional end ?!? thats crazy talk
<RX14> and imagine that the Foo.new("bar") was at a random place in your 30k line codebase
<FromGitter> <girng> u can do optional end 1 line if statement at end
<RX14> @sherjilozair *that*'s why we're explicit
<FromGitter> <j8r> @sherjilozair the point also is adding documentation - it's never bad to specifiy types in arguments
<FromGitter> <girng> return client.send "Test" if client.user_id ==2 # << VALID CRYSTAL CODE , no `end`
<FromGitter> <picatz> @j8r woot woot! Documentation! 🎉
<FromGitter> <j8r> @picatz ?!
<RX14> there's way too many people talking about random stuff
ua_ has joined #crystal-lang
<FromGitter> <picatz> :shipit: Crystal is pop'n
<FromGitter> <sherjilozair> @j8r yes, adding types for documentation makes sense. However, the question is whether it should be compulsory. If I'm writing a script just to test something (common in web scraping, scientific computing), there's nothing to document here. This is the usecase I care about (rapid prototyping), and where optional types would help.
<RX14> @sherjilozair which is *exactly* why we keep optional typing in every place where it makes sense
<RX14> however the example I showed you shows you that the error messages for inferring ivar types are crazy
<RX14> because @x becomes String | Int32 "by magic" based on two wildly disparate statements anywhere in your codebase
<RX14> in methods, you just type x as String and x as Int32 seperately and compile two method instantiations
<RX14> simple and avoids the problem
<RX14> in ivars, thats impossible
ua has quit [Ping timeout: 240 seconds]
<FromGitter> <girng> what'st he difference between
<FromGitter> <girng> property variablename ⏎ and "instance variables"?
<FromGitter> <sherjilozair> @RX14 Yeah this error is crazy.
<RX14> the compiler can automatixcally make methods generic (in fact, every method is templated or generic)
<RX14> it's insane to automatically make classes generic
<RX14> because automatically making classes generic makes them not binary compatible and then you're fucked
<FromGitter> <j8r> @girng the `property`macro generates `def`s to access/modify the ivar from the outside
<FromGitter> <girng> yah, but then why do we need to use @'s in parameter if it's already created by the macro
<FromGitter> <girng> or, i mean inside def initialize
<RX14> @sherjilozair hopefully you understand a bit more now
<FromGitter> <j8r> @girng because it's an instance variable, scoped in the class
<FromGitter> <j8r> to modify the variable, you need the @ thing. But to access it, it has already a method that has its name `def ivar; @ivar; end`
<FromGitter> <j8r> that's why you don't need the @ (personally I prefer to use it)
<FromGitter> <girng> ohhh ok
<FromGitter> <girng> for example: https://play.crystal-lang.org/#/r/3yn1
<FromGitter> <girng> if you remove the `@`, it will print Test Player
<FromGitter> <girng> But if you use the @, it modifies the variable
<FromGitter> <girng> instance variable**
<FromGitter> <j8r> Also there is `def ivar=(@ivar); end` so you can modify it without the @ inside defs
<FromGitter> <j8r> and from outside
ua_ has quit [Ping timeout: 240 seconds]
<FromGitter> <girng> so wait, what happens when the @ isn't used
<FromGitter> <girng> there is no error
<RX14> i really don't like @var except inside the ctor
<RX14> as in
<RX14> inside args
<FromGitter> <girng> but it compiles, but the variable doesn't change (so we know it didn't work)
<FromGitter> <j8r> I was talking inside methods, `@var` vs (self.)`var`
<FromGitter> <sherjilozair> @RX14 Yes, thanks. I'm slightly more convinced. However, I will think about this more. You are using the example of a bad error message to show why something is bad. But I'm not 100% convinced that it's not possible to produce better error messages. Is that what you're claiming? That better error messages are impossible without explicit types?
<FromGitter> <girng> @j8r ok look: https://play.crystal-lang.org/#/r/3yn2, so the `@` is synonymous with `self`, for modifying variables?
<RX14> @sherjilozair i'm not claiming they're impossible
<FromGitter> <girng> it's a short hand syntax?
<FromGitter> <j8r> @girng no
<FromGitter> <girng> well, it works... it modified the variable lol
<RX14> @sherjilozair, you'd have to list every single time the type changed, and the entire backtrace of the type
<RX14> consider that finding out why any particular variable is a particular type in crystal can generate well over 5 pages of errors
<RX14> then multiply that by the number of times an ivar type changes
<RX14> you're on a course for the same error messages you get with C++ templates
<FromGitter> <girng> that means bad performance?
<RX14> and nobody likes them
<FromGitter> <j8r> @girng how do you access methods inside the same classes?
<FromGitter> <girng> @j8r methods? i just type the method name out lol
<FromGitter> <j8r> `def name; end` can be accessed by `name`, a shortcut of `self.name` (in a Class)
ua_ has joined #crystal-lang
<FromGitter> <j8r> Why `name == @name` is becasue `def name; @name; end` generated by the macro
<FromGitter> <girng> ok
<RX14> @sherjilozair i'm sure you could generate a couple megabytes of error messages with only a few lines of crystal if you went the "complete error message" path
<FromGitter> <girng> so with that said, what's the "proper" way to modify a variable in a class? `@` or `self`?
<FromGitter> <j8r> 1) Only use macros like getter, setter and property when you need to. ⏎ 2) It's better to directly modify an instance variable (`@`) vs passing by instance methods
<FromGitter> <j8r> IMO it's also clearer, you directly see instance variables in the code vs another method
<FromGitter> <girng> ok thanks well im sticking with `@` then
tilpner has quit [Quit: :wq]
<FromGitter> <girng> i am still confused
ua_ has quit [Ping timeout: 248 seconds]
<FromGitter> <j8r> Look at the generated methods
<FromGitter> <girng> what differentiates between a "instance variable" and just using property macro
<FromGitter> <girng> bcz you can access the variable after creating the class, you don't need a def initialize
<FromGitter> <girng> for example, there is no def initialize or @'s used at all: https://play.crystal-lang.org/#/r/3yn6/edit
tilpner has joined #crystal-lang
<FromGitter> <j8r> yes
<FromGitter> <girng> so where does this "instance variable" stuff come into play and what makes it different than just a regular variable (for example, `name` in my example)?
<FromGitter> <j8r> there is `@name` under the ground
<FromGitter> <girng> OH
<FromGitter> <girng> so the property macro creates the "instance variable"
<FromGitter> <girng> right?
<FromGitter> <j8r> Also use rather `getter` vs `property`
<FromGitter> <j8r> look at https://devdocs.io/crystal/api/0.24.1/object#property%28%2Anames%29-macro
<FromGitter> <j8r> hum don't seems to work
<FromGitter> <girng> oohh okay so that's where the @@'s come from lol
<FromGitter> <vlazar> @girng Probably this will help to see difference? https://play.crystal-lang.org/#/r/3ync
<FromGitter> <girng> i was looking at some crystal code and kept seeing @@'s all over i was like wtf, but they just forgot to use a macro
<FromGitter> <girng> would be easier to read i imagine
<FromGitter> <j8r> https://crystal-lang.org/api/0.24.2/Object.html#property%28%2Anames%29-macro
__marty__ has joined #crystal-lang
<FromGitter> <girng> @vlazar cool
<FromGitter> <girng> @vlazar so, in the real world examples would there be a favor of using your `modify_player_name_via_method` over `modify_player_name_via_instance_var`. or merely personal preference?
<FromGitter> <j8r> second one
<FromGitter> <girng> i just feeel like there are so many ways to modify the variable, i want to know the "proper" way. and i'm leading towards just using `@` as i believe it's universal / correct and j8r recomend it too
<FromGitter> <j8r> because `self.name` call another method that will modify the var
<FromGitter> <j8r> 1) do you have to modify ONLY in the class or from outside?
<FromGitter> <vlazar> @girg I tend to use instance vars in initializer and methods everywhere else just like @RX14
<FromGitter> <vlazar> even for private
<FromGitter> <vlazar> makes code look cleaner without all those `@`
<FromGitter> <j8r> Maybe but don't really agree
<FromGitter> <j8r> we can't see what's instance var vs method var directly
<FromGitter> <vlazar> and what's more important decouples internal implementation from interface
<FromGitter> <girng> iuno i feel like im going down a deep rabbit hole
<FromGitter> <girng> i overthinking sorry
<FromGitter> <j8r> @girng try to change `property` by `getter` when possible
<FromGitter> <girng> ok =]
<FromGitter> <vlazar> properties can have more logic to it than just assigning/returning instance vars
<FromGitter> <vlazar> > @girng try to change `property` by `getter` when possible ⏎ second that
<FromGitter> <vlazar> it's a good idea to expose as little as possible
<FromGitter> <girng> now looking over my Client Class... if property/getter macrosdidn't exist, it would be so long omg lol. im very thankful for those MACROS :D
<FromGitter> <j8r> @girng you should read all macro related stuff here https://crystal-lang.org/api/0.24.2/Object.html#property(*names)-macro (sorry for devdocs links, didn't work)
<FromGitter> <girng> yah. looks ike that's where all my "instance variable" confusion came from
<FromGitter> <girng> they are THERE!
Nathanaelle has quit [Read error: Connection reset by peer]
<FromGitter> <girng> Underground!
<FromGitter> <vlazar> :)
Nathanaelle has joined #crystal-lang
Nathanaelle has quit [Read error: Connection reset by peer]
Nathanaelle has joined #crystal-lang
bhh has quit [Quit: not here right now...]
bhh has joined #crystal-lang
Nathanaelle has quit [Read error: Connection reset by peer]
Nathanaelle has joined #crystal-lang
Nathanaelle has quit [Read error: Connection reset by peer]
Nathanaelle has joined #crystal-lang
<FromGitter> <epergo> hello guys, quick question, is it correct that `%()` interprets new line character? or should escape it?
<FromGitter> <epergo> I mean, `puts %(a \n b)` should print: ⏎ `"a \n b"` ⏎ or ⏎ ⏎ ```"a ⏎ b"``` [https://gitter.im/crystal-lang/crystal?at=5ae350877c3a01610d29d618]
<oprypin> epergo, try and see
<FromGitter> <epergo> i know it interprets it, but I don't know what it should do
<FromGitter> <epergo> I mean, doc says `If you need to write a string that has many double quotes, parentheses, or similar characters, you can use alternative literals:`, obviously it doesn't say anything about newline character but at first I thought It would not interpret newline
<FromGitter> <epergo> my bad I guess, thanks!
<FromGitter> <girng> if you want \n, can use `p`
<FromGitter> <epergo> yeah, my problem is that I was mocking an API for development, and wanted to return an example JSON with newline characters, so I was using `%()` syntax to create a stringified json and then when I was trying to parse it, it failed
__marty__ has quit [Remote host closed the connection]
<FromGitter> <girng> man, im loving the hardware REPO!
<FromGitter> <girng> is it possible to get the amount of memory used by the crystal app, instead of the entire computer?
<FromGitter> <bararchy> @girng I think @j8r is working on specific process info right now
<FromGitter> <girng> cool, no rush just kinda curious. ima take a whack and read some files c if any of em store anything related to that
<FromGitter> <j8r> @bararchy exactly. Is it possible to release the version v0.2.2? (sry I've missed to change the shards.yml)
<FromGitter> <j8r> @girng I'm working on it. I'm thinking about how to organize this, how to get the PID from an app name
<FromGitter> <j8r> `Process.pid` can be used
<FromGitter> <j8r> @girng if you want to spawn a fiber that monitor the CPU use, better to use now `Hardware::CPU.each_use`
Nathanaelle has quit [Ping timeout: 265 seconds]
Nathanaelle has joined #crystal-lang
<FromGitter> <girng> oksounds great
faustinoaq has joined #crystal-lang
<FromGitter> <j8r> I've created this because working on PIDs, and looping on`Hardware::CPU.used` can' t reuse the previously obtained CPU time
<FromGitter> <bararchy> @j8r I already merged your PR
<FromGitter> <j8r> Of course - talking about the tag ;-)
<FromGitter> <j8r> and also modifying `shards.yml` :-/
<FromGitter> <j8r> Wondering: does `Float32` enough for `/proc/uptime`?
<FromGitter> <j8r> ...likely
<FromGitter> <girng> i don't understand the answer, because top shows memory usage
<FromGitter> <girng> of each process...
<FromGitter> <girng> if the `top` command shows the memory used for each process, how can `there is no such thing as the actual memory usage of a process.` be true?
<FromGitter> <j8r> look at `VmSize` in `/proc/1/status` - this is the actual memory used
<FromGitter> <j8r> I think this is a vocabulary thing
<crystal-gh> [crystal] asterite closed pull request #2433: Add delete_first to Array (master...master) https://git.io/vV1jc
<FromGitter> <girng> ```code paste, see link``` ⏎ ⏎ what is the difference between crystal-run-Mas and crystal [https://gitter.im/crystal-lang/crystal?at=5ae35dd315c9b031144225c6]
<FromGitter> <girng> lol
<FromGitter> <j8r> there is lots of memory - used, cached, buffered, shared
<FromGitter> <girng> yeah and it's pathetic because stackoverflow won't let me comment
<FromGitter> <j8r> In the `Hardware` we don't take the cached, shared and buffered
<FromGitter> <girng> bcz i don't have "enough reputation"not fair at all.
<FromGitter> <girng> they are hindering my ability to ask questions and learn over reputation
<FromGitter> <girng> good thing crystal gitter is here to help :D
<FromGitter> <j8r> I think he would like to said that there isn't "memory used" as is: we must calculate by removing shared, cached, buffered etc from the Total Memory
<FromGitter> <girng> i see. to top is basically just a close estimate
<FromGitter> <girng> to the best of knowledge
<FromGitter> <girng> in terms of memory reading taking cached, shared, buffered into effect
<FromGitter> <j8r> Now in recent Linuxes we have just to do `used = MemTotal - MemAvailable`
<FromGitter> <girng> im going to be using debian 9 for game server, good idea?
<FromGitter> <j8r> Don't really matter (but better to have a recent dist) ;-)
<FromGitter> <j8r> Personally I like Alpine Linux, but you can't be wrong with Debian too
<FromGitter> <girng> Alpine? isn't that a type of tree lol i like the name
<FromGitter> <j8r> also don't forget to create a proper `systemd` / `openrc` service for your application!
<FromGitter> <girng> like a own custom service?
<FromGitter> <girng> daemon?
<FromGitter> <j8r> yes
<FromGitter> <girng> that's one thing i really miss about nodejs, they had a `pm2
<FromGitter> <j8r> That's baaadd
<FromGitter> <girng> but ya i need to create custom service. i think i did it before but i forgot. i bought a cheap VPS to play around with the server
<FromGitter> <j8r> If you wan't to test you init service, you can do it with this containers https://hub.docker.com/u/jrei/
<FromGitter> <girng> iuno what that is lol
<FromGitter> <j8r> Really, not hard and very reliable to create a system service
<FromGitter> <girng> i just re-install debian 9 in vps manager from host. then run my custom .sh script
<FromGitter> <girng> if i mess up the os, i just re-install a deb 9 template lol
<FromGitter> <girng> trial n error :DD
<FromGitter> <girng> my host prob sees me re-install deb 9, 10-30 times a day rofl
<FromGitter> <girng> i bet they love me =]
<FromGitter> <j8r> haha. I will stop talking because I will not advancing on PID for `hardware` :-)
<FromGitter> <girng> okok np ty for chat. i work on server
<FromGitter> <DRVTiny> Help me, please, i'm totally in doubt! :( ⏎ I have 4 classes: Host, Service, HostGroup and Trigger ⏎ All this classes is no more than "msgpack-decoders" created with auto_msgpack (and some magic of my own to provide additional to_json method). ⏎ Now: i have a string that i've read using Redis.get ⏎ And i know type of class to decode this string from_msgpack ... [
Nathanaelle has quit [Read error: Connection reset by peer]
Nathanaelle has joined #crystal-lang
<FromGitter> <DRVTiny> I.e. how to choose desired class to do from_msgpack dynamically? I know that decoded string is appropriate to, say "trigger". How to use the Trigger class to decode this string?
<FromGitter> <bew> I'm not sure I understand what you're doing, but why not do a switch-like statement?
<FromGitter> <DRVTiny> because all branches of that statement will do absolutely the same...
<FromGitter> <DRVTiny> Differences will be only in class names
<FromGitter> <bew> do you have an example of a dumb implementation of what you want?
<FromGitter> <bew> but you'll still have a case..when..end for the class name wouldn't you?
<FromGitter> <DRVTiny> yes, wait a seond
<FromGitter> <DRVTiny> ```code paste, see link``` ⏎ ⏎ Here instead of " = true" i must write something like className[zoltr].from_msgpack(zobj_s.to_slice) [https://gitter.im/crystal-lang/crystal?at=5ae3639eb01085166ccaa2e5]
<FromGitter> <bew> weird naming scheme for your variables, I can't understand a thing ^^
<FromGitter> <bew> nvm, what are the types here?
<FromGitter> <DRVTiny> zobjs_s is a string :)
<FromGitter> <DRVTiny> zoids - Array(Int32)
<FromGitter> <DRVTiny> fill_this is a Hash(String, (Cache2::Service | Cache2::Host | Cache2::HostGroup | Cache2::Trigger))
<FromGitter> <DRVTiny> something like ⏎ fill_this["s1234"] = {serviceid: 567, name: "ITService01"} ⏎ fill_this["t98765"] = {triggerid: 5347896, description: "Operation timeout, 4-th reactor destroyed"}
<FromGitter> <DRVTiny> I prefer camelCase naming scheme bit in Ruby-world using camelCase it is not comfortable IMHO
<FromGitter> <DRVTiny> fill_this is a plain collection of different objects :)
That_Guy_Anon has quit [Ping timeout: 240 seconds]
That_Guy_Anon has joined #crystal-lang
<FromGitter> <DRVTiny> Hmm... I can generate switch aka case statement with macro...
Nathanaelle has quit [Ping timeout: 240 seconds]
Nathanaelle has joined #crystal-lang
ua has joined #crystal-lang
<FromGitter> <bew> hmm yes, but that case statement is not that long, and won't probably change much later. I don't think it's worth the burden, and just make the case statement for each class
<FromGitter> <DRVTiny> i have to create when for each redc.mget do .. end - and block inside mget may grown in the future. But... ok, macro totally satisfy me needs here
<FromGitter> <bew> I don't get it, what do you mean by `for each redc.mget do .. end` ? if you need to repeat the whole case statement multiple time, you could do a (private) method I guess?
<FromGitter> <DRVTiny> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ae36dc5dad6fb186ff3c502]
<FromGitter> <DRVTiny> In next block - it will be Host instead of Trigger
<FromGitter> <Blacksmoke16> I have aJSON structure like ```JSON ⏎ "definitions": { ⏎ "bad_gateway": { ⏎ "description": "Bad gateway model", ⏎ "properties": { ... [https://gitter.im/crystal-lang/crystal?at=5ae36df81130fe3d36242409]
<FromGitter> <bew> oooh ok, didn't understood it was the whole thing that was going to be repeated @DRVTiny
<FromGitter> <bew> maybe you could do a method for the repeated block, then call it with `method(some_args, Trigger)`
<FromGitter> <DRVTiny> @bew Crystal has wonderful, excellent macroses, "i'm lovin it" (C) :)
<FromGitter> <DRVTiny> Hm, will it be literally: Trigger ?
<FromGitter> <bew> yes
<FromGitter> <Blacksmoke16> say i have a json structure like ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ currently my mapping is like `definitions: Hash(String, Definition)` which works fine but i have to use `root.definitions["bad_request"].title` vs `root.definitions.bad_request.title` which isnt a major issue but just wondering if there is a way to do the latter [https://gitter.im/crystal
<FromGitter> ... -lang/crystal?at=5ae36edddad6fb186ff3ca0a]
<FromGitter> <bew> https://carc.in/#/r/3yo1
<crystal-gh> [crystal] sdogruyol opened pull request #6020: Revert "Improve WebSocket handshake validation" (master...revert-5327-jm-fix-websocket-key) https://git.io/vp81j
<FromGitter> <bew> ( @DRVTiny ^)
<FromGitter> <bew> yes @Blacksmoke16 don't use a hash, and use another object with only field `bad_gateway` ?
<FromGitter> <DRVTiny> @bew Wonderful!!! Thank you very-very much again!
<FromGitter> <Blacksmoke16> thats an option, but what if another definition gets added, would have to update the mapping, no way to get it to be dynamic without using Hash()?
<FromGitter> <bew> hmm maybe possible with: #6009
<DeBot> https://github.com/crystal-lang/crystal/pull/6009 (add json mapping extra fields)
<FromGitter> <Blacksmoke16> hmm neat, ill have to make a comment and revisit this when that gets released
<FromGitter> <Blacksmoke16> hash will work for now
<FromGitter> <Blacksmoke16> the json is the definition of a swagger api, so trying to keep things as generic as possible for if/when the schema changes and stuff
<FromGitter> <sherjilozair> What's the best source for learning how to write idiomatic crystal?
<FromGitter> <bew> the compiler, and tools around it developed by core developpers
<FromGitter> <sherjilozair> @bew Are there any parts of the compiler that are relatively stand-alone?
<FromGitter> <j8r> you can learn from the stdlib
<FromGitter> <sdogruyol> std is pretty nice to read
<FromGitter> <bew> oh yes and the stdlib of course (ty @j8r )
<FromGitter> <sherjilozair> stdlib is crystal/src/ excluding compiler/ right?
<FromGitter> <bew> yes!
<FromGitter> <Blacksmoke16> is there a shortcut to doing .not_nil! on stuff
<FromGitter> <Blacksmoke16> using JSON.mapping
<FromGitter> <Blacksmoke16> or something
<FromGitter> <bew> huh? no, no shortcut, but you shouldn't need it often
<FromGitter> <bew> what do you mean `using JSON.mapping` ?
<FromGitter> <Blacksmoke16> nvm was thinking of something else
<FromGitter> <sherjilozair> Is there no fold function in crystal?
<FromGitter> <Blacksmoke16> Is there support for $ref in my mappings?
<RX14> @sherjilozair that's a reduce
<RX14> crystal uses map and reduce terminology not map and fold
<RX14> and it's only really on arrays
<RX14> i mean we don't have trees or such in the std anyway
<FromGitter> <sherjilozair> @RX14 Anyway to get the intermediate results from the reduce?
<RX14> ...why?
<RX14> i mean you could just do array << accum in the reduce
<FromGitter> <bew> @Blacksmoke16 what is that?
<FromGitter> <sherjilozair> i.e. say I want to construct [1, 1*2, 1*2*3, 1*2*3*4] from [1, 2, 3, 4]
<FromGitter> <sherjilozair> @RX14 Do you see editted stuff in IRC?
<RX14> no
<FromGitter> <sherjilozair> Or shoudl I repost?
<RX14> and thank god
<FromGitter> <Blacksmoke16> i think its a swagger specific thing, where you can reference other objects
<RX14> editing is terrible :)
<FromGitter> <girng> what is swagger? new language?
<FromGitter> <girng> checking it out now
<FromGitter> <j8r> API doc, has chnaged its name recently
<FromGitter> <sherjilozair> The *s mess with gitter, but I guess it's visible to you in IRC.
<FromGitter> <sherjilozair> @RX14 Do you see what I want? Any way to do it pure functionally?
<FromGitter> <sherjilozair> Without <<.
<RX14> well you can do anything with a fold purely functionally if you want
<RX14> it'll just be messy
<FromGitter> <bew> @Blacksmoke16 yeah no, that's not supported on a generic JSON implementation, you'll have to support that yourself in some ways. What are you doing in Crystal with swagger?
<RX14> you can transliterate your fancy pantsy haskell if you want but it'll be faster and better and more readable to do it imperatively
<RX14> because crystal is an imperative language
<RX14> going against the flow in any language typically gets you bad code
<FromGitter> <girng> "fancy pantsy" rofl
<FromGitter> <Blacksmoke16> currently have a ruby script im rewriting into crystal that consumes a swagger.json file, and outputs a transformed json structure and javascript functions
<RX14> >> (1..4).reduce([] of Int32) { |arr, i| arr << arr.last + i }
<DeBot> RX14: from ??? - https://carc.in/#/r/3yo4
<FromGitter> <Blacksmoke16> https://github.com/Blacksmoke16/GESI
<RX14> fuck
<RX14> >> (1..4).reduce([] of Int32) { |arr, i| arr << (arr.last + i) }
<DeBot> RX14: from ??? - https://carc.in/#/r/3yo5
<RX14> really?
<FromGitter> <Blacksmoke16> so am able to autogenerate the JS lib from the swagger json
<RX14> oh
<RX14> i see
<FromGitter> <sherjilozair> @RX14 Well, if a function like `accumulate` existed, it would be just be `[1..4].accumulate(|a, b| a * b)`.
<RX14> >> (1..4).reduce([] of Int32) { |arr, i| arr << ((arr.last? || 0) + i) }
<DeBot> RX14: # => [1, 3, 6, 10] - https://carc.in/#/r/3yo8
<FromGitter> <Blacksmoke16> i dont really need support for $ref iirc, was just curious
<RX14> that's still mutating though
<FromGitter> <sherjilozair> @RX14 Python's accumulate: https://docs.python.org/3/library/itertools.html#itertools.accumulate
<RX14> >> (1..4).reduce([] of Int32) { |arr, i| arr << ((arr.last? || 1) * i) }
<DeBot> RX14: # => [1, 2, 6, 24] - https://carc.in/#/r/3yo9
<FromGitter> <girng> ok i just made a swagger account here (https://i.gyazo.com/baacdfde35aeb291ee649b06eaa0f6d6.png) now what?
<RX14> @sherjilozair what's the usecase
<FromGitter> <bew> @Blacksmoke16 nice ;)
<FromGitter> <Blacksmoke16> oh yea ;) beats doing it by hand
<FromGitter> <sherjilozair> Computing strides for a matrix from the dimensions. This: https://github.com/sherjilozair/jet/blob/master/src/jet/tensor.cr#L7
<RX14> well you're going to want to do that fast then
<RX14> which functional will not get you
<RX14> dims.reverse_each and keep it as-is
<RX14> plus, you know the size of the strides so you should really do strides = Array(Int32).new(dims.size)
<crystal-gh> [crystal] sdogruyol closed pull request #6020: Revert "Improve WebSocket handshake validation" (master...revert-5327-jm-fix-websocket-key) https://git.io/vp81j
<RX14> will save you some allocations
<FromGitter> <bew> you could also allocate an array of the correct size, and populate it directly in reverse (from the end to the beginning)
<RX14> yeah
<RX14> that'd be a bit ugly though
<RX14> the reverse is fairly efficient
<FromGitter> <bew> hmm maybe, didn't check how that works yet
<RX14> it's easy
<FromGitter> <sherjilozair> Yeah, my own goal is to avoid ugly code. I don't care a lot for performance here, since the array is going to be very small.
<RX14> you just swap(i, size - i) for i in (0..size/2)
<RX14> swap is simple O(1)
<FromGitter> <bew> oh right, good then
<RX14> plus handling the odd case
<RX14> but
<RX14> you get the idea
<RX14> @sherjilozair I wouldn't call that overly ugly though
<RX14> although the reduce I wrote is shorter
<RX14> but it's probably slower because of the reading into last
<RX14> @sherjilozair I suggest you either write your own accumulate function or suggest it on github
<RX14> i'm not 100% that it'd get accepted
<FromGitter> <bew> yeah I remember I did that technique at school now ^^
<RX14> except we actually do it with pointers lol
<RX14> we calculate the pointers
<RX14> and loop with a swap pointer values and then += 1 -= 1 until they meet
<FromGitter> <sherjilozair> So reverse_each and each_with_index exist, but no reverse_each_with_index.
<RX14> yes
<FromGitter> <sherjilozair> I could use reverse_each_with_index it for this example. Would it get accepted if I add it?
<RX14> i still don't get why we don't just have each and reverse_each take counters
<RX14> probably
<RX14> idk
<FromGitter> <girng> github asking meto verify me email twice now...
<RX14> i wish I knew what the mob wants the collections API to look like today
<FromGitter> <bew> RX14, like: always be with_index, and in the block you use the second arg or not based on your needs?
<FromGitter> <sherjilozair> @RX14 You mean just pass the counters along if there are two variables?
<RX14> @bew yes
<FromGitter> <sherjilozair> Which mob are you talking about? :D
<RX14> @sherjilozair trailing block args are always ignored
<RX14> @sherjilozair the ones on github issues
<FromGitter> <bew> that looks good, can you issue that?
<RX14> @bew i'm sure last time i proposed it that ary said that the overhead of maintaining a flipping counter when it's not required were too much
<RX14> but maybe I should just PR it
<FromGitter> <sherjilozair> You'll have my +1.
<FromGitter> <bew> don't you think LLVM can optimize that away?
<FromGitter> <girng> ok plz dont ask use case i jus twant to know how to do this
<FromGitter> <girng> i want to use crystal, to execute a cmd in the linux console, and get its output
<FromGitter> <girng> is this possible?
<RX14> @girng well the main point of call for that is Process.run
<FromGitter> <girng> ok i'll take a look at api ty
<RX14> @bew yes I do think that
<FromGitter> <girng> dang, no examples in Process docs :X
<FromGitter> <j8r> @girng https://github.com/j8r/exec.cr
<z64> if thats all you want to do and string output is sufficient, you can just use ` - https://crystal-lang.org/api/0.24.2/toplevel.html#%60%28command%29%3AString-class-method
<FromGitter> <j8r> needs a small rework btw
<RX14> @j8r no??
<RX14> why does that exist
<FromGitter> <j8r> haha
<RX14> it's the tiniest wrapper over Process.open
Nathanaelle has quit [Read error: Connection reset by peer]
<FromGitter> <girng> lol
<RX14> please lets not turn into nodejs
<RX14> Process.run*
Nathanaelle has joined #crystal-lang
<FromGitter> <girng> @z64 yea i just want stirng output
<FromGitter> <girng> don't ask im just fiddling around lol
<RX14> @girng `command`
<RX14> like
<RX14> surround the command in backticks
<RX14> and the process is executed and it returns stdout as a string
<FromGitter> <j8r> @RX14 I was fitting my use case, and was in my project anyway
<RX14> stderr is attached
<FromGitter> <girng> ok could i test this in playground, or use WSL?
<RX14> this is where the backtick is implemnted
<RX14> it gives you docs
<RX14> but you can also see how Process.new works
<FromGitter> <girng> oh wow super simple
<FromGitter> <j8r> just beware of `shell = true`, you can have suprises
<FromGitter> <bew> @RX14 stderr is not attached when using backtick method
<RX14> it is
<RX14> stderr is inherited
<FromGitter> <bew> where? it just gets the output?
<RX14> I meant attached as in attached to the parent
<RX14> ...
<FromGitter> <bew> oh
<RX14> stdin and stderr are inherited from the parent
<RX14> you can see it in the source
<FromGitter> <bew> ok, misunderstood
<FromGitter> <sherjilozair> @girng Calling shell commands in code is not the worst pattern. I wouldn't be very embarrassed by it.
<RX14> it depends on the code
<RX14> and the command
<RX14> I definitely use it pretty rarely
<FromGitter> <girng> won't let me get `output`
<RX14> yes
<RX14> thats using Process.new not Process.run
<RX14> Process.new returns Process which is a handle for a running process
<RX14> Process.run returns Process::Ststus
<RX14> which is a handle for a dead process
<FromGitter> <girng> in the Process class? it's defined with BACKTICKS wtf
<FromGitter> <girng> is that a method?
<RX14> it's an operator
<RX14> like
<RX14> `command`
<RX14> like you just enclose it in backticks in your source
<RX14> the compiler transforms `command` into `("command")
<RX14> and that method is called
<RX14> thats not a method on the process class
<RX14> it's on the top level
<FromGitter> <girng> wtf..
<FromGitter> <girng> so i don't use Process at all
<FromGitter> <girng> just backticks
<RX14> depends on usecase
<FromGitter> <girng> just for string output
<RX14> you can outgrow backticks pretty quickly
<FromGitter> <j8r> You may want to change the `Process` behavior e.g. not runiing in `sh`, directly call the binary `ls`
<RX14> meh
<FromGitter> <girng> ok, my apologies then i thought I had to do Process.\`cmd\` or something iw as like that's not right :P
<FromGitter> <girng> since that's in the Process class
<RX14> no it's not
<RX14> it's in process.cr
<RX14> look at the indent
<RX14> it's a method at the top level
<FromGitter> <girng> oh
<FromGitter> <girng> yep, nvm you r right
<FromGitter> <girng> ok. so oprypin is gonna kill me for asking this but...
<RX14> if oprypin will kill you, I probably will
<FromGitter> <girng> if let's say `command` with a small output..like say 10 characters or w/e, just a small command. if re-using it over and over like, let's say inside a loop do sleep 1.0 end cause any memory issues?
<FromGitter> <sherjilozair> Don't let the mob silence you @girng . Speak your heart.
<FromGitter> <girng> i wont have any memory leak issues right, it gets cleared? just more cpu intensive
<FromGitter> <girng> if called ALOT
<FromGitter> <j8r> no, the sub process exits
<RX14> @girng yeah it'd be fine
<FromGitter> <girng> ok sweet, ty just OCD about memory stuff lol
<FromGitter> <j8r> also depend of the script
<RX14> i've never created a memory leak in crystal
<FromGitter> <girng> i try not to ask but i can't help it
<RX14> ever
<RX14> you won't
<FromGitter> <girng> disgunbegood.jpg
<Vexatos> .cr
<FromGitter> <girng> i LOVE CRYSTAL!
<FromGitter> <j8r> @girng if you want more performances, you can execute `/bin/dash` rather than `/bin/bash` (x4 gain).
<FromGitter> <bew> @girng that's new 😂
<FromGitter> <j8r> But your script needs to be POSIX
<RX14> /bin/sh, please
<FromGitter> <j8r> nowadays `/bin/sh` is just a symlink for whatever shell behind
<RX14> /bin/dash is unlikely to be there
<RX14> $ /bin/dash
<RX14> zsh: no such file or directory: /bin/dash
<RX14> please dont make assumptions about distro/os
<FromGitter> <j8r> He is on Debian I guess
<RX14> /bin/sh and /bin/bash are the only shells you can ever count on
<FromGitter> <j8r> Or ubuntu: He is on WSL
<RX14> and you shouldn't count on bash either
<FromGitter> <j8r> very often it's the same - just a symlink to bash
<RX14> sure
<FromGitter> <j8r> except debian
<RX14> i'll take correct over fast
<RX14> assuming dash might get you perf, but you'll piss off anyone who tries to run it on not-debian
<RX14> so everyone
<FromGitter> <j8r> of course - he told me his server is on Debian 9, that's why
<RX14> i still hate assumptions even if I know my operating environment...
<FromGitter> <j8r> Why an assumptions?
<RX14> assuming that dash exists
<FromGitter> <girng> @j8r how do i tell the backticks to do execute inside /bin/dash?
<RX14> cant
<FromGitter> <j8r> I know the subject don't worry, I work every day on Debians (even on old 5!!!)
<FromGitter> <girng> i never heard of this dash lol googling that now
<RX14> just dont worry about it
<FromGitter> <girng> found more info: https://wiki.archlinux.org/index.php/Dash
<RX14> /bin/sh is fine
<RX14> we should probably accept shell: "/bin/dash" as well as shell: true
<FromGitter> <girng> interesting indeed
<FromGitter> <girng> i find it kinda cool how all the problems i have w/ crystal there is a solution for em. and it's just not a solution, but it's implemented really easily. syntaxically too. for example, backticks for command.
<FromGitter> <j8r> Why i told you that? Because now your used has probably /bin/bash, and the default of Debian/Ubuntu is /bin/sh. If you launch your new server with a new custom user, it may have no default shell
<FromGitter> <girng> oh @rx14 i know what was happening earlier
<FromGitter> <girng> u were trying to explain the command but on gitter, it showed: https://i.gyazo.com/0aaeb1cdb162af68e354d775cb67c72d.png which is why i was confused lol
<FromGitter> <girng> ur on IRC, so the backticks look different
<FromGitter> <sdogruyol> weird..this should be fixed https://github.com/crystal-lang/crystal/issues/4204
<FromGitter> <girng> gitter should escape those backticks if sent from irc
<FromGitter> <sdogruyol> yet I can't compile after last full system upgrade :|
<RX14> @sdogruyol yeah it broek
<RX14> blame libressl
<FromGitter> <sdogruyol> damn it
<FromGitter> <j8r> is it normal that `Dir.current` doesn't work in specs?
<FromGitter> <sdogruyol> and I thought everything's OK after the upgrade 😢
<FromGitter> <bew> @j8r what does it mean "doesn't work" ?
<RX14> doesnt compile
<RX14> i think
<RX14> idk
<FromGitter> <j8r> All seems to work, but when reaching the `Dir.current` there is a `getpwd` exception
<FromGitter> <j8r> *when running the specs on my project
<FromGitter> <j8r> but it should have the same issue in whatever spec
<FromGitter> <bew> what's the error?
faustinoaq has quit [Quit: IRC client terminated!]
<FromGitter> <j8r> `getcwd: No such file or directory (Errno)`
<FromGitter> <bew> try `cd .` then retry?
<FromGitter> <bew> (might fix it if you are in a moved directory) or just spawn a new shell maybe
<FromGitter> <j8r> yes I've noticed after a cd it works
<FromGitter> <j8r> just... strange
<FromGitter> <girng> guys how can i speed up crystal start up time. takes 5 seconds no
<FromGitter> <sdogruyol> someone wrote an Ethereum client in Elixir https://medium.com/compound-finance/introducing-exthereum-the-newest-ethereum-client-7a5e30d4d6aa
<FromGitter> <sdogruyol> we should do it too
<FromGitter> <sdogruyol> interesting
<FromGitter> <girng> now, used to be instant. or is it just bcz my project is getting kinda big?
<z64> @girng can you be more specific by "start up time"? do you mean time to compile you application, or time for your binary to start "running"?
<FromGitter> <bararchy> @j8r v.0.2.2 released :)
<FromGitter> <bararchy> ✨
<FromGitter> <girng> @z64 compile, like when i do crystal src/MasterServer.cr
<FromGitter> <girng> it used to just take 1-2 seconds now it's at least 5
<z64> `crystal foo.cr` compiles *and* runs
<z64> if you want more compile time stats you can do `crystal build foo.cr -p` or `crystal build foo.cr --stats`
<FromGitter> <girng> @z64 ok let me do stats that's interesting
<FromGitter> <girng> --stats data: https://play.crystal-lang.org/#/r/3yp7
<z64> i don't think there's really anything your can practically do to improve them, but that might give you some insight as to what the compiler is doing
<FromGitter> <j8r> @bararchy Thanks, still working on PID. 0.3.0 in the following days :-)
<FromGitter> <j8r> @bararchy I'm on Manjaro and don't have this bug, strange?!
<FromGitter> <girng> @z64 Do you think maybe because I'm on WSL it could affect it? I heard WSL is pretty "native"
<FromGitter> <bararchy> Awesome, when you add it I'll try and create a small example for the project that does HTOP style system stats
<z64> i'm totally unfamiliar with WSL
<FromGitter> <girng> But, I wonder if it's because of the requires I have
<FromGitter> <girng> those are all my requires, that could be it, right?
<FromGitter> <bararchy> @j8r I also found a bug with Arch Linux not showing mem as it should, I'll look into it
<FromGitter> <girng> is it possible to "statically" compile the main requires above "hardware"? like in the crystal code, so they don't all get compiled each time
<FromGitter> <girng> if that makes sense, lol hard to explain
<FromGitter> <girng> oh, i have another question. i wonder if the usage of comments effects compile time? does the tokenizer or w/e its called, have to strip all the comments? before running, or what? because in my LoginHandler.cr file, it's 25KB in size, and each game method has a commend block (3lines) above it, with a description
<FromGitter> <girng> or.. is that negligible?
<z64> no it doesn't, parsing is extremely fast
<FromGitter> <girng> ok, yeah just checkin
<z64> comments are just ignored entirely and won't make it into the later compiler phases where most of the time is spent (semantics / codegen, etc - look at the stats printout you made)
<FromGitter> <sdogruyol> 25kb sounds big
<FromGitter> <girng> hmm maybe it's mysql
<FromGitter> <girng> connecting
<z64> thats why i said to use `build` :p
<FromGitter> <girng> u did?sorry didnt c
<FromGitter> <girng> 1 sec le tme scroll up
<z64> but it roughly adds up to 3/4 seconds anyways from what i can see from your paste
<FromGitter> <girng> `crystal build foo.cr -p`? ok
<z64> right, or `--stats`
<FromGitter> <girng> HOLY
<FromGitter> <girng> rofl
<FromGitter> <girng> if i build, and then do ./MasterServer
<FromGitter> <girng> it connects to mysql INSTANTLY, no load at all!
<z64> lol. anyways, i gotta go. good luck
<FromGitter> <girng> ok ty
<FromGitter> <girng> have nice day ttyl
<FromGitter> <girng> ok. if i do `crystal build src/MasterServer.cr -p && ./MasterServer`, it seems like it's faster than just `crystal src/MasterServer.cr` lol what is this sorcery
<FromGitter> <sdogruyol> WSL magic?
<FromGitter> <girng> hahaah
<FromGitter> <girng> im going to do some trial n error, remove some requires
<FromGitter> <girng> see if i can hone down whats making it take the 5 seconds
<FromGitter> <girng> ok so i commented out `MasterServer.new("0.0.0.0", 9300)`
<FromGitter> <girng> time went back down to 2seconds
<FromGitter> <girng> so yeah, this class is fck'd lmao
<FromGitter> <girng> gosh damnwhat did i do wrong
alex`` has quit [Ping timeout: 265 seconds]
<FromGitter> <j8r> hown many macros have you?
<FromGitter> <girng> only have ⏎ ⏎ ```macro everything_mapping(a) ⏎ JSON.mapping({{a}}) ⏎ DB.mapping({{a}}) ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5ae38b16dad6fb186ff44eeb]
<FromGitter> <j8r> and the "a" is big?
<FromGitter> <girng> only 11 key/values
<FromGitter> <girng> is alot?
<FromGitter> <j8r> that's fine
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
<FromGitter> <girng> ok so im been look around. not sure if this is the cause but. my LoginHandler.cr file looks ike this (25kb big): ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ continues with 29 more methods. that could be it? [https://gitter.im/crystal-lang/crystal?at=5ae38f34270d7d370813641d]
<FromGitter> <bew> probably not
<FromGitter> <branconinja> hey guys!
<FromGitter> <branconinja> I am new on crystal
<FromGitter> <branconinja> How can I be part on the github organization?
<FromGitter> <branconinja> What I need to do?
<FromGitter> <girng> ok gn. need sleep i be back 3-5 hours!
<RX14> @branconinja well you start by being helpful on the issue tracker and writing PRs, but it also requires to go above and beyond in terms of having a deep understanding of the language and being opinionated
<FromGitter> <bew> also, as you're new to Crystal, you can try to make a few projects in Crystal, learn how to use the language in the current state, come here if you have any questions, and as you gain experience in Crystal, try to participate on the issues/PRs
<FromGitter> <branconinja> thanx <RX14> but I would like to be part of the editor-tools that is more simple lol
<FromGitter> <branconinja> thank you for the tips
<FromGitter> <j8r> @girng you don't sleep much - stop crystal now!
Jenz has joined #crystal-lang
<RX14> @branconinja the editor tools stuff isn't official
<RX14> you'll have to ping someone who does that stuff
<oprypin> branconinja, you can contribute to anything you want without being part of an organization on paper
<FromGitter> <branconinja> ok
Jenz has quit [Quit: Mutter: www.mutterirc.com]
faustinoaq has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <j8r> @branconinja be apart of an organization isn't just to belonging to it, in the first place this is to have more rights on the repositories, to do more extensive work
faustinoaq has quit [Quit: IRC client terminated!]
<oprypin> right
<FromGitter> <j8r> There is no point to be granted of rights that we won't use (properly)
<FromGitter> <j8r> But don't worry @branconinja , you are Brazilian right? I'm pretty sure you can have your chance in https://github.com/CrystalBR if you ask to @hugoabonizio :-D
faustinoaq has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 264 seconds]
Raimondii is now known as Raimondi
sz0 has joined #crystal-lang
Nathanaelle has quit [Ping timeout: 265 seconds]
<FromGitter> <j8r> How can I do this work `File.basename File.read("/proc/1/cmdline")`? Exception: `String contains null byte (ArgumentError)`
<FromGitter> <j8r> there is a method to check null byte for `String`, but how remove them?
<FromGitter> <bew> whaat are you doing? why are your trying to do basename on sth that's not a file path
<oprypin> j8r, this is what i would do https://carc.in/#/r/3ypv
<FromGitter> <j8r> This should be a path, other PIDs are fine but the PID 1 (here `/sbin/init`) behave differently
<oprypin> j8r, i dont see why you say it behaves differently
<FromGitter> <j8r> me too, you can try on you Linuxes but mine I have this issue
<FromGitter> <j8r> If I try on an other PID, no problem
<oprypin> j8r, i dont see any issue, everything is according to specifications
<FromGitter> <j8r> hum ok that's normal for null bytes
<FromGitter> <j8r> so the issue is (indeed) on the crystal side, how can I handle them?
<oprypin> what are you even talking about
<FromGitter> <j8r> String separated by null bytes
<oprypin> the issue is only in your code. i have provided you code for parsing /proc/. i can be more specific if you specify yopur problem
<FromGitter> <j8r> removing this annoying null byte
<FromGitter> <j8r> but I've found a way (without regexes): `.rchop '\0'` do the trick
<FromGitter> <j8r> or `split '\0'`
<oprypin> that is generally incorrect
<FromGitter> <j8r> I replace null bytes by spaces
<oprypin> that is generally incorrect
<oprypin> j8r, I believe this will be the most correct and efficient way: https://carc.in/#/r/3ypy
<FromGitter> <j8r> nice @oprypin !
<FromGitter> <j8r> I'm crying, there are processes that have such a mess of characters
<FromGitter> <j8r> for example Chromium en Firefox with their sub processes
<FromGitter> <j8r> `File.read("/proc/1/cmdline").gsub('\0', ' ')` do also the job
<FromGitter> <j8r> Thanks! Maybe I need to find another way to avoid this mess
<oprypin> i don't understand what you're trying to achieve with these spaces
<FromGitter> <j8r> to be printable, like do Gnome System Monitor or qps
<crystal-gh> [crystal] asterite closed pull request #3622: Accept to pass compiler options to crystal docs (master...feature/crystal-docs-accepts-compiler-option) https://git.io/v1np2
<oprypin> what if i call my process "cool program"
<oprypin> and you'll just get "cool"
<FromGitter> <j8r> no, the goal is to get the basename of the path
<FromGitter> <j8r> let me show you , sec
<oprypin> please use the provided code, only it can discern an empty file from a fine with an empty arg
<FromGitter> <bew> like that? https://carc.in/#/r/3yq9
<FromGitter> <j8r> https://imgur.com/a/pkhRwkL
<FromGitter> <j8r> look at the firefox cmdline. I will don't `File.basename`d it
<oprypin> bew, the problem it solved at my latest link
<oprypin> is*
<crystal-gh> [crystal] asterite closed pull request #3634: [WIP] Add ASM.JS/Emscripten Target (master...asmjs) https://git.io/v1WbV
<FromGitter> <bew> more like this then? https://carc.in/#/r/3yqb
rohitpaulk has quit [Ping timeout: 260 seconds]
<FromGitter> <j8r> @bew this works :-o
<FromGitter> <bew> just be careful with the `not_nil!`s
<oprypin> why do i even try
<crystal-gh> [crystal] asterite closed pull request #3794: Move Array#product to Enumerable (master...master) https://git.io/vMTcK
<oprypin> you have the list of args, just basename the first one