<Svenskunganka>
Oh thank you! I knew I saw it somewhere, was looking through the API docs and couldn't seem to find it.
dhk has quit [Quit: Leaving]
<FromGitter>
<mverzilli> np!
msg has joined #crystal-lang
msg is now known as Guest679
Guest679 has quit [Ping timeout: 240 seconds]
sz0 has joined #crystal-lang
squeaky_pl has quit [Remote host closed the connection]
squeaky_pl has joined #crystal-lang
Svenskunganka has quit [Ping timeout: 268 seconds]
Svenskunganka has joined #crystal-lang
msg has joined #crystal-lang
msg is now known as Guest98842
Svenskunganka has quit [Ping timeout: 240 seconds]
Guest98842 has quit [Ping timeout: 240 seconds]
squeaky_pl has quit [Remote host closed the connection]
squeaky_pl has joined #crystal-lang
madgoat has joined #crystal-lang
madgoat has left #crystal-lang [#crystal-lang]
squeaky_pl has quit [Ping timeout: 260 seconds]
msg has joined #crystal-lang
msg is now known as Guest62674
Guest62674 has quit [Ping timeout: 260 seconds]
schoening has joined #crystal-lang
<schoening>
Is exception checking code always "slow" or just when it raises an exception? I have to check for "broken pipe" errors before sending to a websocket every 50milliseconds https://hastebin.com/womisutipo.cr
Raimondi has quit [Ping timeout: 268 seconds]
<FromGitter>
<mverzilli> I don't know! maybe you could write a couple of test scripts, one that always raises and one that doesn't. then benchmark
schoening has quit [Ping timeout: 260 seconds]
akwiatkowski has joined #crystal-lang
<FromGitter>
<dreyks> in general (in other languages, including Ruby) exceptions are only slow if they raise. this is because of the stack unwinding to form stacktrace, so one would expect mostly the same for crystal. but as Martin said, you should test
Qchmqs has joined #crystal-lang
msg has joined #crystal-lang
msg is now known as Guest54550
schoening has joined #crystal-lang
bjz has joined #crystal-lang
Svenskunganka has joined #crystal-lang
Svenskunganka has quit [Ping timeout: 240 seconds]
akwiatkowski has quit [Ping timeout: 260 seconds]
akwiatkowski has joined #crystal-lang
<schoening>
Hash vs NamedTuple? When to pick what
<FromGitter>
<crisward> I'm pretty sure NamedTuple's are immutable.
Svenskunganka has joined #crystal-lang
<schoening>
Yeah, I think they are. Okay. So is that the difference? If I need a mutable vs immutable structure?
Guest54550 has quit [Remote host closed the connection]
msg has joined #crystal-lang
msg is now known as Guest71802
Guest71802 has quit [Remote host closed the connection]
<Svenskunganka>
Is there anything in the stdlib that allows you to work with .tar.gz files? Zlib::Inflate.gzip for decompression, but how about the tar format?
<Svenskunganka>
And is there a clean way to avoid callback hell? Right now I have blocks for this kind of "pipeline": HTTP::Client.get -> ZLib::Inflate.gzip -> (tar?) -> File.open
<FromGitter>
<ezrast> @schoening That is one difference. Also, NumedTuples require their keys to be Symbols whereas Hash supports any hashable type; but NamedTuples can be expanded into keyword arguments with `**`.
<FromGitter>
<crisward> @ezrast That's interesting I didn't know that.
<schoening>
@ezrast Thanks, uhm, what does that mean "expanded into keyword arguments"
akwiatkowski has quit [Read error: Connection reset by peer]
akwiatkowski has joined #crystal-lang
mark_66 has joined #crystal-lang
gloscombe has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
msg has joined #crystal-lang
msg is now known as Guest53532
<schoening>
Hehe.. "Hash" for too unspecific for an Array type. Okay. I just turn the Hash into a string then xP
<FromGitter>
<sdogruyol> try to avoid so much inlined data structures
<FromGitter>
<sdogruyol> Array(Hash(String,String) maybe what you looking for though
<FromGitter>
<sdogruyol> it's an array of hash with string keys and string values
Svenskunganka has quit [Ping timeout: 255 seconds]
<FromGitter>
<chyzwar> Hi,
<FromGitter>
<sdogruyol> Hey
<schoening>
@sdogryol Thanks for the Type! Please tell me why to avoid "inlined data structures" I don't really understand what that means.
<FromGitter>
<sdogruyol> it's easy to get lost
<FromGitter>
<sdogruyol> depends on the context though
Vallkury[m] has left #crystal-lang ["Kicked by @appservice-irc:matrix.org"]
kodotest[m] has left #crystal-lang ["Kicked by @appservice-irc:matrix.org"]
<schoening>
I think I don't understand what "inlined data structures" means.. I try to keep everything simple. But I am making a game and need to send map information to the clients ^^
Philpax_ has joined #crystal-lang
<FromGitter>
<sdogruyol> oh
<FromGitter>
<sdogruyol> okay i got it now yeah games are an exception :P
<schoening>
Porting over my code from Node.js. Its so much fun working in Crystal so far hehe
<schoening>
Haha! xD
<FromGitter>
<sdogruyol> yeah once it's compiled there's no looking back :)
Philpax has quit [Ping timeout: 240 seconds]
<schoening>
Yes.. that is a bit annoying. I dunno if its because I am using an ancient refurbished thinkpad or that it just takes time to compile. Probably a mix
<schoening>
But I do like types. I come from JavaScript and PHP background. It's nice to see an error before running the program :p
<FromGitter>
<sdogruyol> currently Crystal 0.20.5 has a bug thus leading to slower compile times
Svenskunganka has joined #crystal-lang
<schoening>
Ahh
<FromGitter>
<sdogruyol> it's gonna be fixed in next release which is hopefull today :tada:
<schoening>
:D
<schoening>
I guess it's good that my game is a hobby project. Are there gonna be big syntax changes in the future?
<FromGitter>
<sdogruyol> nope
<FromGitter>
<sdogruyol> i can say that the syntax is pretty stable for the last year
<schoening>
Sweet
<FromGitter>
<sdogruyol> i'm building and maintaining Kemal for more than 1 year and it's been easy to maintain
<schoening>
OMG
<schoening>
Perfect
<schoening>
coz I just ran into an issue with it and am google about Kemal haha
<FromGitter>
<sdogruyol> not many breaking changes
<FromGitter>
<sdogruyol> you can ask me here
<schoening>
I am using ws and I am trying to pass the |socket| as an argument to my class and it wants to know what type that socket is.. where do I find the type names?
<schoening>
Maybe I should show an example..
<FromGitter>
<sdogruyol> ah i see what you mean
Svenskunganka has quit [Ping timeout: 240 seconds]
<FromGitter>
<sdogruyol> it's a nice question
<FromGitter>
<sdogruyol> the type is `HTTP::WebSocket`
<FromGitter>
<schoening> That red dot is the player haha! Well then. Now things are gonna get interesting ^^
<FromGitter>
<sdogruyol> imgur is blocked in my country
<FromGitter>
<sdogruyol> :(
<FromGitter>
<schoening> Oh damn. Why o_o
<FromGitter>
<sdogruyol> IDK
<FromGitter>
<schoening> Well. It's just a grid anyways. I wont be able to resist posting about it eventually again :p
<FromGitter>
<sdogruyol> it's still something :)
<FromGitter>
<rishavs> anyway to diable the git checking/updating on every shard build? I just want it to build my src and throw it in the bin. :D
<FromGitter>
<schoening> Yeah ^^
<FromGitter>
<sdogruyol> @rishavs don't use shard build and use ```crystal build src/your_app.cr -o bin/app``` instead
<FromGitter>
<schoening> Only problem I have now is that I was relying on a very nice astar pathfinding library written in JavaScript. I guess it is time to finally learn how to do that on my own.. and implement it in Crystal. And OpenSource it. Unless I find one.
<FromGitter>
<sdogruyol> i dont know what's astar pathfinding
<FromGitter>
<rishavs> thanks!
<FromGitter>
<rishavs> a star is one of the fastest pathfinding methods used in games. if u have a grid, it will tell you the shortest paths between two points
<FromGitter>
<rishavs> :D
<FromGitter>
<schoening> @sdogruyol When you have a grid it finds the shortest path to your destination.
<FromGitter>
<schoening> Ya ^
<FromGitter>
<schoening> Well, I didn't find it on crystalshards. Time to learn :D
Svenskunganka has joined #crystal-lang
<FromGitter>
<rishavs> well, if you want to do it yourself, Amit's blog's got you
<FromGitter>
<rishavs> the sameness between ruby/crystal is such a huge boon to beginners like me
<FromGitter>
<schoening> That wold be nice @sdogruyol :P I don't wanna spam you with questions. I don't know Ruby so some obvious stuff isnt that obvi to me
<FromGitter>
<sdogruyol> that Ruby script seems pretty easy
<FromGitter>
<schoening> ;_; must be nice to know ruby..
<FromGitter>
<sdogruyol> it helps :P
<FromGitter>
<rishavs> psst... i dont either! i cam from lua land
<FromGitter>
<rishavs> love2d is my posion of choice
<FromGitter>
<rishavs> :D
<FromGitter>
<sdogruyol> Ruby has a lot of lua-isms
Svenskunganka has quit [Ping timeout: 240 seconds]
<FromGitter>
<schoening> Ohh but how do you deal with all these 0 indexed arrays :p
<FromGitter>
<schoening> Add myself to the list @sdogruyol ? You mean like when I launch my game?
<FromGitter>
<sdogruyol> @schoening whenever you want
gloscombe has quit [Ping timeout: 260 seconds]
gloscombe has joined #crystal-lang
Svenskunganka has joined #crystal-lang
Svenskunganka has quit [Ping timeout: 240 seconds]
bjz_ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
gloscombe has quit [Ping timeout: 260 seconds]
gloscombe has joined #crystal-lang
rafadc has joined #crystal-lang
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: https://git.io/vDdyJ
<crystal-gh>
crystal/master bdc81db Ary Borenszweig: String: remove `to_unsafe_slice` and keep `to_slice`, but make it return a read-only Slice....
Guest53532 has quit [Remote host closed the connection]
msg has joined #crystal-lang
msg is now known as Guest83846
Guest83846 has quit [Remote host closed the connection]
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: https://git.io/vDFk6
<crystal-gh>
crystal/master 367e9de Karl Seguin: Add a explicit exception message when a nil capture group is accessed....
bew78 has joined #crystal-lang
<bew78>
I'm trying to fix #3936, so I need to add an 'abstract' argument. When I use this 'abstract' argument, the compiler gives me: can't use abstract inside def
Guest82534 has quit [Remote host closed the connection]
mounibec has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
rafadc has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
mounibec has joined #crystal-lang
mounibec has quit [Client Quit]
mounibec has joined #crystal-lang
<bew78>
What is the simplest way to remove the first char from a string ?
<Papierkorb>
bew78: Use #[] with a range of 1..-1: `the_string[1..-1]`
<Papierkorb>
bew78: That'll return a copy of 'the_string', not modify it
<bew78>
nice, thank you!
<Papierkorb>
cheers
<bew78>
and is there a way to modify it ?
<bew78>
like in 'just drop the first char' ?
sz0 has joined #crystal-lang
<Papierkorb>
Strings are immutable, so not really
msg has joined #crystal-lang
msg is now known as Guest75214
<RX14>
soon to be lchop actually
<bew78>
RX14: will it use a pointer movement to be fully efficient or will it still create a copy ?
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
<RX14>
strings are immutable
<RX14>
every operation copies
<RX14>
every single one
<RX14>
well every modification
<RX14>
if you care that much about performance you should be using an Array(Char)
<RX14>
because strings are UTF-8
<RX14>
and if you care about 0-copy that much
<RX14>
UTF-8 isn't going to cut it
soveran has quit [Ping timeout: 240 seconds]
bmcginty_ has joined #crystal-lang
bmcginty has quit [Ping timeout: 240 seconds]
<FromGitter>
<rishavs> @fridgerator Thanks! that fixed it. Dunno where i originally copied the snippet from.
<FromGitter>
<fridgerator> :thumbsup:
mark_66 has quit [Remote host closed the connection]
<bew78>
thanks RX14 but I found my way around: I'm dealing with SockAddrUn path to handle abstract unix socket, so I used the unsafe pointer directly, before the creation of String object.. I'll push my PR soon, you'll see, maybe there is a better way..
mounibec has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<FromGitter>
<rishavs> @fridgerator if i want to send a time object to the db for a field like "last_read_at", what should i use? ⏎ ie. my schema has this line `field :last_read_at,???`. what should go there?
<FromGitter>
<rishavs> i want to capture the timestamp when the last time the item was viewed
soveran has joined #crystal-lang
A124 has quit [Read error: No route to host]
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: https://git.io/vDFVJ
Guest75214 has quit [Remote host closed the connection]
<FromGitter>
<fridgerator> @rishavs `Time` should work
msg has joined #crystal-lang
msg is now known as Guest48331
Guest48331 has quit [Remote host closed the connection]
A124 has joined #crystal-lang
bew78 has quit [Quit: WeeChat 1.7]
<FromGitter>
<rishavs> Thanks. If I want to send the time info in the data to be insrted into the db, shoud I send it using the Time struct? ⏎ ⏎ data = Post.new ⏎ data.title = env.params.body["post_title"] ⏎ data.content = env.params.body["post_content"] ... [https://gitter.im/crystal-lang/crystal?at=58ab339f21d548df2c3506ed]
<FromGitter>
<rishavs> thanks @fridgerator . it worked. Is this type specific to crecto? I didnt know crystal had it
<RX14>
close enough to a release to change the topic i guess :)
<FromGitter>
<sdogruyol> :+1:
<FromGitter>
<sdogruyol> @RX14 finally we'll have your multipart PR in STD, congrats mate :clap:
<RX14>
haha
<RX14>
it feels like a journey
<FromGitter>
<sdogruyol> ain't it :P
<FromGitter>
<sdogruyol> so you mentioned that it'll be faster than the current multipart shard, right?
<RX14>
uhh
<FromGitter>
<rishavs> are you guys talking about the unix socket?
<RX14>
no, multipart/* mime type support
<RX14>
especially multipart/form-data
fridgerator has joined #crystal-lang
<FromGitter>
<sdogruyol> yeah
msg has joined #crystal-lang
<RX14>
commonly used for HTML form responses @rishavs
<FromGitter>
<rishavs> ok. sry for interrupting, please continue. Pretty sure thats way beyond me for now -_-
akwiatkowski has joined #crystal-lang
<FromGitter>
<sdogruyol> thanks to @RX14 s great effort we finally have that :)
msg is now known as Guest73959
<FromGitter>
<sdogruyol> @rishavs for example Kemal uses multipart to handle file uplaods
<RX14>
hmm
<RX14>
can't remember why I said it would be faster
<RX14>
it's easier for sure
<RX14>
with the single object
<RX14>
oh, maybe the buffer sizes...
<FromGitter>
<rishavs> hmmm. i am happy for another release. :D. Hopefully i'll soon be able to understand a lot of stuff in here :p
fridgerator has quit [Client Quit]
mounibec has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter>
<sdogruyol> who knows maybe we'll have multi thread support for 0.22 :P
<Papierkorb>
Let's hope for data structures being able to cope with that
<Papierkorb>
Cluttering mutexes all around ain't nice
<FromGitter>
<sdogruyol> hopefully
rafadc has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<RX14>
i'd kinda like the default array/hash to be safe
<Papierkorb>
may be too expensive
<RX14>
yeah
<Yxhuvud>
Yeah well, data structures with mutexes pre-cluttered is also not nice (especially not for single threaded perforance). But a set of concurrency-aware data structures to go with the existing ones would be a good thing to do.
<Papierkorb>
and not that helpful, really
<RX14>
Papierkorb, why not helpful?
<Papierkorb>
if you change your @array, you probably need to change something else too, and thus create not a crash, but other interesting issues
<RX14>
of course we should have concurrent data structures
<Papierkorb>
yes, but in a helpful way
<RX14>
thing with crystal though is that using your array concurrently is capable of actually crashing your whole application
<RX14>
instead of for example java where you get a CME
<Papierkorb>
yes, still we need something smarter than clutter Array/Hash with mutexes
<FromGitter>
<sdogruyol> how Go does it?
<Yxhuvud>
TBH what I'd like to see is a light-wieght ownership system where a thread owns a piece of memory, but with good access to structures to bridge the gap and unsafe tools that allows us to build our own should we need to.
<Papierkorb>
Yes. Even in a multi-threaded application, only few structures will actually be shared among threads. Even marking these shared explicitly may not be too much of a hassle
<RX14>
I too would like to see that
<Papierkorb>
(However such mark would be set)
<RX14>
i would like to see a different malloc
<FromGitter>
<sdogruyol> why another malloc?
<RX14>
default malloc allocates from a pool per fiber
<FromGitter>
<sdogruyol> aint that good enough
<RX14>
sorry i meant that default malloc would allocate memory that's only writiable from the current fiber
<Yxhuvud>
if you have a common pool then you can't really avoid stop the world pauses altogether.
<RX14>
indeed
<RX14>
by having multiple pools we can (moslty) eliminate STW pauses
<FromGitter>
<sdogruyol> now that makes sense
<RX14>
obviously with applications with only 1 fiber thats not possible
<FromGitter>
<sdogruyol> does Go do this to achieve nearly seamless GC pauses?
<RX14>
no
<RX14>
their GC is terrible lol
<FromGitter>
<sdogruyol> they're getting really good improvements compared to previous releases
<RX14>
that "very low GC latency" comes at a massive CPU cost
<FromGitter>
<sdogruyol> how come it's terrible?
<RX14>
they're optimizing as if GC pause latency is the only metric
<RX14>
and it is not
<RX14>
it's a terrible GC for real performance
rafadc has joined #crystal-lang
<Yxhuvud>
erlang has an independent gc per thread, and I wonder if go doesn't have some part of that for their fibers, but for everything that is shared memory it really isn't possibly to partition it without any pauses.
<RX14>
a great GC for dick-measuring contests with devs
<FromGitter>
<sdogruyol> still it solves the pause problem in a "brute force" way
<FromGitter>
<sdogruyol> better than nothing IMHO
<RX14>
but the "pause problem" isn't a problem in 99% of applications
<Yxhuvud>
I did not claim that. FWIW though, some makers of modern garbage collectors are less dismissive. I can recommend the comments by Gile Tene in this thread (and in general): https://mail.google.com/mail/u/0/#label/mechanical+sympathy/159218c98921e822
<RX14>
i mean that is a pretty biased articlew
<RX14>
and go's GC has sold itself to developers really well
<Yxhuvud>
it is a great group in general, if a bit java focused.
<RX14>
i'm not saying we shouldn't optimize for latency of course
<RX14>
but I think creating a more advanced GC which takes a more balanced approach would be good
onec has quit []
<Yxhuvud>
I want that too, but think creating one takes a *hellovalot* of work, and that you can't prioritize all features at once. The priority to start off with should be dependent by primary use case, and optimizing for latency fits go very well. I wouldn't want it for a database.
<Yxhuvud>
What will be the primary use case for crystal that would decide what to focus on? Beats me.
rafadc has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<RX14>
anyway I think that having a heap per fiber would be helpful
<RX14>
it's somewhat like go's "request oriented gc"
<Yxhuvud>
Agreed, and that puts limits on how shared memory would work.
<RX14>
i would not at all be opposed to banning shared memory apart from using an explicit "shared" malloc
<RX14>
which a concurrent collection could use
<Yxhuvud>
well you could have a special heap for shared memory as well.
<RX14>
well yes, that would be the special malloc
<RX14>
but the special malloc would be about making it explicit
<RX14>
it makes you think about concurrency
<RX14>
and not accidentally mutate something concurrently which isn't designed for it
<Yxhuvud>
Having access to value types for intraprocess communication makes this so much simpler. I wonder how java avoided them for so long
fryguy9 has joined #crystal-lang
fryguy9 has quit [Client Quit]
<Yxhuvud>
(they will get them in java 10 or something like that)
<Yxhuvud>
they also limit the need to focus so much on throughput, as there is simply less to do.
<RX14>
escape analysis too would be great
<RX14>
which asterite mentioned recently
<RX14>
because escape analysis means no garbage is even created
Svenskunganka has joined #crystal-lang
Svenskunganka has quit [Ping timeout: 260 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<FromGitter>
<schoening> It says in the manual that Structs are allocated on the stack. So, does that mean I would create an stack overflow if I create too many structs? :o
<RX14>
yes
<FromGitter>
<dreyks> struct overflow :-D
<RX14>
but you can't really just allocate structs in a loop
<RX14>
it doesn't work that way
<FromGitter>
<schoening> HAHA
<FromGitter>
<schoening> Let's build that @dreyks a Crystal questions community
mounibec has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<RX14>
you can only allocate a fixed number of structs of fixed size right now unless you do... recursive calls
<FromGitter>
<dreyks> yeah recursion is the key to stack overflow
<FromGitter>
<dreyks> you actually not even need the structs then :)
<FromGitter>
<schoening> Is tco planned?
<RX14>
it already exists
<RX14>
LLVM is great at tco and converting recursive algorithms into loops
<FromGitter>
<schoening> Oh. Ok, awesome :D
<RX14>
yeah llvm is great
<RX14>
the compiler at the moment does almost no optimizations at all
<Papierkorb>
LLVM is also great at then getting rid of most loops :P
<RX14>
like as far as I know the number of optimizations the compiler does is less than 5
<RX14>
the rest is llvm
<RX14>
and llvm does amazingly well
<FromGitter>
<schoening> wow
<FromGitter>
<dreyks> that's great. why reinventing the wheel when one can rest on the shoulders of giants
mounibec has joined #crystal-lang
<FromGitter>
<schoening> Yeah, otherwise projects like these probably wouldn't go this far and be so great without a lot more funding
rafadc has joined #crystal-lang
<RX14>
indeed
<RX14>
llvm makes the focus be on developing the language and developer experience
<RX14>
rather than implementing compiler optimizations
Svenskunganka has joined #crystal-lang
soveran has quit [Remote host closed the connection]
Svenskunganka has quit [Ping timeout: 260 seconds]
onec has joined #crystal-lang
soveran has joined #crystal-lang
<FromGitter>
<crisward> Is there any way to check a type inline. I have a class property that has a type of `Time | Nil`, and I want to be able to call `to_s` on it with a time format. It won't compile because it could be nil. Is there a nice way to write this?
<Papierkorb>
crisward, you could use #try: `the_time.try(&.to_s("the format"))`
<Papierkorb>
crisward, if the_time is nil, the result of that expression will also be nil
<FromGitter>
<crisward> Thanks `.try` worked. Many thanks!
Guest73959 has quit [Remote host closed the connection]
<Papierkorb>
cheers
msg has joined #crystal-lang
msg is now known as Guest92924
soveran has quit [Remote host closed the connection]
<lhz>
coming from Ruby, i'd expect [1,2,3].reduce(&.+) to return 6, but it returns 1. is [1,2,3].reduce { |sum, n| sum += n } the most terse way to sum an array in Crystal?
akwiatkowski has quit [Ping timeout: 260 seconds]
<Papierkorb>
lhz: Yes, #sum :)
<Papierkorb>
s/Yes/No/
<lhz>
Papierkorb: duh, talk about missing the obvious. thanks! :)
rafadc has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<lhz>
i actually looked through the api docs for Array, but forgot the stuff inherited from Enumerable.