straight-shoota has quit [Ping timeout: 264 seconds]
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
rocx has quit [Ping timeout: 260 seconds]
ryanprior has joined #crystal-lang
<FromGitter>
<ryanprior> Can I bootstrap the Crystal compiler without installing a binary Crystal compiler? I ask because I'm interested in building a bootstrap package.
<oprypin>
bestwebua, the error is compile-time. crystal doesn't let you call `(DummyClass | Nil).some_method` because indeed, Nil doesn't have such a method. what if you forgot to call `set_class_var`? does the error make sense then?
<FromGitter>
<naqvis> @bestwebua you have told compiler that `class_var` might be `Nil` or it might reference to instance of `OtherDummyClass`. So you will have to handle for cases where this class var is nil. Quick and simple way could be to use `try` like ⏎ ⏎ ```p DummyClass.class_var.try &.some_method``` ⏎ ⏎ above code will work when `class_var` is not nil [https://gitter.im/crystal
<oprypin>
that link shows you the explicit way. `if (temp = DummyClass.class_var); temp.some_method; end` - will work
<oprypin>
crude way to move the error away from compiletime would be `def self.class_var; @@class_var.not_nil!; end`. and i think this is equivalent: `class_getter! class_var`
<oprypin>
yes.
<oprypin>
and a nice debugging tool would be to `p typeof(DummyClass.class_var)` - it's the compile-time type rather than just `p DummyClass.class_var.class`
<FromGitter>
<bestwebua> Thanks guys, now everything fell into place) 🍻
<FromGitter>
<chosenhood> Okay that's great, but how would it be done if I had something like this? ⏎ MyCustomParser returns a custom object type. The issue I have is that the compiler says it can be MyObjectType | Nil. ⏎ I only want to add objects of MyObjectType, no nils. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5eb14c8b97338850a2eaac1f]
<FromGitter>
<tenebrousedge> this is an x y problem
<FromGitter>
<tenebrousedge> you don't need a macro to get rid of `Nil`
<FromGitter>
<tenebrousedge> and you can't create a variable at compile time using runtime methods
<FromGitter>
<tenebrousedge> if you know the return value from `MyCustomParser.parse` will never be nil, use `not_nil!`
<jhass>
kingsleyh: I guess you want to embed the files at compile time?
<FromGitter>
<chosenhood> Yeah that's what I want
<jhass>
whoops, chosenhood^, sorry for the wrong highlight
<jhass>
so, do they also neeed to be parsed at compile time or is that okay at runtime?
<FromGitter>
<chosenhood> I have a custom parser which builds an object based on the json files. ⏎ I need them parsed in compile time.
<jhass>
I would question that need. But anyways. Then you want to come up with a serialization format for the parsed object, something you can store in a literal (hash, string, array, tuple, named tuple, integer, float, combination thereof)
<jhass>
then write a run macro (see the docs linked above, same page) that reads the file, parses it and outputs crystal code that builds up this literal
<FromGitter>
<chosenhood> Before that I had a runtime variation of this code which did the same logic like in the macro but I also checked if my object is truthy or not before adding it to the hash
<jhass>
then you can reinstantiate the object at runtime from the literal
<jhass>
your run macro also could output code that builds up your custom objects with literals as arguments
<jhass>
but as you can see this gets quite complex, so I would suggest to reevaluate if the probably fairly minor gains in runtime speed/application boot time is worth the development and code commplexity
<jhass>
also if it's any substantial data this approach will likely negatively affect compilation speed and binary size
<jhass>
compared to a pure runtime approach or a hybrid approach where you just store the file contents as string literals and parse those at runtime
<FromGitter>
<chosenhood> Your idea with literals seems interesting.
<jhass>
so a first step is to develop a crystal program that outputs crystal code that builds up the structures you want. Basically something that compiles if you do crystal run generator.cr | crystal run
<FromGitter>
<chosenhood> Those jsons are basically big config files and there is many of them. It's kinda better if it's included in compile time and later there is no dealing with reading those files, relative paths etc. Had big problems when my code is run in docker and so on as it is a shard.
<jhass>
then you can use that program to either just pregenerate files in your library or hook it up to the run macro
<jhass>
if that's your only concern I would strongly argue in favor of just storing them as stringliterals with the read_file macro and parsing them at runtime
<jhass>
much simpler to maintain
<jhass>
and reason about
<FromGitter>
<chosenhood> Yup. I like that approach with literals.
<FromGitter>
<chosenhood> My main concern is avoiding dealing with reading files in runtime
<straight-shoota>
rucksack might probably has an advantage when packing huge payloads, though
<FromGitter>
<Uzay-G> this is pretty noob but how do we get the length of an array in crystal?
<FromGitter>
<Uzay-G> I tried `.length` but I guess not
<FromGitter>
<tenebrousedge> `size`
<FromGitter>
<Uzay-G> thanks
<FromGitter>
<Uzay-G> oh also my problem yesterday was because for some reason postgres was connecting on ipv6. Thanks for your help :)
<FromGitter>
<tenebrousedge> np glad you got it working
<FromGitter>
<3n-k1> does specifying a branch other than master in shard.yml even work? i've never been able to get it working, even though the branch absolutely exists on the remote
<FromGitter>
<Uzay-G> try deleting `lib/`and then running `shards update`
<FromGitter>
<Uzay-G> it worked for me
<FromGitter>
<3n-k1> that did it, thanks!
<FromGitter>
<Uzay-G> is there a way to like have multi-line strings?
<FromGitter>
<bararchy> Hi everyone, if there are among you those who are interested in Application Security and infosec in general, starting tomorrow we will do a two days push of changes and improvements to https://github.com/NeuraLegion/broken_crystals, this project is meant to help Crystal devs improve application security and avoid common pit-falls, If you have any idea on cool situations, scenarios or security issues you wish
<FromGitter>
... to add to the project let us know either in twitter (@neuralegion) or over at the Github issues. Happy and secured development!
<sorcus>
bararchy: :thumbs_up:
<FromGitter>
<bararchy> Thanks sorcus
_ht has quit [Quit: _ht]
sagax has quit [Ping timeout: 260 seconds]
<FromGitter>
<Uzay-G> Hey, what do you guys think is the most mature and efficient web framework in crystal?
<FromGitter>
<Uzay-G> I'm planning on building something with it and wanted to know your opinions
<FromGitter>
<Blacksmoke16> depends on what your needs/requirements are
<FromGitter>
<Blacksmoke16> you have a few choices :p
<FromGitter>
<Uzay-G> like what?
<FromGitter>
<Uzay-G> which one have you used that are good?
<robacarp>
all of them
<FromGitter>
<Uzay-G> all of them are good? 😆
<robacarp>
but really, it depends on how complex your application is going to be
<FromGitter>
<watzon> It's really between Lucky and Amber if you're looking for a full framework
<FromGitter>
<watzon> Athena too if you just want an API
<FromGitter>
<Blacksmoke16> API or server rendered? Looking for something simple or full stack? etc
<FromGitter>
<watzon> Personally I prefer Lucky
<FromGitter>
<Uzay-G> full stack I guess with server rendering and an api
<FromGitter>
<Uzay-G> but more backend focused
<FromGitter>
<Uzay-G> I might use lucky yeah
<FromGitter>
<watzon> Lucky is nicely integrated with laravel mix too
<FromGitter>
<watzon> It's got you covered on both ends pretty well
<FromGitter>
<Blacksmoke16> Athena's the way to go 😉
<FromGitter>
<Blacksmoke16> takes a diff approach compared to other frameworks, so has some unique stuff at least work checking out
<FromGitter>
<Blacksmoke16> worth*
go|dfish has joined #crystal-lang
<FromGitter>
<Blacksmoke16> id be happy to answer any questions etc as well
<FromGitter>
<watzon> What happened to gring? Did he disappear again?
<FromGitter>
<Blacksmoke16> (PS im biased, Athena is mine :S)
<FromGitter>
<Blacksmoke16> he comes around every so often, says `goodmorning`, or `crystal time` then disappears again :P
<FromGitter>
<Blacksmoke16> so id imagine he's up to something haha
<FromGitter>
<watzon> Trying to mention him doesn't show his new username anymore haha
<FromGitter>
<watzon> I need to chat with a game dev though
<FromGitter>
<Blacksmoke16> @ImAHopelessDev_gitlab @watzon needs you
<FromGitter>
<watzon> Weird, his name wouldn't come up for me haha
<FromGitter>
<Blacksmoke16> had to scroll up to find it
<FromGitter>
<Blacksmoke16> ah, i missed the `client.on_message_create do |message|`
<FromGitter>
<Blacksmoke16> well fwiw `OptionParser` can be used for any arg array
<FromGitter>
<Uzay-G> oh nice
<FromGitter>
<Uzay-G> what does fwiw mean lol
<FromGitter>
<Blacksmoke16> default is just `ARGV`
<FromGitter>
<Blacksmoke16> for whatever its worth
<FromGitter>
<Blacksmoke16> ah nvm, would require `-` based args like for a cli
<FromGitter>
<straight-shoota> @Uzay-G If you're not too strongly attached to the name, I'd recommend to change to an uncontested name while it's still fresh
<FromGitter>
<Uzay-G> well idt there are any discord bots named `onyx`
<FromGitter>
<straight-shoota> No, but crystal shards =)
<FromGitter>
<kinxer> Sure, but it's not gonna help people find your thing if there are other, unrelated things with the same name. Like, I probably shouldn't start a self-hosted digital journal project named "Markdown"; that name is already decidedly taken, even if it's something totally different.
<FromGitter>
<watzon> Yeah it's best to be unique in as many aspects as possible to set your project apart from others