ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.30.1 | 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
<FromGitter> <bew> Yeah but maybe not clear enough for ppl who don't want to care how your shard work, and don't want to debug this kind of errors in "not-in-my-code"
<FromGitter> <bew> But i'll try it when it's done :)
<FromGitter> <bew> See how my random-stupidity-generator handle this case
<FromGitter> <bew> Bed is calling though, ++
<FromGitter> <Blacksmoke16> by compile time error i was thinking like `Assertion Foo requires x generic types, but only 1 was given`
<FromGitter> <Blacksmoke16> as ill have access to all that data
<FromGitter> <Blacksmoke16> ill keep you posted ๐Ÿ˜‰
ma__ has quit [Quit: My MacBook has gone to sleep. ZZZzzzโ€ฆ]
devil_tux has joined #crystal-lang
<FromGitter> <Blacksmoke16> @bew got this working
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5b4a9f029a51607fca4308]
<FromGitter> <Blacksmoke16> ```DB query for: Type โŽ DB query for: User โŽ true โŽ ``` [https://gitter.im/crystal-lang/crystal?at=5d5b4aa7beba830fffc85dcd]
lucasb has quit [Quit: Connection closed for inactivity]
<FromGitter> <Blacksmoke16> ```code paste, see link``` โŽ โŽ is the compile error if you forget to add the pos arg to one of the exists annotations [https://gitter.im/crystal-lang/crystal?at=5d5b4b001db76d0ffe07986e]
<FromGitter> <Blacksmoke16> deff can make it more clear
ma__ has joined #crystal-lang
<FromGitter> <Blacksmoke16> `Error: wrong number of type vars for ExistsAssertion(P, M) (given 0, expected 2) on user_id@[Assert::Exists] in Item` im open to suggestions
_whitelogger has joined #crystal-lang
devil_tux has quit [Ping timeout: 258 seconds]
Yxhuvud has quit [Ping timeout: 264 seconds]
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
DTZUZU has joined #crystal-lang
alex`` has quit [Ping timeout: 258 seconds]
chemist69 has quit [Ping timeout: 252 seconds]
chemist69 has joined #crystal-lang
teardown has joined #crystal-lang
ht_ has joined #crystal-lang
ht_ has quit [Remote host closed the connection]
devil_tux has joined #crystal-lang
ma__ has quit [Quit: My MacBook has gone to sleep. ZZZzzzโ€ฆ]
ma__ has joined #crystal-lang
ma__ has quit [Client Quit]
Yxhuvud has joined #crystal-lang
return0e_ has quit [Ping timeout: 245 seconds]
alex`` has joined #crystal-lang
<FromGitter> <absolutejam_gitlab> I have a base class which has `name` and `description` as properties, which are defined in the `initialize`
<FromGitter> <absolutejam_gitlab> I have classes that inherit from this that must also keep the `name` and `description` but can define other properties
<FromGitter> <absolutejam_gitlab> Is there a way to run validations on the `name` property (which is being set by `initialize` at the moment) even if child classes overwrite `initialize`?
<FromGitter> <absolutejam_gitlab> I thought `name=` on the parent might work but I guess that's not called by `initialize(@name = String)`
return0e has joined #crystal-lang
DTZUZO has quit [Ping timeout: 268 seconds]
DTZUZO has joined #crystal-lang
<FromGitter> <Blacksmoke16> @absolutejam_gitlab if you define an initializer on the child and dont call super, it doesnt inherit both
<FromGitter> <Blacksmoke16> so the parent would never be getting called
devil_tux has quit [Ping timeout: 272 seconds]
DTZUZO has quit [Quit: WeeChat 2.0]
<FromGitter> <absolutejam_gitlab> Aye that's what I mean
DTZUZO has joined #crystal-lang
<FromGitter> <absolutejam_gitlab> https://github.com/crystal-lang/crystal/issues/7936 @asterite
<FromGitter> <absolutejam_gitlab> Is there a standard way of defining a convertor?
<FromGitter> <tenebrousedge> what are you trying to do?
<FromGitter> <absolutejam_gitlab> I'm having issues with yaml mapping choosing the wrong type in a union
<FromGitter> <absolutejam_gitlab> It can either be an array of properties or property and its choosing the wrong one
<FromGitter> <tenebrousedge> what's your mapping look like now?
<FromGitter> <tenebrousedge> the section on converters here is probably your answer to how to do that: https://crystal-lang.org/api/0.30.1/YAML.html#mapping(**_properties_)-macro
lucasb has joined #crystal-lang
<FromGitter> <naqvis> Why I'm unable to send/recv data on SSL enabled sockets? Even below sample code from docs doesn't seem to work on Mac and Ubuntu โŽ *Server* โŽ โŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5bef349507182477163095]
DTZUZO has quit [Ping timeout: 245 seconds]
<FromGitter> <absolutejam_gitlab> @tenebrousedge Oh, there's the convertor info, thanks
<FromGitter> <absolutejam_gitlab> So an example from `Time` โŽ โŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5bf30c1db76d0ffe0cc589]
<FromGitter> <absolutejam_gitlab> So I guess I can just case on the YAML node type
<FromGitter> <absolutejam_gitlab> ` default: String? | Hash(String, String) | Hash(String, Hash(String, String)),`
<FromGitter> <absolutejam_gitlab> Gross.
<FromGitter> <Blacksmoke16> could make an alias
<FromGitter> <absolutejam_gitlab> Oh yeah definitely, but I just mean the spec itself
<FromGitter> <absolutejam_gitlab> Just standardise on one type
<FromGitter> <absolutejam_gitlab> Like how you can have `foo: ` as a network in docker-compose
<FromGitter> <absolutejam_gitlab> Why an empty object. Why
<FromGitter> <Blacksmoke16> :S
<FromGitter> <naqvis> @Blacksmoke16 Appreciate your thoughts/comments/insights on what could be causing that SSL enabled communication issue?
<FromGitter> <Blacksmoke16> uhh, could one of the reads be blocking?
<FromGitter> <naqvis> seems like that way, I wasn't able to communicate to different server on SSL, so thought of doing the investigation to see if data does get transmitted on SSL sockets, but seems that's not happening
<FromGitter> <naqvis> looking into `HTTP::Client` revealed that, have to manually invoke `flush` after every send (weird)
<FromGitter> <naqvis> this is different from non-TLS sockets, where write doesn't need to end up with `flush`
<FromGitter> <naqvis> anyway, got this sorted out
<FromGitter> <naqvis> ๐Ÿ˜†
<FromGitter> <absolutejam_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5bfb951db76d0ffe0d0ac0]
<FromGitter> <absolutejam_gitlab> Oh dear, haha
<FromGitter> <Blacksmoke16> whoa
<FromGitter> <absolutejam_gitlab> I had a lot of distinct types, but they shared a lot of the same functionality. I did consider inheritance to clarify them a bit
<FromGitter> <absolutejam_gitlab> but at the minute, I have an arbitrarily nestable object that gets erialized
<FromGitter> <Blacksmoke16> success
<FromGitter> <absolutejam_gitlab> gotta actually parse it now
<FromGitter> <Blacksmoke16> gl
<FromGitter> <absolutejam_gitlab> Probably should have used struct too...
<FromGitter> <absolutejam_gitlab> nvm
<FromGitter> <absolutejam_gitlab> Is there an inbuilt way to format text to certain columns, word wrapping, etc.?
<FromGitter> <absolutejam_gitlab> I've seen `PrettyPrint` but I don't understand its use
<FromGitter> <Blacksmoke16> that would be the way
<FromGitter> <Blacksmoke16> or a custom to_s
<FromGitter> <absolutejam_gitlab> any examples knocking about?
<FromGitter> <absolutejam_gitlab> oh wait a minute
<FromGitter> <absolutejam_gitlab> got it
woodruffw has quit [Ping timeout: 272 seconds]
<FromGitter> <absolutejam_gitlab> I'm lying
<FromGitter> <absolutejam_gitlab> I assumed the following would work: โŽ โŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5c06b853490e334d2d45b7]
<FromGitter> <absolutejam_gitlab> and that would format `some_text`, breaking at column 20 (or before - not sure how the breaking works)
<FromGitter> <j8r> nice!
<FromGitter> <absolutejam_gitlab> ?
<FromGitter> <j8r> or you can just pass `STDOUT`
<FromGitter> <absolutejam_gitlab> I need the result as a string
<FromGitter> <absolutejam_gitlab> or an array is even better
<FromGitter> <j8r> I didn't know PrettyPrint
<FromGitter> <j8r> so `String.build`
<FromGitter> <j8r> sorry, what's the expected result?
<FromGitter> <absolutejam_gitlab> Text split at/before column 20
<FromGitter> <absolutejam_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5c0832bfd2887f532766bd]
<FromGitter> <absolutejam_gitlab> Feel like docs are very much needed for that module
<FromGitter> <j8r> you can use `String#split(limit: 20)`
<FromGitter> <j8r> each column is delimited by a space I suppose
<FromGitter> <j8r> you can also use the block variant, and stop after the 20th iteration
<FromGitter> <absolutejam_gitlab> Hm
<FromGitter> <j8r> can you give an example with the input, and the output wanted?
<FromGitter> <absolutejam_gitlab> I'm converting a sentence/paragraph to line-limited comments
<FromGitter> <absolutejam_gitlab> `# foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz`
<FromGitter> <absolutejam_gitlab> ```# foo bar baz โŽ # foo bar baz โŽ # etc.``` [https://gitter.im/crystal-lang/crystal?at=5d5c093b4e17537f526bfd5f]
<FromGitter> <absolutejam_gitlab> And I don't want to split in the middle of a word
DTZUZO has joined #crystal-lang
alex`` has quit [Ping timeout: 245 seconds]
ht_ has joined #crystal-lang
alex`` has joined #crystal-lang
gangstacat has quit [Quit: ฤœis!]
gangstacat has joined #crystal-lang
<FromGitter> <sam0x17> are the default `HTTP::Cookie` cookies secure as in I can store a logged in user_id and expected it not to be tampered with?
<FromGitter> <sam0x17> I know there is a `secure` boolean property, which I have been setting to true, though it is undocumented
<FromGitter> <Blacksmoke16> secure just makes it so it's only transferred over https
<FromGitter> <sam0x17> ah ok, so it needs some encryption
<FromGitter> <Blacksmoke16> could use JWTs
<FromGitter> <Blacksmoke16> and encode the user id in it
<FromGitter> <sam0x17> I might just do that
<FromGitter> <Blacksmoke16> also could set the `SameSite` value to make it more secure
<FromGitter> <sam0x17> ๐Ÿ‘
<FromGitter> <Blacksmoke16> and http only
<FromGitter> <Blacksmoke16> is this cooking going to be read by js ever?
<FromGitter> <sam0x17> js accesses the API but the cookies dont get read by js
<FromGitter> <Blacksmoke16> do you have to save state to know when a user is logged in?
<FromGitter> <Blacksmoke16> on the front end
<FromGitter> <sam0x17> its an SPA so it has its own state management on frontend
<FromGitter> <Blacksmoke16> gotcha, so it must set something else that tells it a user is "logged in"
<FromGitter> <sam0x17> yeah
<FromGitter> <Blacksmoke16> then yea, http_only, secure, and SameSite would be good
<FromGitter> <sam0x17> should I still encrypt though?
<FromGitter> <sam0x17> I'm assuming yes, since a user could just craft their own cookie to log in as someone else otherwise right?
<FromGitter> <Blacksmoke16> not with JWTs
<FromGitter> <sam0x17> right i mean as in use a JWT
<FromGitter> <sam0x17> kk
<FromGitter> <Blacksmoke16> as if they change it, it changes the signature
<FromGitter> <Blacksmoke16> plus they would need a secret key to sign it
<FromGitter> <sam0x17> yup
<FromGitter> <Blacksmoke16> now granted its not encrypted in the sense you cant see what data is encoded into it
<FromGitter> <Blacksmoke16> its just signed so you can know if it was tampered with
<FromGitter> <sam0x17> oh thats fine that works too
devil_tux has joined #crystal-lang
<FromGitter> <Blacksmoke16> ๐Ÿ‘
flaviodesousa has joined #crystal-lang
flaviodesousa has quit [Quit: KVIrc 5.0.0 Aria http://www.kvirc.net/]
devil_tux has quit [Ping timeout: 244 seconds]
<FromGitter> <kingsleyh> hello
<FromGitter> <kingsleyh> whats the best idomatic Crystal to make this work?
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5c370b142faa4fbd3d8238]
<FromGitter> <kingsleyh> currently it `Error: can't cast Sushi::Core::SlowBlock to Sushi::Core::FastBlock`
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5c373c2cdb146ad60aa8a5]
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
<FromGitter> <kingsleyh> ah ok cool - for some reason I thought case only worked with numbers and strings
<FromGitter> <Blacksmoke16> nope
<FromGitter> <kingsleyh> @Blacksmoke16 can you give me an idiomatic way of handling if a variable is nil? do one thing or do something else
<FromGitter> <Blacksmoke16> `something || something_else`?
<FromGitter> <Blacksmoke16> you have quite a few ways to handle this...
<FromGitter> <kingsleyh> an alternative to: *latest = latest*fast.nil? ? slow : fast
<FromGitter> <Blacksmoke16> that looks fine as is
<FromGitter> <kingsleyh> sorry let me explain better
<FromGitter> <kingsleyh> `_latest = latest_fast_block.nil? ? latest_slow_block : latest_fast_block`
<FromGitter> <kingsleyh> so in the case when lastest_fast_block is not nil - the compiler still thinks that it could be nil so can't use it
<FromGitter> <Blacksmoke16> `_latest = latest_fast_block || latest_slow_block`
<FromGitter> <Blacksmoke16> ?
<FromGitter> <kingsleyh> awesome I like it
<FromGitter> <absolutejam_gitlab> I love those idioms
<FromGitter> <kingsleyh> switching between many languages - so I'm feeling a bit lost at the moment and confused hahah
<FromGitter> <Blacksmoke16> :p
<FromGitter> <kingsleyh> yes these are very concise - very nice!
<FromGitter> <Blacksmoke16> indeed
rohitpaulk has joined #crystal-lang
<FromGitter> <kingsleyh> @Blacksmoke16 what's a nice way of doing tis
<FromGitter> <Blacksmoke16> `variable.try &.some_method`
<FromGitter> <Blacksmoke16> or as always, handle nilability higher up
<FromGitter> <kingsleyh> what happens in this case if variable is nil?
<FromGitter> <kingsleyh> the same as not_nil! - it raises?
<FromGitter> <Blacksmoke16> no
<FromGitter> <Blacksmoke16> just wouldnt do anything
<FromGitter> <fridgerator> crash
<FromGitter> <Blacksmoke16> also no
<FromGitter> <Blacksmoke16> just wouldnt do anything
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Object.html#try(&block)-instance-method
<FromGitter> <fridgerator> i meant his example
<FromGitter> <Blacksmoke16> if the variable is nil it doesnt yield so the block doesnt get executed
<FromGitter> <kingsleyh> @Blacksmoke16 and what would be a nice way of doing that when needed the value back from the method
<FromGitter> <kingsleyh> e.g. *something = foo.not*nil!.some_method
<FromGitter> <Blacksmoke16> `response = (v = variable) ? v.some_method : raise "some exception"`
<FromGitter> <Blacksmoke16> or
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5c4669b059db27dfaf2a6b]
<FromGitter> <Blacksmoke16> or without knowing any other context, try to handle the nilability higher up
<FromGitter> <Blacksmoke16> which would remove the need for checking for nil
<FromGitter> <kingsleyh> yup
<FromGitter> <kingsleyh> Crystal doesn't have Option does it
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <kingsleyh> like Some | None
<FromGitter> <Blacksmoke16> still not sure i follow
<FromGitter> <kingsleyh> Some("apple") or None
<FromGitter> <sam0x17> how would I go about clearing all cookies in HTTP::Repsonse?
<FromGitter> <sam0x17> ^ no, that's a rust thing
<FromGitter> <sam0x17> @kingsleyh
* FromGitter * Blacksmoke16 still doesnt know what thats supposed to do :p
<FromGitter> <sam0x17> that's the way rust deals with nillability
<FromGitter> <Blacksmoke16> like noop if its nil?
<FromGitter> <sam0x17> there is a generic enum `Option<T>` that is either `None` or `Some(T)`
<FromGitter> <sam0x17> rust enums are weird they are really fancy type unions and can have methods and stuff
<FromGitter> <kingsleyh> sorry I do a lot of functional programming in Scala
<FromGitter> <sam0x17> oh, is that a scala thing?
<FromGitter> <sam0x17> I didn't know rust got it from there
<FromGitter> <kingsleyh> and we have Option and Either which lets you wrap a value and then call map, getOrElse etc on it to handle it
<FromGitter> <kingsleyh> which side steps the whole Nil thing
<FromGitter> <sam0x17> yeah crystal is a lot more forgiving at least than rust with that, like you can or things together to get rid of the nil as @Blacksmoke16 demonstrated way above
<FromGitter> <kingsleyh> yep
<FromGitter> <sam0x17> and you can directly call `.as(T)` which in rust would be unsafe
<FromGitter> <Blacksmoke16> and @sam0x17 i dont think there is a way to do that atm?
<FromGitter> <kingsleyh> in Scala I would instead of returning something that could be String | Nil - I would return Option[String] - so I can map around the option of string if it's there - otherwise I can handle the else case
<FromGitter> <sam0x17> the only implication for me is usually whenever I have to read something from a string-keyed hash like thing, I have to check if the key exists first before reading it, and then call `.not_nil`, other than that I typically never have nilable things
<FromGitter> <sam0x17> yeah its basically the same thing, idiomatically
<FromGitter> <Blacksmoke16> @sam0x17
<FromGitter> <sam0x17> since enums in rust/scala are essentially type unions, `String | Nil` literally is the same as `Option[String]` or whatever
<FromGitter> <Blacksmoke16> ```if key = hash["key"]? โŽ # key is here and not nil โŽ else โŽ # key didnt exist โŽ end``` [https://gitter.im/crystal-lang/crystal?at=5d5c484f25764a3642cdec87]
<FromGitter> <kingsleyh> yeah
<FromGitter> <sam0x17> @Blacksmoke16 the `.as(T)` syntax I use all the time
<FromGitter> <Blacksmoke16> i rarely need .as
<FromGitter> <Blacksmoke16> only when dealing with unions
<FromGitter> <sam0x17> yeah, it's this ruby API
<FromGitter> <sam0x17> there is a value in the db that could be `false` or an `Int32` situationally, but never `true`
rohitpaulk has quit [Ping timeout: 246 seconds]
<FromGitter> <sam0x17> so you end end up with some `.as(Int32)`ing
<FromGitter> <Blacksmoke16> false meaning `0`?
<FromGitter> <Blacksmoke16> or like actually `false`
<FromGitter> <sam0x17> ruby decided to treat it as a string field
<FromGitter> <sam0x17> so actually `"false"`
<FromGitter> <Blacksmoke16> :S
<FromGitter> <Blacksmoke16> rip
<FromGitter> <sam0x17> yeah
<FromGitter> <sam0x17> fun
<FromGitter> <Blacksmoke16> hows the Granite conversion going
<FromGitter> <sam0x17> I gave up I have too much custom tooling
<FromGitter> <sam0x17> also tried lucky briefly (which I liked) but then was like meh, time to get back to work
<FromGitter> <Blacksmoke16> :P
<FromGitter> <Blacksmoke16> yea i couldnt imagine it being a trivial amount of work
<FromGitter> <sam0x17> its one of those like now is the time if I'm gonna do it since I've only ported only 15% of the API
<FromGitter> <sam0x17> but I've already ported over 15% of the API
<FromGitter> <sam0x17> lol
<FromGitter> <Blacksmoke16> oh well, maybe v3
<FromGitter> <sam0x17> yeah, or just my next personal project
<FromGitter> <Blacksmoke16> by then Granite + Athena will be ready to rock ha
<FromGitter> <sam0x17> noice
<FromGitter> <Blacksmoke16> @bew came across something else that would be good to include with the assertions
<FromGitter> <sam0x17> yeah I saw you guys going back and forth with that
<FromGitter> <Blacksmoke16> (is what i based it on in the first place)
<FromGitter> <Blacksmoke16> so like `obj.validate ["group1"]` would only runs the assertions assigned to that group
<FromGitter> <sam0x17> and the groups are like lists of fields with certain validations?
<FromGitter> <Blacksmoke16> more like grouping assertions by names
<FromGitter> <Blacksmoke16> so you can run a subset of them
<FromGitter> <sam0x17> oh gotcha
<FromGitter> <sam0x17> yeah its really funny, I didn't really mean to but I ended up writing a bunch of weird custom serialization tooling for this that also uses a groups context
<FromGitter> <sam0x17> *concept
<FromGitter> <sam0x17> it all operates on hashes and then at the end you would supposedly do `.to_json` if that's what you want
<FromGitter> <sam0x17> but the syntax is like:
<FromGitter> <Blacksmoke16> decided to split the serializer (still WIP), and this validation lib
<FromGitter> <sam0x17> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5c4afe79229b63d98fddc6]
<FromGitter> <Blacksmoke16> :thinking:
<FromGitter> <sam0x17> this is a real context I use plus a `:some_property` that I threw in just now for demonstration purposes
<FromGitter> <sam0x17> but basically you can define any number of hash contexts, which internally are just procs that take in a hash and reference to the model and spit out a modified version of the hash
<FromGitter> <sam0x17> and there is tooling for having a "parent" so in the second one we are saying `:extended` is based on `:safe`
<FromGitter> <sam0x17> to use it you would just go `user.to_hash(:extended)`
<FromGitter> <Blacksmoke16> fancy :p
<FromGitter> <sam0x17> the default `.to_hash` with nil passed in just takes the crystal versions of the model fields
<FromGitter> <sam0x17> but yeah getting procs to nest in each other is tricky
<FromGitter> <sam0x17> as a general principle I like to have any string known at compile time to be a symbol, so I often end up writing custom stuff just so I can see lots of symbols everywhere xD
<FromGitter> <sam0x17> which means I should use enums more lol
<FromGitter> <sam0x17> but I like this a lot better than the old rails API, where these extended JSON properties were added literally within the API methods themselves in an ad-hoc sort of way, with code duplication across numerous methods (really bad)
<FromGitter> <sam0x17> serialization should be a model thing, not a controller thing
<FromGitter> <sam0x17> also it makes it so I can use them in non-JSON contexts if I want to, since they are crystal hashes / types
<FromGitter> <sam0x17> I might extract it into a shard and add support for a few ORMs
<FromGitter> <Blacksmoke16> at work we used to have transformer classes for our entities
<FromGitter> <sam0x17> yeah this is probably really similar
<FromGitter> <Blacksmoke16> but lately have been combining the ORM stuff, assertions, and serialization stuff on the entities themselves
<FromGitter> <sam0x17> yeah, I like that approach
<FromGitter> <sam0x17> the only problem with my approach is it relies on a massive and ugly type union, but I may be able to get around that somehow
<FromGitter> <Blacksmoke16> whats the use case for working with hahes?
<FromGitter> <sam0x17> I just like them
<FromGitter> <Blacksmoke16> i always saw that in crystal land as a smell
<FromGitter> <Blacksmoke16> due to the big unions you get and stuff
<FromGitter> <absolutejam_gitlab> Surely it's better to have a defined class unless you need a big, nebulous glob of assorted data
<FromGitter> <absolutejam_gitlab> which is a bit gross
<FromGitter> <sam0x17> they print well, they `.to_json` well, they have real crystal types, but agreed on the unions
<FromGitter> <Blacksmoke16> why not just call `to_json` on your objects?
<FromGitter> <sam0x17> I do at the end
<FromGitter> <Blacksmoke16> vs going from obj to hash to json?
<FromGitter> <sam0x17> a big reason is most orms don't make the fields iterable
<FromGitter> <sam0x17> and I always end up in that situation somehow where I have to iterate over them
<FromGitter> <Blacksmoke16> i must be spoiled from granite
<FromGitter> <sam0x17> and if I'm going to do that, I don't want it to be in JSON land
<FromGitter> <Blacksmoke16> can you not do
<FromGitter> <Blacksmoke16> `User.first!.to_json`?
<FromGitter> <sam0x17> all the orms do that
<FromGitter> <Blacksmoke16> right, so what do you have to iterate over?
<FromGitter> <sam0x17> but you can't do `User.first!.attributes.each do |k, v|`...
<FromGitter> <sam0x17> some can, but most dont
<FromGitter> <Blacksmoke16> sorry, but whats the use case for doing that?
<FromGitter> <Blacksmoke16> to limit the properties that get serialized?
<FromGitter> <sam0x17> often, yes, but my thing does that instead
<FromGitter> <sam0x17> all it needs, (and all any of these systems need) is a clever system of macros where the type union is literally only the types that are actually used with that model's hashes in current code
<FromGitter> <sam0x17> I haven't played with macro-defining the members of a type union before, but I think it would make this a lot better, like overhead wise no use than a `NamedTuple`, but with the advantages of `Hash(Symbol, TypeUnion)`
<FromGitter> <sam0x17> *worse than
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5c4f95fa99e74f6a61c0f0]
<FromGitter> <Blacksmoke16> is my ideal setup i been working towards
<FromGitter> <Blacksmoke16> exclude all properties by default, specify the ones you want serialized
<FromGitter> <Blacksmoke16> also would be that `@[CRS::Groups("group1")]` you could add to only serialize those in a given group
<FromGitter> <sam0x17> yeah with the grouping that fits my needs
<FromGitter> <sam0x17> was basically just typing a long winded way of saying that
<FromGitter> <Blacksmoke16> :P this way you avoid having to use hashes or anything, its all just natively built in
<FromGitter> <sam0x17> yeah, pretty legit
<FromGitter> <Blacksmoke16> thats a valid Granite model btw, other than the`CRS` stuff, as thats still WIP refactor of the current serializer shard i have
<FromGitter> <Blacksmoke16> `@[CrSerializer::Options(expose: true)]` and `@[CrSerializer::ClassOptions(exclusion_policy: CrSerializer::ExclusionPolicy::ExcludeAll)]` is what it is atm
<FromGitter> <Blacksmoke16> will get there one day :P
<FromGitter> <sam0x17> love it, though the names get pretty long lol
<FromGitter> <Blacksmoke16> yea thought of the `CRS` alias to help with that in the new world
<FromGitter> <sam0x17> I like that
<FromGitter> <Blacksmoke16> debating whether to have each "option" be its own annotation, or have it act like `JSON::Field` where you apply all serialization related options into one
<FromGitter> <absolutejam_gitlab> you're such an annotations hoe, haha
<FromGitter> <sam0x17> inevitably, the first one will be better for people who have way too many on the same field
<FromGitter> <absolutejam_gitlab> Do any of the web frameworks use them?
<FromGitter> <Blacksmoke16> *its the future*
<FromGitter> <absolutejam_gitlab> Be good for middleware like auth
<FromGitter> <Blacksmoke16> athena does
<FromGitter> <absolutejam_gitlab> a la Python's Flask
<FromGitter> <Blacksmoke16> only one afaik
<FromGitter> <absolutejam_gitlab> Obviously :P
<FromGitter> <absolutejam_gitlab> Do you work on Crystal proffesionally @Blacksmoke16 ?
<FromGitter> <Blacksmoke16> naw
<FromGitter> <absolutejam_gitlab> professionally *
<FromGitter> <Blacksmoke16> we use http://symfony.com at work
<FromGitter> <absolutejam_gitlab> F
<FromGitter> <absolutejam_gitlab> We use Laravel
<FromGitter> <sam0x17> I do, but as CTO I get to decide what we use xD
<FromGitter> <absolutejam_gitlab> But I'm not a developer
<FromGitter> <Blacksmoke16> i dont mind it, most of my shard ideas comes from it
<FromGitter> <sam0x17> symfony is a new one that I had never heard of
<FromGitter> <Blacksmoke16> has some (IMO slick stuff), that i been putting into athena
<FromGitter> <sam0x17> but makes sense I've been out of PHP ecosystem for over 10 years
<FromGitter> <Blacksmoke16> namely the converters, DI, console commands, the assertion/serialization stuff
<FromGitter> <Blacksmoke16> also the logger shard i did
<FromGitter> <absolutejam_gitlab> monolog?
<FromGitter> <Blacksmoke16> yea
<FromGitter> <Blacksmoke16> my clone of it :P
<FromGitter> <absolutejam_gitlab> crylog right?
<FromGitter> <Blacksmoke16> yea
<FromGitter> <absolutejam_gitlab> I like it, just don't have need for it yet
<FromGitter> <Blacksmoke16> monolog is super cool
<FromGitter> <Blacksmoke16> so flexible and powerful
<FromGitter> <absolutejam_gitlab> I actually quite like Laravel
<FromGitter> <absolutejam_gitlab> just a lot of magic, and I don't always like that. Maybe my inexperience being unable to reason about it all, and I don't use PHPStorm either
<FromGitter> <absolutejam_gitlab> I don't have to write PHP though, so it's not the end of the world
<FromGitter> <sam0x17> I only ever went from scratch with php haha I think back in 2005 ish there weren't any frameworks or I didn't know of any at least everything was like `mysql_connect` and `if($_GET['mode'] == 'blog') { require('blog'); }` and bad stuff like that lolol
<FromGitter> <sam0x17> it was all very very procedural I dont think I even used classes ever
ht_ has quit [Remote host closed the connection]
<FromGitter> <Blacksmoke16> :p
<FromGitter> <Blacksmoke16> rails is like that too with the magic
<FromGitter> <sam0x17> true, tho there is the orm
<FromGitter> <Blacksmoke16> maybe one of you can tell me how can i have a property on a model in rails that doesnt represent a column?
<FromGitter> <Blacksmoke16> can you even do that?
<FromGitter> <sam0x17> I was working with raw mysql engine commands and just manipulating the associative arrays
<FromGitter> <sam0x17> omg yeah there are a bunch of ways
<FromGitter> <sam0x17> you basically use hooks to trick it
<FromGitter> <sam0x17> like a "converter" in rails is easy for example
<FromGitter> <sam0x17> because you can use `self[:db_field]` to access raw fields even if you override them with `def the_field` and `def the_field=(val)`
<FromGitter> <sam0x17> so if you define getters and setters for something that manipulate something in `self[:whatever]`, you've effectively written a converter or a custom property
<FromGitter> <Blacksmoke16> hmm interesting
<FromGitter> <sam0x17> no reason that couldn't carry on in crystal orms ;)
<FromGitter> <Blacksmoke16> i dont even remember what my models looked like
<FromGitter> <sam0x17> here I'll show you an ugly one
<FromGitter> <Blacksmoke16> `Latest commit 0b67aa9 on Jul 10, 2018`
<FromGitter> <Blacksmoke16> didnt think it was that recent ha
<FromGitter> <absolutejam_gitlab> I find symbols quite weird in Crystal
<FromGitter> <Blacksmoke16> there was talk about removing them
<FromGitter> <absolutejam_gitlab> I get them in Ruby and in Elixir they're useful
<FromGitter> <Blacksmoke16> and just having them be specific to autocasting enums
<FromGitter> <absolutejam_gitlab> and every time I think of using them for basic pattern matching, an enum is better
<FromGitter> <sam0x17> https://gist.github.com/sam0x17/d0176cdaaf894757001e542d9826a28d this one is really bad
<FromGitter> <sam0x17> (had to redact it a bit)
<FromGitter> <Blacksmoke16> assuming you know about the symbol => enum feature?
<FromGitter> <absolutejam_gitlab> I do wish there was a bit more pattern matching and destructuring but that's my preference
<FromGitter> <absolutejam_gitlab> Don't think so
<FromGitter> <Blacksmoke16> ๐Ÿ˜ฎ
<FromGitter> <Blacksmoke16> sec
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/7fhu
<FromGitter> <absolutejam_gitlab> like โŽ โŽ ```def log(:err, something : String)``` [https://gitter.im/crystal-lang/crystal?at=5d5c555067969726f935c2f7]
<FromGitter> <Blacksmoke16> can use an symbol, instead of full name of the enum
<FromGitter> <sam0x17> and if you are wondering, yes, `safe_id_constraint` makes it so that a certain range of production ids for that model are off limits to ensure that filenames in aws that are used in production dont get overwritten by anything in development. Yes that bad lol
<FromGitter> <Blacksmoke16> i meant to make a feature request about that
<FromGitter> <Blacksmoke16> allow to type a method arg to a enum member
<FromGitter> <Blacksmoke16> then would be like
<FromGitter> <absolutejam_gitlab> that's weird, @Blacksmoke16
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d5c55b867969726f935c5b8]
<FromGitter> <absolutejam_gitlab> the example you posted
<FromGitter> <absolutejam_gitlab> Yeah, I see Enums doing the same job in Crystal tbh
<FromGitter> <Blacksmoke16> @sam0x17 jeeze
<FromGitter> <absolutejam_gitlab> They're not used as heavily as in Elixir, and Elixir's VM allows reflection on them and shit, which wouldn't really be possible in Crystal
<FromGitter> <absolutejam_gitlab> as they have to be known at compile time and all that
<FromGitter> <Blacksmoke16> current way to do it would be have a log method typed to the enum
<FromGitter> <Blacksmoke16> and inside of it have a clas
<FromGitter> <absolutejam_gitlab> I guess thinking about it, I dunno how destructuring would work
<FromGitter> <absolutejam_gitlab> Because it doesn't rely on hashes/structs & objects like Elixir & JS
<FromGitter> <absolutejam_gitlab> And the associated literals
<FromGitter> <Blacksmoke16> dunno
<FromGitter> <absolutejam_gitlab> i wish `Array(String)` worked the same as `[] of String`
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <absolutejam_gitlab> wait, `.new` is the same right?
<FromGitter> <Blacksmoke16> yes
<FromGitter> <absolutejam_gitlab> it always catches me out
<FromGitter> <absolutejam_gitlab> The former syntax is my preference
<FromGitter> <Blacksmoke16> so just use that then
<FromGitter> <Blacksmoke16> `arr = Array(String).new`
<FromGitter> <absolutejam_gitlab> Yeah, was just saying, haha
<FromGitter> <Blacksmoke16> fair enough :p
<FromGitter> <j8r> I remember to have proposed to remove them
<FromGitter> <j8r> but`["a", "b"] of String | Int32` is more efficient than using `Array(String | Int32){"a", "b"}`
<FromGitter> <j8r> Don't think it's a fair case, because it's very rarely used
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang