RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.0 | 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
DTZUZU has quit [Quit: WeeChat 2.2]
jemc has quit [Ping timeout: 268 seconds]
<FromGitter> <bajro17> Thanks for help @jwoertink @fridgerator @j8r
<FromGitter> <swinSpo> @Blacksmoke16 that seems like a huge deal if it cant connect to mysql? Are there other database packages / frameworks that work with mysql?Or cant you use mysql with crystal?
<FromGitter> <swinSpo> Hi, so i have an issue with getters and properties
<FromGitter> <swinSpo> ``````
<FromGitter> <swinSpo> I thought i would use a getter to "shorten" this
<FromGitter> <swinSpo> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5be39d2292b7d1172154b2cb]
<FromGitter> <swinSpo> but that gives me the error " no argument named 'provider'"
<FromGitter> <swinSpo> Ohhh its the spacing between ```provider: EnvProvider```
<FromGitter> <Blacksmoke16> could just use lower mysql version? or PG, or fix it and make a PR :p
<FromGitter> <swinSpo> the thing is i tried with sqlite first, but that also gave me an error
<FromGitter> <swinSpo> I can use PG for sure, if that works
<FromGitter> <Blacksmoke16> oh? could be more going on then?
<FromGitter> <swinSpo> The sqlite3 error is "/usr/bin/ld: cannot find -lsqlite3 (this usually means you need to install the development package for libsqlite3)"
<FromGitter> <swinSpo> also there is no "libsqlite3" package to install
<FromGitter> <swinSpo> And on the github page https://github.com/crystal-lang/crystal-sqlite3 there is no hint on how to solve this issue or what to do
<FromGitter> <swinSpo> just for comparison, the Go version with sqlite3 works
<FromGitter> <bajro17> sqlite3 not lsqlite3
<FromGitter> <bajro17> are you try this example from github?
<FromGitter> <swinSpo> yes
<FromGitter> <bajro17> can you put it on github or https://play.crystal-lang.org
<FromGitter> <bajro17> to check
<FromGitter> <DanilaFe> Hello! I just wanted to share my recent project, Pegasus, which is a parser generator that outputs C: https://github.com/DanilaFe/pegasus
jemc has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> @swinSpo it's idiomatic to overload the `[]` operator for indexed getters like that: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5be3bd0e7a36913a9a0b6245]
<FromGitter> <dscottboggs_gitlab> @swinSpo it's idiomatic to overload the `[]` operator for getters like that: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5be3bdf162866f747365c3b2]
jemc has quit [Ping timeout: 252 seconds]
DTZUZU has joined #crystal-lang
DTZUZU has quit [Quit: WeeChat 2.2]
jemc has joined #crystal-lang
DTZUZU has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
<FromGitter> <swinSpo> damn, that is really interesting.. It really seems like crystal gives you a lot of "power" to do things, it feels like a dynamic language
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
jemc has quit [Ping timeout: 252 seconds]
<FromGitter> <swinSpo> Hey, i am reading through the docs here
<FromGitter> <swinSpo> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5be3e6de6b9822140df89783]
<FromGitter> <swinSpo> is this a typo? The first one uses 4 times more memory
<FromGitter> <swinSpo> I have a question regarding the "Hash", is this comparable with a map in Go? Why is it called Hash and not Map? And what about concurrent usage of the Hash? Is it concurrent safe? Or would I need to use a Mutex?
crystalsuer has joined #crystal-lang
<crystalsuer> hey all
crystalsuer has quit [Client Quit]
<FromGitter> <proyb6> @swinSpo you mean 77.11M as in memory usage?
<FromGitter> <j8r> @swinSpo in Hash, it means Hash table. Also called in other languages as object, record, struct, dictionary, keyed list, or associative array.
<FromGitter> <dscottboggs_gitlab> @swinSpo different languages have different names for what crystal calls a Hash, Go calls a `map` and Python calls a `Dict`. It's called a hash because the values are sorted according to the hashes of the keys and then referenced by looking in that sorted list
<FromGitter> <dscottboggs_gitlab> yeah, that
<FromGitter> <dscottboggs_gitlab> I like how all three of us just happened to type messages to that dude at the same time haha
<FromGitter> <proyb6> M is a unit for Million for score, MB is megabyte for memory
<FromGitter> <dscottboggs_gitlab> also it's helpful to remember that crystal is basically a hard fork of ruby so a lot of naming and stuff came from ruby
<FromGitter> <proyb6> r
<FromGitter> <swinSpo> @proyb6 yes
<FromGitter> <swinSpo> @j8r @dscottboggs_gitlab i see, it is a bit confusing for me because I am using Go, Java, typescript and now Crystal and they all seem to name things a little different but thats alright
<jhass> oprypin: maybe you're thinking of https://github.com/crystal-lang/crystal/issues/1150 (I didn't realize I opened over 140 issues...)
<FromGitter> <swinSpo> what about concurrent usage? I need to lock the Hash to not have race conditions right?
<FromGitter> <dscottboggs_gitlab> concurrency is handled like in go, but without the parallellism (yet)
<FromGitter> <swinSpo> No I mean the map access
<FromGitter> <dscottboggs_gitlab> you use `spawn do...end` like `go func() {} ()` in golang, and communicate over channels. yes in the case of accessing a hash concurrently you could use a mutex
<FromGitter> <dscottboggs_gitlab> but generally communication from concurrent processes happens through channels in crystal and go
<FromGitter> <swinSpo> yes sure, but many times you have a global map of data that you access through many requests
<FromGitter> <swinSpo> for example I like to implement repositories as in memory -map for tests and development, so many requests access the map (hash)
<FromGitter> <dscottboggs_gitlab> yes there is a mutex class (https://crystal-lang.org/api/0.27.0/Mutex.html) ⏎ ⏎ concurrency is a little weird in crystal for now (one of the main things keeping it from 1.0) so make sure you test to make sure things actually work the way you expect them to
<FromGitter> <swinSpo> hmm interesting
<FromGitter> <swinSpo> Yes I noticed the mutex class, but it only seems to have lock and unlock and no read lock and read unlock?
<FromGitter> <dscottboggs_gitlab> I'm not sure I understand, that doesn't make sense to me. you would want to lock both reads and writes whichever you're doing
<FromGitter> <dscottboggs_gitlab> Is there any way to create a function/method which is only accessible by instance methods or class methods of a particlar class or within a particular file? ⏎ ⏎ I have some `private def` methods that I want to access from class methods basically
DTZUZO has quit [Ping timeout: 252 seconds]
<FromGitter> <swinSpo> @dscottboggs_gitlab why? You can read many times
<FromGitter> <dscottboggs_gitlab> the whole point of locks, to prevent data from changing mid-read or write? or am I misunderstanding something?
<FromGitter> <swinSpo> Take a look at
<FromGitter> <swinSpo> "the lock can be held by an arbitrary number of readers or a single writer"
<FromGitter> <dscottboggs_gitlab> OH!
<FromGitter> <dscottboggs_gitlab> I see. So you can lock it so that no one can write to it but you can still read from it. I don't think that requires a separate function though, does crystal already do that?
* FromGitter * dscottboggs_gitlab shrugs https://carc.in/#/r/5gre @swinSpo
<FromGitter> <dscottboggs_gitlab> goodnight
<FromGitter> <swinSpo> @dscottboggs_gitlab im not sure what i am looking at
ashirase has quit [Ping timeout: 268 seconds]
ashirase has joined #crystal-lang
<FromGitter> <swinSpo> i haven't seen this syntax yet
<FromGitter> <swinSpo> **data
<FromGitter> <swinSpo> whats that?
<FromGitter> <swinSpo> also what is this p! ?
<FromGitter> <bararchy> @swinSpo => https://crystal-lang.org/api/master/toplevel.html#p%28object%29-class-method
<FromGitter> <bararchy> and `p!` => https://crystal-lang.org/api/master/toplevel.html#p%21%28%2Aexps%29-macro
<FromGitter> <swinSpo> @bararchy i understand p! now, but i still dont see an explanation for **t
<FromGitter> <bararchy> That's a way of writing `an array of vars`
<FromGitter> <bew> But it is a NamedTuple in crystal, not a Hash like in Ruby
<FromGitter> <swinSpo> ah sorry i didn't read far down enough
<FromGitter> <swinSpo> I have another question
<FromGitter> <swinSpo> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5be41a2d7a36913a9a0da5c3]
<FromGitter> <swinSpo> I am not sure I understand the purpose of this? It says ```In this way a module can be used as a namespace: ⏎ ⏎ Base64.encode64 "hello" #=> "aGVsbG8=" ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5be41a54bb06d73a99401f76]
<FromGitter> <swinSpo> But I can already do this without the extend ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5be41a9262866f747367fdc8]
<FromGitter> <bew> That shouldn't be
<FromGitter> <bew> Huh weird
<FromGitter> <swinSpo> I have this code in my test.cr file
<FromGitter> <swinSpo> so its all together, not sure if that changes anything
<FromGitter> <swinSpo> https://carc.in/#/r/5gs8
<FromGitter> <bararchy> the original point to `extend self` is to avoid writing `def self.method(bla)`
<FromGitter> <mkhairi> hi, is there a way/method like ruby const_get? i want convert string to class
<FromGitter> <bew> no there isn't, there are other ways to achive this kind of goal though
<FromGitter> <bew> where is that string coming from?
ua has joined #crystal-lang
dabedoc has joined #crystal-lang
<dabedoc> hello :)
dabedoc has left #crystal-lang [#crystal-lang]
<jokke> hey there, i have a jsonb field in postgres and when reading the record from the db it's unclear how to deserialize it so i need to define the field as JSON::Any. Is there a builtin way to turn a JSON::Any into a specific structure like there is JSON::Serializable for initializing from a pull parser
<jokke> and if not, would something like this be easy to add to JSON::Serializable? basically it should be a matter of using #[] with the defined field names and using .as(Type) with the defined types for the trivial cases. If however it's a nested object or uses a converter, things get a bit more interesting
Raimondi has quit [Ping timeout: 240 seconds]
Raimondi has joined #crystal-lang
<FromGitter> <vusaalab> Hi guys! is crystal good for video transcode with ffmpeg
Raimondi has quit [Remote host closed the connection]
ua has quit [*.net *.split]
rohitpaulk has quit [*.net *.split]
bmcginty has quit [*.net *.split]
oprypin has quit [*.net *.split]
livcd has quit [*.net *.split]
RX14 has quit [*.net *.split]
pabs has quit [*.net *.split]
bmcginty has joined #crystal-lang
oprypin has joined #crystal-lang
ua has joined #crystal-lang
RX14 has joined #crystal-lang
livcd has joined #crystal-lang
rohitpaulk has joined #crystal-lang
Raimondi has joined #crystal-lang
<jhass> well that's just shelling out, no?
<FromGitter> <vusaalab> Hi guys! is crystal good for video transcode with ffmpeg
Raimondi has quit [Remote host closed the connection]
<FromGitter> <bew> Yes, or more exactly it depends what part of it you want to do in Crystal and how much work you want to do
Raimondi has joined #crystal-lang
<FromGitter> <vusaalab> I want to convert all mov and webm to mp4
Raimondi has quit [Remote host closed the connection]
ua has quit [Ping timeout: 272 seconds]
Raimondi has joined #crystal-lang
<FromGitter> <vusaalab> and chunk file upload
Raimondi has quit [Remote host closed the connection]
<FromGitter> <vusaalab> @bew chunk file upload and convert MOV and WEBm to mp4
Raimondi has joined #crystal-lang
<FromGitter> <swinSpo> My first Safe Map
<FromGitter> <swinSpo> https://carc.in/#/r/5gsl
Raimondi has quit [Remote host closed the connection]
Raimondi has joined #crystal-lang
<FromGitter> <swinSpo> Something I cant do in Go xD
<FromGitter> <bew> @swinSpo crystal has no threads for now, everything is concurrent...
<FromGitter> <swinSpo> @bew you mean nothing?
<FromGitter> <bew> No, it is concurrent, not parallel
<FromGitter> <bew> @swinSpo checkouot https://crystal-lang.org/docs/guides/concurrency.html
<FromGitter> <swinSpo> why would it be concurrent then
<FromGitter> <swinSpo> ```p! "hi" ⏎ p! "hi2"``` [https://gitter.im/crystal-lang/crystal?at=5be4485147217e07ffee74b7]
<FromGitter> <swinSpo> this is not executed concurrently is it?
<FromGitter> <bew> no, because you're in the same fiber
<FromGitter> <bew> yeah by "everything" I mean things executed in different fibers
<FromGitter> <swinSpo> so not everything is concurrent
<FromGitter> <swinSpo> yes
<FromGitter> <bew> but a mutex is useless in concurrent environement, because only 1 fiber can execute at a given time
<FromGitter> <swinSpo> so if it does not have parallelism yet, that means I have no race conditions on map reads and writes yet?
<FromGitter> <bew> yes
<FromGitter> <bew> parallelism will come, but you probably won't have to deal with mutexes directly
<FromGitter> <straight-shoota> But it's still not a bad idea to be prepared
<RX14> mutex is useful right now
<RX14> but hash accesses and writes never contain a yield point
<FromGitter> <swinSpo> the way you phrase it though is a bit odd, the way you mean it is that it doesnt have parallelism
<RX14> so it's not useful for this specific case
<RX14> you will have to deal with mutexes in parallelism...
<FromGitter> <bew> RX14 "mutexes is useful right now" for what?
<RX14> when there's a yield point in the mutex protected code...
<RX14> i.e. doing any IO
<FromGitter> <swinSpo> i haven't understood the yielding yet. I have never seen this before
<FromGitter> <swinSpo> I have used PHP, Java, c#, Go and javascript.. what is yielding like?
<RX14> it's just that there are only certain points where threads switch fibers
<RX14> when you use channels or do network IO
<RX14> you don't really have to worry about them
<RX14> they're an implementation detail
<FromGitter> <swinSpo> @bew also, you said " but you probably won't have to deal with mutexes directly" Why do you think that? If crystal gets parallelism (which i hope for in the future) then why wouldnt you use a mutex?
<RX14> bew is incorrect
<RX14> any shared memory will have to be protected using a mutex
<FromGitter> <swinSpo> Yeah I use maps as a form of dumb data storage / repository
<RX14> maps shared between fibers currently dont need mutexes but they will once parallelism lands is all
jemc has joined #crystal-lang
<FromGitter> <bew> Ah true for shared memory indeed
<livcd> but the abstraction to use will be modeled after Go with channels right ?
jemc has quit [Quit: WeeChat 2.2]
<RX14> we've had channels already
<RX14> and you can pass objects around with channels in parallelism just fine and it'll be safe
<RX14> it's just hard to verify if an object is being used from one fiber only
<jokke> which is why you should assume that it's not imho
<jokke> which is also why things like. `@foo.upcase unless @foo.nil?` don't work and shouldn't work
<RX14> i guess word-length stores are atomic on x86
<RX14> so at the very least we can avoid segfaults
flaviodesousa has quit [Quit: KVIrc 4.2.0 Equilibrium http://www.kvirc.net/]
<oprypin> jhass, thanks for the link. yeah it seems similar to what I had in mind, but it's actually talking about something different. I guess that *was* the right post, just that I misremembered.
<livcd> The channels underneath use mutex anyway right ?
<FromGitter> <swinSpo> jokke, what do you mean with @foo.upcase unless @foo.nil?
<FromGitter> <swinSpo> are you talking about that causing a race condition potentially?
<RX14> oops
<jokke> swinSpo yes. @foo can be changed in between the calls
<RX14> it's talking about instance vars not being restructed
<RX14> because of the race condition between type check and use
<jokke> ^
<FromGitter> <vladfaust> Is there `method_missing` for Class calls?
<RX14> no
<FromGitter> <vladfaust> Is there any workaround then?
<RX14> probably not
<RX14> yeah nope its not possible
<RX14> it probably should be though
<RX14> a feature request would be good
<FromGitter> <swinSpo> How do I even ping someone from IRC
<FromGitter> <swinSpo> RX14 i think you are right about the race condition between type check and use
<jhass> most IRC clients recognize highlights on the plain username
<RX14> *all
<RX14> @RX14 or RX14 pings me
<FromGitter> <swinSpo> however, when would you use a global class instance and mutate things inside of it for your app?
<RX14> depends on usecases
<RX14> there are a lot of reasons for global state
<FromGitter> <swinSpo> can you give an example? I am trying to come up with someone
<RX14> that's like asking for a real-world example of an if statement - there are so many uses it's hard to think :)
<RX14> if we stay witning the webapps sphere perhaps a stats counter
<RX14> within*
<RX14> but for anything that isn't request based, having global state is the norm
<RX14> stateless applications are very rare outside webapps, and even there they're a fairly new idea
<jokke> jhass: o/ long time no see
<jokke> swinSpo: ^ that's an example btw
<jokke> oh lol
<jokke> i thought you meant highlighting ppl from irc still ^^
* jokke has to read more carefully
<FromGitter> <j8r> how can I mix differently scoped macro vars? `\{% vars = vars + key.id %}` complains `undefined macro variable 'vars'` and `{% vars = vars + key.id %}` complains `undefined macro variable 'key'`
<FromGitter> <j8r> for something like ⏎ ⏎ ```{% vars = "" %} ⏎ macro mac(key) ⏎ {% vars = con_vars + key.id %} ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5be460393102f145216d7802]
<FromGitter> <vladfaust> 1) Try wrapping in `{% begin %} {% end %}`
<FromGitter> <j8r> already done, no luck :(
<FromGitter> <vladfaust> 1) Sometimes `{% key = key %}` helps
<RX14> @j8r you cant
<RX14> you need to use a mutable constant for that
<FromGitter> <j8r> for the carc: https://carc.in/#/r/5gt6
<RX14> thats the only way
<FromGitter> <vladfaust> https://carc.in/#/r/5gtc
<RX14> oh nice
<FromGitter> <vladfaust> It's not nice, it's a kinda ugly workaround. Got to use in some shards :(
<FromGitter> <j8r> Hum ok then I'll do `Array(Tuple(String, String))` for my use case, thanks @RX14 and @vladfaust :)
<RX14> well
<FromGitter> <straight-shoota> @vladfaust's doesn't scale
<FromGitter> <vladfaust> @straight-shoota https://carc.in/#/r/5gtd
<RX14> mutable constants are probably going to be removed entirely sooner or later
<FromGitter> <bew> wat??
<FromGitter> <bew> :/
<RX14> make real DSLs, macros suck
<FromGitter> <vladfaust> Yeah, but it's the only way to store info in compile time
<RX14> you're not supposed to do that
<FromGitter> <vladfaust> My ORM abuses it so much: https://github.com/atomframework/model/blob/master/src/atom/model.cr#L78
<FromGitter> <vladfaust> > you're not supposed to do that ⏎ ⏎ Why? What's bad in storing meta in compile time?
<RX14> can't do increamental compilation
<FromGitter> <j8r> hum I need to find something other than the mutable constant, because I include a module with this macros
<FromGitter> <j8r> all structs that include this module will share the same constant :/
<FromGitter> <vladfaust> @j8r how bout defining that const in `included` macro?
<FromGitter> <vladfaust> > can't do increamental compilation ⏎ ⏎ Anyway, storing meta is crucial
<jokke> whaaat mutable constants are going to be removed??
<RX14> maybe
<RX14> bcardiff was talking about it
<FromGitter> <j8r> included dones't solve, I feel I'm doing wrong
<jokke> this is going to break like every second shard lol
<RX14> i don't really care either way
<RX14> maybe every second shard shouldn't abuse macros then
<FromGitter> <j8r> how about `ARGV`?
<RX14> thats not a mutable constant
<jokke> i don't understand why it's abusing
<FromGitter> <j8r> refactor the OptionParser
<FromGitter> <vladfaust> The language should not consist 99% of workarounds then?
<RX14> we're talking about macros specifically
<FromGitter> <vladfaust> Nice words as the core team member, @RX14 :)
<jokke> RX14: how would you write a dsl for defining fields in an orm without a mutable constant?
<FromGitter> <j8r> mutable class_variables?
<RX14> jokke, probably annotations
<jokke> mhm
<FromGitter> <vladfaust> I'm disappointed so much right now
<FromGitter> <proyb6> Is it feasible to convert string to hash and use for comparing string using ==
<jokke> i hope that if it indeed is going to be removed it is being done by deprecating it first
<RX14> pretty much all ORMs should probably be looking at annotations and working out what's stopping them from using them
<FromGitter> <proyb6> The benchmark shown it took <4nanoseconds compare to 50nanoseconds when compare with string
<FromGitter> <vladfaust> > what's stopping them from using them ⏎ ⏎ Ugly syntax maybe?
<FromGitter> <Blacksmoke16> its not tho
<jokke> i don't agree. nothing ugly about annotations imo
<RX14> you mac make a macro that expands to an annotated field
<RX14> it wouldn't even need to break API
<RX14> also yes, I agree with jokke
<jokke> fridgerator: you reading this/
<jokke> ?
<RX14> removing mutable constants isn't certain
<RX14> and it's not doon
<RX14> it's just something to be aware of
<jokke> yeah. but if it's on the table and there are alternatives it's worth looking into
<RX14> and you should be treating their use as essentially a bug in the language if you can't find a good alternative
<FromGitter> <vladfaust> Mad world we're living in
<FromGitter> <j8r> but what's differentiating class_variables and constants?
<RX14> @j8r constants can't be assigned to twice
<RX14> amnd can exist at the top-level
<FromGitter> <j8r> right. So we can usually replace them by cvars then?
<RX14> we're not removing constanrs
<FromGitter> <j8r> with a globally available struct
<RX14> we're talking about the very very specific behaviour of being able to modify constants *in macros*
<FromGitter> <vladfaust> Yes
<FromGitter> <j8r> Anyway having constants not so constant aren't really intuitive
<FromGitter> <vladfaust> I disagree, @j8r; you can say "having methods defined in macros is magic"
<RX14> constants will still be mutable at runtime
<RX14> like
<FromGitter> <kinxer> I do have to agree, as a newcomer to Crystal, that "mutable constant" seems like a confusing contradiction.
<RX14> I think we;re talking about 2 things here
<FromGitter> <j8r> yeah macros vs runtime
<RX14> constants being mutable at runtime, which is normal and will stay
<RX14> and constants being mutable in macros, which is weird
<RX14> the constant itself is never mutable
<RX14> in either case
<RX14> it's just that what's constant is the reference
<RX14> you can follow the pointer and you get mutable data
<RX14> but the pointer is constant
<FromGitter> <vladfaust> As always, I'm against the crowd and think that the constant itself should be mutable at compilation
<RX14> same in ruby, java, C#, etc. etc.
<FromGitter> <kinxer> Why is it useful to have something called a constant that is not, in fact, constant? Sure, the pointer is constant, but (maybe from inexperience) I don't see how that is useful at all.
<FromGitter> <vladfaust> > As always, I'm against the crowd and think that the constant itself should be mutable at compilation ⏎ ⏎ Because macros are "over-language", we can explicitly write code in macros, define and redefine methods, why limit constants?
<RX14> you can define and redefine methods without macros
<RX14> you cannot do the same for constants
<FromGitter> <vladfaust> You cannot write code from an external file without macros
<FromGitter> <vladfaust> But you can with
<RX14> @kinxer essentially it's impossible to do so most languages allow it and so it's treated as fine
<RX14> @vladfaust you can always write *more code* with macros
<RX14> you cannot modify existing code
<RX14> mutable constants are the only way that assumption is broken
<FromGitter> <fridgerator> @jokke just catching up. I'm not surprised, I've known that crecto (and probably every other ORM) was abusing macros.
<FromGitter> <fridgerator> I assumed it would become an issue sooner or later
<FromGitter> <vladfaust> Isn't redefining methods essentially *is* modifying existing code? I mean, those previous definitions are wiped from the program (unless explicitly using `previous_def`)
<FromGitter> <vladfaust> Shouldn't the same logic apply to constants?
<RX14> maybe
<RX14> maybe redefining constants at the top-level is fine
<RX14> since it's not at runtime
<FromGitter> <vladfaust> How would it affect incremental building then?
<RX14> who knows, not worse thanr edefined methods that for sure
<FromGitter> <vladfaust> I wanted to create an issue, but I'm afraid I'll be weak with my use-cases and argumentation
<RX14> i'd wait until it's actually proposed to remove mutable constants
<FromGitter> <kinxer> @RX14 I think I've been thinking about constant primitives (which, I believe, don't exist as-such in Crystal), but I'm pretty sure I understand now that I'm framing it as pointers to objects.
<FromGitter> <vladfaust> But they aren't mutable at the moment :D
<RX14> you know what i mean @vladfaust :P
<RX14> @kinxer constant primitives are immutable currently
<RX14> classes like String which are naturally immutable are also constant
<FromGitter> <kinxer> @RX14 Oh, okay. Yeah, I'm on the same page now.
<FromGitter> <swinSpo> @vladfaust does your orm work with mysql?
<FromGitter> <vladfaust> @RX14 but if String constant had a property, would it be mutable?
<RX14> yes
<RX14> in fact String is secretly mutable
<FromGitter> <vladfaust> Oh, I like secrets
<FromGitter> <swinSpo> a mutable constant sounds like a variable
<RX14> it's just hidden from the API
<RX14> the size of the string in codepoints is lazilly evaluated in strings
<RX14> but since String#size always either caclulates or looks up the codepoint length then it's hidden from the API
<FromGitter> <vladfaust> So, essentially, constant is either a primitive or a pointer, and neither is mutable
<FromGitter> <j8r> For more info: https://news.ycombinator.com/item?id=18371392
<FromGitter> <vladfaust> @swinSpo MySQL would require some additions to the codebase similar to https://github.com/atomframework/model/tree/master/src/atom/ext/pg/result_set
<FromGitter> <j8r> And Swift is moving out NSString https://news.ycombinator.com/item?id=18394640 ⏎ Crystal Strings are like Pascal Strings?
<RX14> crystal strings are always UTF-8
<RX14> and they store their size
<RX14> so yes, similar to pascal
<RX14> however since they're UTF-8 there are 2 sizes
<RX14> the bytesize and the codepoint size
<RX14> bytesize is always present
<RX14> and codepoint size is lazily calculated
<Yxhuvud> Hmm. I wonder if there are cases where it would make sense to create some sort of index for strings, to make it faster to index by codepoint for big strings.
<FromGitter> <swinSpo> I know this is a silly example, but i ran the http server for both crystal and Go and made a simple benchmark
<FromGitter> <swinSpo> Go could handle 18000 requests / second and crystal 20000 requests/second.. How is that possible though if it doesnt support parallelism?
<Yxhuvud> @swinspo: it still support concurrency. But it seems low in any case. Did you use a singlecore VM or something?
<Yxhuvud> (or some nonetrivial computation at the endpoint?
<RX14> @Yxhuvud, indexing strings by codepoint actually turns out not to be that common
<FromGitter> <swinSpo> @Yxhuvud how is 20k r/s low? lol!
<FromGitter> <swinSpo> i just used ab on localhost
<RX14> @swinSpo because crystal manages about 100k/s per core on modern hardware
<RX14> ab is an old benchmarking tool
<Yxhuvud> rx14: I'm thinking in the context of parsers etc. then suddenly it could make a lot of sense.
<RX14> ab itself isn't fast enough for a lot of webservers @swinSpo
<RX14> check out wrk
<RX14> @Yxhuvud you still dont often index inside strings in parsers
<RX14> you write your parser with a fixed lookahead
<RX14> usually 1
<RX14> and accessing the current and next char is O(1) for Char::Reader
<Yxhuvud> Sure, but then you want to combine several characters and want to handle ranges etc.
<RX14> what do you mean?
<RX14> crystal's parser has a lookahead of 1 token and the lexer doesn't re-read chars
<RX14> and crystal is very complex
<Yxhuvud> well, say you have identified a token of 7 characters. It is nice to be able to refer to them in an efficient way that doesn't have to duplicate the storage of the actual string in memory, but preferably just refer into the existing string to be able to recreate sequences at need.
<Yxhuvud> perhaps it is a bigger problem in parsers that actually support overlapping tokens :)
<Yxhuvud> (like mine)
<FromGitter> <tonobo> Heyho guys, i want to read the last line of a file, without reading the whole file. ruby allows me to do a reverse_each, how can i do this in crystal.
<FromGitter> <Blacksmoke16> `.reverse.each ...`?
<RX14> Yxhuvud, overlapping tokens?!?!
<Yxhuvud> tonobo: you better provide a more complete example of what you want to reproduce.
<Yxhuvud> rx14: grammars can be ambigous or be unambigous but have partial results which are ambigous.
<RX14> @tonobo reverse_each exists in crystal
<Yxhuvud> eg: it can parse palindromes.
<FromGitter> <tonobo> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5be4718a7a36913a9a100662]
<FromGitter> <swinSpo> @RX14 wrk also just gives me 30k r/s with ./wrk -t12 -c400 -d30s http://127.0.0.1:8080/
<FromGitter> <tonobo> I want to use something like this -> ⏎ ⏎ ```File.open(logfile, "rb").each_line.reverse.first``` [https://gitter.im/crystal-lang/crystal?at=5be471d06b9822140dfc3b25]
<RX14> @swinSpo release mode crystal?
<RX14> @tonobo you can do that in crystal but you'd have to buffer the whole file into memory to do that
<FromGitter> <swinSpo> Damn.. and Go now gives me 140K r/s work wrk
<FromGitter> <tonobo> RX14: I don't want this ...
<RX14> if your files aren't going to be large (1MiB+) i'd suggest using File#each_line do |line|; @line = line; end
<FromGitter> <swinSpo> @RX14 I have built with crystal build --release test.cr
<FromGitter> <tonobo> my files could be pretty large ;)
<FromGitter> <tonobo> Thats because i'm do so
<FromGitter> <swinSpo> that gives me 64K r/s for crystal
<RX14> @tonobo yeah you'll have to do backwards search for the last `\n` manually :(
<RX14> as in use file.size and file.pos= to read chunks and search them for line seperators
<Yxhuvud> swinspo: how many cores do you have?
<FromGitter> <tonobo> So sad ;(
<RX14> @swinSpo yeah thats the parallelism
<RX14> @tonobo finding the last line in a file is not a simple problem and probably doesn't belong in crystal's stdlib
<Yxhuvud> tonobo: I guess ruby has implemented some sort of optimization to their file iterator to handle it for you?
<RX14> there should definitely be a shard for it if there isn't already though
<RX14> @Yxhuvud, probably
<Yxhuvud> I guess a similar specialization would be possible in crystal too, but probably not very prioritized.
<FromGitter> <swinSpo> but I dont understand that result.. I have 4 cores with HT, wouldn't my result for Go be almost 6-7 times faster?
<FromGitter> <tonobo> Thanks guys, i'll try to move the file pointer backwards.
<FromGitter> <swinSpo> compared to crystal
<RX14> @swinSpo if you use GOMAXPROCS=1 then crystal is faster
<RX14> so there's a bit of that and a bit of non-linear scaling
<Yxhuvud> @swinspo: also remember that you run wrk on one cpu
<RX14> it depends on workload and processor
<RX14> so
<FromGitter> <tonobo> if its a generic solution i'll file a pull request
<FromGitter> <swinSpo> so what you are saying is that once crystal gets parallelism, it will probably be as fast as Go if not faster?
<RX14> we'll see
<RX14> go has put a lot of effort into parallelism
<FromGitter> <proyb6> It's also depend on the type of router path
<FromGitter> <proyb6> I think if the router path is compare in string will be slower than slice?
<FromGitter> <proyb6> with parallelism and slice would be a big winner.
<FromGitter> <tonobo> RX14: FYI ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5be47d34bb887874749a27d9]
<Yxhuvud> reading char by char like that can be a performance drain.
<Yxhuvud> but perhaps it is good enough for your needs?
<FromGitter> <tonobo> Is it better to read more than a just single byte?
<FromGitter> <tonobo> Maybe reading a bunch of bytes and afterwards checking for newline?
<Yxhuvud> benchmark and find out. my experience in reading files backwards efficiently was back in ruby 1.8 time.
<Yxhuvud> (also I wonder if File have buffers in crystal, and how that may interact with the question)
<FromGitter> <tonobo> ¯\_(ツ)_/¯
riceandbeans has quit [Read error: Connection reset by peer]
non-aristotelian has joined #crystal-lang
non-aristotelian has quit [Client Quit]
non-aristotelian has joined #crystal-lang
non-aristotelian has quit [Client Quit]
<Yxhuvud> oprypin: yes?
<Yxhuvud> (I mean, I suppose wrk may be multicpu too, but that is beside the point)
<oprypin> Yxhuvud, compare that picture to what you actually see on https://gitter.im/crystal-lang/crystal
<Yxhuvud> ah, you are improving the bridge somehow?
<oprypin> no just faking it with a userscript :(
non-aristotelian has joined #crystal-lang
<FromGitter> <bew> Fun, will you share it @oprypin?
<oprypin> yeah, just squashing some bugs
<FromGitter> <bew> So you can @-complete IRC users?
<oprypin> oh yeah, forgot about that part :<
<oprypin> i made it so you can click on irc users names, at least
<jhass> weechat plugin next? :D
<FromGitter> <bew> Arf, RX14 did a xchat plugin iirc
<oprypin> i have patches for Quassel and Konversation and i think RX14 has a Hexchat plugin
<FromGitter> <bew> Ah yes hexchat maybe
<RX14> yep
<RX14> its not mine
<RX14> it's Vexatos's
<oprypin> ok but is it public?
<RX14> yep
<oprypin> ok so where is it?
<RX14> cant remember
<oprypin> :>
<RX14> you do /addbot FromGitter ~ <>
<RX14> the ~ is custom and can be whatever
<RX14> its just a prefix to the nicks which ways whether its a bot or not
<FromGitter> <wontruefree> do we use a python irc bridge?
<FromGitter> <wontruefree> who maintains it?
<FromGitter> <bew> It's a crystal irc bridge
<FromGitter> <vladfaust> Can I register an `at_fork` callback somehow? I want to re-initialize a Redis client on fork
<FromGitter> <bew> @oprypin maybe? (not sure)
<FromGitter> <wontruefree> who runs the IRC brigde?
<FromGitter> <wontruefree> like hosts it
<oprypin> me
<FromGitter> <wontruefree> thanks
<FromGitter> <wontruefree> did you also write the bridge?
<oprypin> yes
<FromGitter> <wontruefree> I am looking at it
<FromGitter> <bew> Btw @oprypin why were you writing a gitter userscript if you ~never~ very rarely use gitter?
<FromGitter> <wontruefree> I think I might use ths for another project
<oprypin> wontruefree, i also host it for other projects btw
<FromGitter> <vladfaust> > a bit
<oprypin> bew, just thinking where most users are
<oprypin> also, haven't written LiveScript in a while, gotta have some of that sick pleasure
<FromGitter> <wontruefree> I use to always have IRC open but switched to gitter recently
<FromGitter> <bew> Interesting, didn't know livescript
<FromGitter> <j8r> Some patches are still needed to pass cryst specs on Alpine, to got 0
<FromGitter> <j8r> To got 0.27.0
<FromGitter> <vladfaust> Is it a common practice to re-initialize `Logger` instance after Proccess fork?
<FromGitter> <vladfaust> Could `STDOUT` be fked up upon forking?
<RX14> no
<FromGitter> <vladfaust> O'aight
Yxhuvud has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
ua has joined #crystal-lang
<FromGitter> <kinxer> On OpenSUSE Tumbleweed I added the Crystal repo using the instructions here (https://github.com/crystal-lang/crystal-book/blob/597dd3a9b39d305ef8cc8bb0218df3f3e76144fd/installation/on_opensuse.html) and have been getting an error when trying to refresh from the repo: ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5be4aedcf1b8753404971b11]
<FromGitter> <kinxer> Any thoughts about what the issue is?
ua has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
<FromGitter> <jwoertink> Is this a bug? Or intended with how the language works?
<FromGitter> <jwoertink> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5be4b8a13102f145216fe331]
<FromGitter> <jwoertink> If you have json that is parsed like `{"bitrate":null}`, then that doesn't act like nil
<oprypin> jwoertink, it's an object that returns `nil` inside `inspect` (for whatever reason)
<oprypin> returns `"nil"` rather
<FromGitter> <jwoertink> oh, it's actually a string
<FromGitter> <jwoertink> nope
<FromGitter> <jwoertink> ```icr(0.27.0) > h["bitrate"] == nil ⏎ => true``` [https://gitter.im/crystal-lang/crystal?at=5be4b91b62866f74736c2ca6]
<FromGitter> <jwoertink> that works
<FromGitter> <jwoertink> ok, I see what you're saying
<oprypin> also returns `true` in `==`
<FromGitter> <oprypin> https://i.imgur.com/ir27Hd6.gif
<FromGitter> <oprypin> ((https://i.imgur.com/ir27Hd6.gif))
johndescs has quit [Ping timeout: 268 seconds]
johndescs has joined #crystal-lang
<FromGitter> <straight-shoota> nice
<oprypin> /cc @bew
<non-aristotelian> Piggy-backing off JW's question: why does Crystal do this? `hash = Hash(String, String | Nil).from_json %({"a":null}) => {}` (cr 0.27.0)
<oprypin> non-aristotelian, it's a bug in my opinion
<non-aristotelian> oprypin: Looks like it. I saw something similar in PG 9.6 JSONB_OBJECT_BUILD, etc.
<non-aristotelian> One more reason to avoid NULL, Nil, every-where.
<non-aristotelian> jwoertink: Will you pastie your initialization of `h`?
<non-aristotelian> oprypin: Where do I submit bug-reports?
<jokke> umm at github?
<non-aristotelian> jokke: TY.
<FromGitter> <jwoertink> `h = JSON.parse(%({"bitrate":null}))`
<jokke> non-aristotelian: yw :)
<non-aristotelian> TY jwoertink
<jokke> non-aristotelian: avoiding nil is a noble cause but doomed to fail :)
<non-aristotelian> jokke: I can do it in my database -- betcha I can avoid it in my own code -- other people's code? You're prolly right.
<jokke> as soon as you have optional user input it's over
<non-aristotelian> I disagree. Optional to me means there's a sane-default. No first-name, "" it is. No DOB? 1900-01-01 it is.
<jokke> there's nothing more terrible than "special" values for empty inputs
<non-aristotelian> NULL is a special "value".
<jokke> no
<jokke> it's a special type
<jokke> easily to distinguish from anything else
<jokke> *easy
<jokke> without any domain knowledge required
<non-aristotelian> I dunno how Cr implements nil; PG has a NULL marker for every type.
<jokke> what's a sane default for a password in a db connection? :)
<non-aristotelian> Depends on the context.
<jokke> let's say i write a webapp and it has a settings class in which available settings are defined. one of which is the database password
<non-aristotelian> You're asking my opinion on a hypothetical scenario -- not interested in going there.
<jokke> how is that hypothetical? :D
<jokke> i have like 5 projects with this exact scenario
<jokke> which is why the password property is String | Nil
<jokke> so i can construct an url and using `password.try { |pw| url.password = pw }`
<oprypin> non-aristotelian, this is one of the top perks of Crystal and is almost unique. `nil` is just the only possible value of type `Nil`, and no other type can "be" nil
<jokke> i wouldn't say it's even almost unique :P
<oprypin> don't be offended by this special treatment in json, it was made deliberately for the case of serializing objects, but also perhaps accidentally affects hashtables
<non-aristotelian> oprypin: Not offended. :) Not sure what you mean "it was made deliberately for the case of serializing objects".
<jokke> what i'm trying to say: nil is not like null in other languages because the compiler will detect uses of it and protect you from assuming a value being set/filled/whatever when it, in fact, isn't. So nil or the class Nil has a very important role and function in crystal. Avoiding it with special values for empty inputs isn't something you should do to protect yourself against null pointer exceptions,
<jokke> the compiler does this for you
<jokke> *in most other languages
<non-aristotelian> oprypin: I enjoyed that article -- also there are some comments detailing avoidance of NULL/Nil. TY for sharing.