<FromGitter>
<girng> reason i ask is because some characters don't have any items equipped, and i don't want to send the equipped key with the namedtuple over the network
<FromGitter>
<bew> Don't use NamedTuple that way, use a struct (it's roughly the same thing memory and performance wise, and it's more flexible
<FromGitter>
<bew> Or even a class, I don't you should try to over optimize things that way
<FromGitter>
<bew> Don't *think
<FromGitter>
<girng> ok. i'll just send over the key "equipped", i worry about bandwidth/optimize things l8er
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
<FromGitter>
<girng> how can i create my own type
<FromGitter>
<girng> i am getting really annoying writing Hash(String, Int32) all over the place
<FromGitter>
<bew> Alias?
<FromGitter>
<girng> ty
<FromGitter>
<bew> And what do you mean by "all over the place"?
<FromGitter>
<girng> i will create alias of "EQ_TYPE"
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
DTZUZO has quit [Ping timeout: 240 seconds]
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.]
illy_ 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 [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
DTZUZO 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
That_Guy_Anon has joined #crystal-lang
<FromGitter>
<bararchy> @girng alias MyType = Hash....
<FromGitter>
<bararchy> It helps for long type name
<FromGitter>
<girng> im going to make a headers.cr file (similar to headers.h) in c++
<FromGitter>
<girng> put ALL MY types n stuff in there
<FromGitter>
<girng> aliases, etc
<FromGitter>
<schoening> Just so I am sure I understood this once and for all: ⏎ if @a.is_a?(String) cannot be guranteed because it is a getter and I could have some weird getter that returns a string on first call and then only numbers. Thats the idea right? And if (a = @a).is_a?(String) is, as a value ok since it no longer is a getter. Correct?
That_Guy_Anon has quit [Ping timeout: 240 seconds]
<FromGitter>
<bararchy> Basically `@a` is an instance var, which means it can be changes anywhere in the class
qard has quit [Ping timeout: 256 seconds]
<FromGitter>
<bew> @schoening note: `@a` is not a method call (a getter), but the logic is the same as what you explained
<oprypin>
schoening, no, this is not a getter, just an instance variable. this is a precaution against a different execution thread possibly changing the value in the background
<oprypin>
local variables don't get shared between threads
rohitpaulk has joined #crystal-lang
That_Guy_Anon has joined #crystal-lang
alex`` has joined #crystal-lang
alex`` has quit [Ping timeout: 246 seconds]
<FromGitter>
<bararchy> @girng looking at the code you posted, I would create a Account or User class with all relevant data in it, it seems too complex to be a Tuple (in the sense it's hard to manage this way, and hard to scale up if needed)
That_Guy_Anon has quit [Ping timeout: 276 seconds]
That_Guy_Anon has joined #crystal-lang
That_Guy_Anon has quit [Client Quit]
<FromGitter>
<bararchy> not sure why but working in Crystal make you susceptible to Hash\Tuple abuse, I've seen many people do this instead of using Class\Struct (even me)
<FromGitter>
<codem4ster> and another thing; if this is a rule, why the local variables behave different than instance variables? This is very confusing.
<FromGitter>
<epergo> I think it doesn't work because the compiler doesn't really know if between the check and the actual split has been another method call or whatever that changed the instance variable some_string to nil
<FromGitter>
<epergo> if you extract the value to an auxiliary variable and do the condition on it, works
<FromGitter>
<bararchy> @codem4ster If you look 4-5 lines above your original question you would see the answer to your question :) ⏎ for the sake of pushing the nail even further ⏎ ⏎ `@var` means an instance variable ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5ad6f94c109bb04332d42264]
<FromGitter>
<codem4ster> This is easier I think; ⏎ ⏎ ```@some_string.as(String).split if @some_string``` ⏎ ⏎ But that is not the case. Crystal has concurrency not parallelism, it has Fibers not Threads, it uses a scheduler. So this 'if' line is a blocking operation and there is no way to go through split and if even it was threaded. [https://gitter.im/crystal-lang/crystal?at=5ad6fab96d7e07082b07cde6]
<FromGitter>
<codem4ster> So there is no way to change the value of the @some_string between if and split.
<FromGitter>
<straight-shoota> Crystal doesn't actually support parallelism yet, but it is designed for it.
<FromGitter>
<straight-shoota> So yes, it probably won't be a problem with the current state of concurrency. But it wouldn't be such a great idea if the language needed to be changed once parallelism arrives, would it?
<FromGitter>
<ezrast> Even without parallelism, the type of `@some_string` would still only be guaranteed up until the first method call inside the conditional body.
<FromGitter>
<straight-shoota> yes, your variable doesn't change it's type
<FromGitter>
<codem4ster> so?
<FromGitter>
<straight-shoota> it can never be nil or a different type than Int32
<FromGitter>
<straight-shoota> just replace `i -= 1` with `i = nil` and you'll se the compiler taking care
<FromGitter>
<codem4ster> yes I'm already saying that. Compiler can take care local variables even if they're shared between fibers.
<FromGitter>
<straight-shoota> exactly
<FromGitter>
<codem4ster> then why it cannot take care of instance variables in the same situation?
<FromGitter>
<straight-shoota> because it can't track them
<FromGitter>
<codem4ster> why it can't track them?
<FromGitter>
<codem4ster> :)
<FromGitter>
<codem4ster> because shared? local variables are shared also. But it can track them.
<FromGitter>
<bararchy> @codem4ster local vars arent shared between threads
<FromGitter>
<bararchy> when there will be threads
<livcd>
many of you came from Ruby. What made you to try Crystal and why did you "abandon" ruby ?
<FromGitter>
<bararchy> it's the assumption of the compiler that he would be able to take care of it
<FromGitter>
<codem4ster> oh now I got it
<FromGitter>
<codem4ster> they're shared on fibers not threads
<FromGitter>
<codem4ster> although crystal not support threads this design is choosen for the future
<FromGitter>
<bararchy> exactly ^
<FromGitter>
<straight-shoota> even without threads, instance variables belong to objects and they could be modified by different code the Compiler might not even know about (like C bindings)
<FromGitter>
<bararchy> livcd basiclly speed, and after starting it became 'safety' and then speed
<FromGitter>
<bararchy> which is a very anti-pattern for Ruby
<FromGitter>
<bararchy> Ruby pushes you to forget about types and handle everything with Exceptions
<FromGitter>
<bararchy> I actually saw code people made that instead of `if-else` they totally used Exception handeling to control program flow
<livcd>
I am curious how many of you will go back to Ruby when GraalVM+TruffleRuby is ready
<FromGitter>
<straight-shoota> no way
<FromGitter>
<straight-shoota> Crystal as a language is so much superior to ruby
<FromGitter>
<straight-shoota> static typing with global inference is really nice, union types are awesome, the concurrency model etc.
<FromGitter>
<straight-shoota> there are soo many bugs you can't even have in Crystal because the language and compiler prevents them
<FromGitter>
<yxhuvud> aye. I came for the performance but stayed for the language
<FromGitter>
<yxhuvud> and that if statement could read `if a` without checking type if the point is only to remove the nil type, which very much matches how ruby would do it.
<FromGitter>
<girng> @bararchy thanks for suggestion. i like my inline namedtuples, makes it feel more like javascript object literals (from what i'm so used to)
<FromGitter>
<girng> but im sure if it gets too advanced i will need re-organize
<FromGitter>
<girng> @livcd im not sure, unless there are performance advantages, and if there is a crystal converter, then i'll try it but if not, im not going to
<FromGitter>
<girng> im not going to convert all my codebase over, seems waste of time. but those truffle people are nice people i posted on their github and received help in an issue thread. they are good people
<FromGitter>
<girng> is there a table printing console method/functionality built in crystal?
<FromGitter>
<girng> Much easier to read now :D :D :D
<FromGitter>
<epergo> yeah! it's a nice little shard
<FromGitter>
<girng> is it possible to just update the table instead of submitting a new "puts" each time?
<FromGitter>
<bararchy> @girng you can try `print table\r`
<FromGitter>
<bararchy> which should rewrite over the same line
<FromGitter>
<bararchy> but it might not work if the table uses `\n`
<FromGitter>
<bararchy> which I guess it does
<FromGitter>
<bararchy> so..no. ⏎ or use ncurses etc..
<FromGitter>
<girng> ic
<FromGitter>
<girng> for my game server manager, i was thinking maybe i could execute a .exe each time i restart my crystal server (for dev purposes), which would open up the .exe server manager written in godot, then i could just send these values over a stream to it and have it update in the godot engine
<FromGitter>
<girng> when i say "restart my crystal server" i mean re-running `crystal src/App.cr`
<FromGitter>
<girng> so, through code i could get it to launch a file automatically, and terminate that process when the app restarts. would be really cool
<FromGitter>
<bararchy> as means cast, .to_i32 means convert ⏎ ⏎ "1".as Int32 will never work, those are different types that canoot be casted ⏎ "1".to_i32 uses a convertion table to replace the var from `1:String` to `1:Int32` [https://gitter.im/crystal-lang/crystal?at=5ad72000270d7d3708dcb2b3]
<FromGitter>
<girng> so if it's a JSON::Any, i just need to cast it?
<FromGitter>
<girng> that means as_i, since no conversion wil take place (since it's already a JSON::Any)?
<FromGitter>
<bararchy> JSON::Any is a union type of all posibble types a json can handle. ⏎ you can `{"foo": 1}.to_i32` right? but JSON::Any mioght be exactly that
<FromGitter>
<bararchy> can=can't
<FromGitter>
<girng> okay, so thinking of UNION Types think as_i
<FromGitter>
<bararchy> I think JSON::Any has some way to "know?" or something thous it support `.to_h` or `.to_a` etc.. ⏎ but now I'm just gueeing
<FromGitter>
<bararchy> you should look at the source for that
<FromGitter>
<girng> "union type of all possible types" = as_i, makes sense now
<FromGitter>
<girng> ty Bar
<FromGitter>
<bararchy> np :)
<FromGitter>
<girng> i ask kinda weird questions. but it's bcz i hate just putting it into my code and thinking "oh, okay this works". but i like to understand "why it works"
<FromGitter>
<girng> i do a lot of trial and error lol
<FromGitter>
<bararchy> @girng only way to learn :)
<FromGitter>
<girng> slow and steady :D
<FromGitter>
<girng> when you are in a case when clause statement. and if a method "returns" something, is there a way to detect that?
<FromGitter>
<girng> i guess i could just use `raise`
Jenz has joined #crystal-lang
<Jenz>
Good day people, how is Crystal doing?
<FromGitter>
<girng> goo morning!
<Jenz>
Im in a superb mood, I installed arch so I could run gdb on crystal programs (even though barely anything works)
<Jenz>
That was not the only reason though, lol
<FromGitter>
<girng> nice, im on WSL
<FromGitter>
<girng> although i tried crystal on lubuntu it's very nice
<Jenz>
I was on macOS before, yikes, glad I left it
<Jenz>
Do not get me wron though, macOS is nice, just not for me I guess
<Jenz>
*wrong
<FromGitter>
<girng> @jenz i'd crystal is doing very well i joined two weeks and beeen asking questions in this chat 24/7
<FromGitter>
<girng> and i always receive help, and on the crystal subeddit
<FromGitter>
<girng> subreddit*
<Jenz>
Yeah, the crystal community is great :D, Ive been here for maybe two months or something (I have no control of time, might be twice as much), it quickly became my favorite lang
<FromGitter>
<girng> =]
<FromGitter>
<sdogruyol> welcome to Arch @Jenz
<FromGitter>
<sdogruyol> I've also dropped OS X and switched back to Linux
<Jenz>
Thanks! Are you on a macbook?
<Jenz>
And congratulations on getting into the core team, Kemal is awesome
<Jenz>
Loads of awesome people here ^^
alex`` has quit [Ping timeout: 240 seconds]
<FromGitter>
<sdogruyol> thank you Jenz
<FromGitter>
<sdogruyol> nope, I'm not on a Macbook
<wuehlmaus>
carc.in is quite usus, i just thought that it was in critter automatically :)
<wuehlmaus>
thanks for the links
<oprypin>
uh what
<wuehlmaus>
ah, gitter, sorry for confusing, i meant gitter.im
Jenz has joined #crystal-lang
<FromGitter>
<sam0x17> well friends I have successfully got the crystal *compiler* to build stuff in a google cloud function by including pre-compiled versions of pcre and libevent. working on a shard that automatically "bootstraps" a crystal app/library by uploading it to a cloud function that does the compilation and then deploys the compiled binary to its own cloud function. This is instead of the existing approach I use whereby I
<FromGitter>
... simply upload a --static compiled binary from my machine.
<FromGitter>
<straight-shoota> well, `--static` tells the linker to use static libraries if available.
<FromGitter>
<straight-shoota> so you don't need to have the libraries installed on the target system as they're included in the binary
<FromGitter>
<sam0x17> i.e. more portable, but bigger binary
* Jenz
gets it
<FromGitter>
<sam0x17> but yeah, when it's done my shard will create a zip of the current crystal app, upload it to the compile-crystal cloud function, which downloads the specified version of the crystal compiler (or default to the latest release) , compiles the app, and then deploys it as its own cloud function with the specified options and name
<FromGitter>
<sam0x17> second part is fully working, just stubbing the uploading of the zip right now
rohitpaulk has joined #crystal-lang
Jenz has quit [Quit: Lost terminal]
Jenz has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 264 seconds]
<FromGitter>
<girng> back, good morning
<FromGitter>
<girng> @sdogruyol upvoted
baweaver is now known as baweaver_away
baweaver_away is now known as baweaver
Jenz has quit [Remote host closed the connection]
Jenz has joined #crystal-lang
Jenz has quit [Disconnected by services]
<FromGitter>
<j8r> @Jenz not sure if it's my distribution or missing libraries, so i prefer to use Alpine
<FromGitter>
<girng> so if i do as_h from my json text, it's now creating all these types for it `(Array(JSON::Type) | Bool | Float64 | Hash(String, JSON::Type) | Int64 | String | Nil)`
<FromGitter>
<girng> that doesn't seem efficient.. what am i doing wrong
<FromGitter>
<girng> why so many 64 bit gosh damn i just want a string
<oprypin>
see JSON.mapping
<oprypin>
also note that all this .as_h code breaks in the next version of Crystal
<FromGitter>
<girng> .....
<FromGitter>
<j8r> @oprypin as_h will broke?!
<oprypin>
i thought it was already released so didnt think much of it
<FromGitter>
<girng> but how do you do JSON.mapping on data that you don't KNOW
<oprypin>
.as_h itsellf will work but it will give a result that needs to be dealt with differently
<FromGitter>
<girng> what the types/keys are going to be sent...
<FromGitter>
<girng> from the client...
<oprypin>
girng, you just said {"bio", "location", "gender"} - so you know
<FromGitter>
<girng> hacker could easily use wireshark and modify and send diff keys though
<FromGitter>
<girng> and try to crash server
<oprypin>
catch exception
<FromGitter>
<j8r> exactly
<FromGitter>
<girng> yes my methods are in a begin raise
<FromGitter>
<girng> always will be a json string from godot
<FromGitter>
<j8r> if you now what to expect, pls use a mapping
<FromGitter>
<girng> for example, from the client i send: ` {"cmd":"LOGIN","message":{"password":"mike","username":"Test"}}`
<FromGitter>
<girng> it's always gonna be a string over tcp
<FromGitter>
<girng> now, if a user saves a profile, i send ` {"cmd":"SAVEPROFILE","message":{"bio":"test","gender":"","location":""}}`
<oprypin>
cool cool
<FromGitter>
<girng> so iuno how to put all this data in a "struct" or use json mapping for it. it's just 1 string that gets parsed
<FromGitter>
<girng> think of nodejs's JSON.parse(), is how i'm viewing it
<FromGitter>
<girng> is my perspective on how it's working (cause i'm so used to it)
<oprypin>
cant vouch for performance of this with a large number of commands, but https://carc.in/#/r/3wbm
<oprypin>
probably not such a good idea
<FromGitter>
<girng> ohh i see
<FromGitter>
<girng> so i can define all those in my headers.cr file?
<FromGitter>
<girng> that will make it much more static
<oprypin>
i guess
<FromGitter>
<girng> bcz i have a lot of code i need a separate file for the structs then, which is fine
greengriminal has joined #crystal-lang
<FromGitter>
<girng> but that is surely better than json::any right?
<oprypin>
surely
<FromGitter>
<girng> json::any is a TRAP
<FromGitter>
<girng> thank you oprypin, this helps a lot
<FromGitter>
<girng> this feels more like i'm using a statically typed language now, of which i like
<FromGitter>
<girng> the more stuff i define, better i feel about my code
<FromGitter>
<girng> explicitly define*
greengriminal has quit [Quit: Leaving]
<FromGitter>
<girng> @oprypin i have currently 32 commands. using the | operator will be ok with that many times?
<oprypin>
nah, hold on
<FromGitter>
<schoening> Are macros one of those things that once you "get" them you love them? At a glance I am reminded of what people say about lisp programmers only being able to use their own code coz they all created their own dsl :p
<z64>
ary's talk on macros is excellent, i definitely recommend watching it (can't grab a link myself right now..)
<oprypin>
girng, you can do that as well, it's just MUCH more efficient to select on a number than it is to go through all strings
<oprypin>
normally i wouldn't tell you to bother with this but this code for selection of command will be run the most by far, so it's worth optimizing
<FromGitter>
<girng> yeah, your enum / struct way is better, in fact it's probably way better
<FromGitter>
<girng> well you said debug, but why do i need escaped "'s to help me debug the string lol
<oprypin>
what if someone sends you just a hundred newlines as part of the string and you print it. what will be easier to understand -- a blank screen or "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
<FromGitter>
<girng> well, in that case yeah
<FromGitter>
<fridgerator> @girng have you ever used unity 3d? just curious on your thoughts of godot vs unity
<FromGitter>
<girng> but why is crystal escape the quotes in any event, is that part of read_string(bytesize)?
<FromGitter>
<girng> replacing new lines with \n is useful for debugging, but escaping quotes i don't understand how that is useful, because godot isn't sending that
<FromGitter>
<girng> in your example, godot is sending new lines...
<FromGitter>
<girng> that would be useful to see the \n's then
<FromGitter>
<girng> @fridgerator well, i'll keep it short and sweet: Godot for 2d, Unity for 3d
<FromGitter>
<girng> @fridgerator however, for app development, Godot is much better than your html crap packaged w/ electron. Godot's UI tools are insane and underrated because no one thinks you can create ui stuff because it's a "game engine" however they are wrong
<oprypin>
girng, do you not see that i literally put the string in the middle of my program and it works?
<FromGitter>
<girng> @oprypin i don't understand that code tbh too advanced of a macro for me :P
<oprypin>
dont look at the link
That_Guy_Anon has quit [Read error: Connection reset by peer]
<FromGitter>
<girng> @oprypin ok, on sec let me show u something
<FromGitter>
<drum445> Hello team, could somebody please let me know whether this is something I need to worry about on my API: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ It happens when a client connects and disconnects quickly, such as multiple page refreshes [https://gitter.im/crystal-lang/crystal?at=5ad7b0746d7e07082b0ba1ca]
<oprypin>
you need escaping to produce strings in source code
<FromGitter>
<girng> o
<oprypin>
there is no such escaping happens in the actual string, it's just a way to represent it in source code
<FromGitter>
<girng> ohhhh i see
<oprypin>
and `p` just happens to produce the escaped output because it's convenient. the actual string is not like that
<FromGitter>
<girng> that's for all languages mostly?
<FromGitter>
<girng> or just crystal specific
<oprypin>
the actual string is what you see when you use `puts` but it's not always convenient to use `puts`
<oprypin>
all languages have it
<FromGitter>
<girng> well, your \n example is actually good because i do need to check for new lines and if i use p i can see them
<oprypin>
not all but most
<FromGitter>
<girng> so basically, source code (internally) needs to escape them. so actually, raw_message is literally the raw_message, if i do `p raw_message`
<FromGitter>
<girng> raw source code message
<FromGitter>
<j8r> there is also `pp`, usefull to debug async/long tasks
<oprypin>
girng, no, it is not internally stored like that
<FromGitter>
<girng> WTF
<oprypin>
when you put an escaped string in source code, the compiler reads it once and stores it as a proper string
<oprypin>
and `p` converts a normal string to a source-like representation just for you to see it that way
<oprypin>
drum445, seems normal
<oprypin>
it's good that it doesnt let the error go undetected, isnt it?
<FromGitter>
<drum445> There are a fair amount of them that stack up over time, nothing I need to concern myself with you reckon? It doesn't seem to affect performance or even stop the response
<oprypin>
drum445, you shouldn't leave unhandled exceptions
<oprypin>
i always argue that these should crash the entire program
<FromGitter>
<drum445> I don't know how to catch those though matey :(
<FromGitter>
<drum445> I would appreciate some advice
<FromGitter>
<girng> "when you put an escaped string in source code" .................... i give up. I NEVER did this, godot is sending it from the client w/o escapes. yes, i understand p converts it to display, but i never "put an escaped string in the source code" willfully. ⏎ ⏎ so you're telling me it gets converted/escaped automatically regardless if i send something that is escaped or not? then, the `p` re-converts it so i
<FromGitter>
... can see it as it was when it first got entered into the source code?
<FromGitter>
<drum445> I get that, but thanks mate. I'm not sure where in my code to put the catch
<FromGitter>
<girng> converted into source code*
<FromGitter>
<drum445> Mind if I send you a sample?
<oprypin>
girng, imagine you were doing a test, where you don't want to care about what godot does
<FromGitter>
<drum445> do you know where it would go in that file matey?
<oprypin>
girng, no, internally they're just your normal text
<FromGitter>
<drum445> not even sure how to write it tbh 😢
<oprypin>
drum445, no, there's nowhere in that file that you could put it. it's on kemal
<FromGitter>
<drum445> you don't like Kemal?
<oprypin>
i've seen a few worrying things about it, yeah. but i dont have enough experience to recommend either it or anything else
<oprypin>
i mean i have general experience but never cared abotu web frameworks
<FromGitter>
<drum445> fair enough, I'm quite a fan of it atm. Either way any ideas how to catch the error?
<oprypin>
drum445, just ignore it, it's ok. if it ever becomes a problem in future versions of the language, kemal can be changed to handle it
<oprypin>
drum445, i sure prefer kemal over amber :p
<FromGitter>
<drum445> Ha yeah same mate, I'll ignore it for now. Thanks a lot for your help bud
<FromGitter>
<girng> "source-like representation just for you to see it that way" = this implies that the source code has to escape it? if it's "source-like" ⏎ ⏎ but now you said "internally they're just your normal text". then what is the reason for a source-like representation if internally they are normal text.
<FromGitter>
<girng> only use-case i can see is the \n issue, which is good to see. but escaped strings is silly makes no sense to escape them because it doesn't help the debugging process at all. in fact, it makes it harder because i just spent 10 minutes wondering why the hell godot was sending escapes strings. then i realized i was using p instead of puts
<crystal-gh>
[crystal] Sija opened pull request #5962: Expand Regex to allow querying for metacharacters (master...regex-special-char) https://git.io/vpIjw
<crystal-gh>
[crystal] Sija opened pull request #5963: Use Char instead of String in split/join calls whenever possible (master...followup-to-pr-5882) https://git.io/vpLvn
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]