<FromGitter>
<watzon> @tenebrousedge you mean adding it to `Regex` and `String`?
<FromGitter>
<tenebrousedge> yes
<FromGitter>
<tenebrousedge> it seems like there should be prior discussion
<FromGitter>
<watzon> What would be the point? Just returning a bool instead of a `Regex::MatchData?`
<FromGitter>
<tenebrousedge> yes, and avoiding setting the pseudo-globals
<FromGitter>
<watzon> Hmm that does make sense
<FromGitter>
<tenebrousedge> sometimes one needs to test if an element is present in a string, but the match itself is not used
<FromGitter>
<tenebrousedge> Ruby added it in 2.4 I believe
<FromGitter>
<tenebrousedge> the downside of course is that you then have `=~`, `match?`, `match`, and `===`
return0e_ has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
ht_ has joined #crystal-lang
ht_ has quit [Quit: ht_]
ua has quit [Ping timeout: 240 seconds]
alexherbo2 has joined #crystal-lang
alexherbo2 is now known as alex```
ua has joined #crystal-lang
duane has quit [Ping timeout: 240 seconds]
sagax has quit [Quit: Konversation terminated!]
duane has joined #crystal-lang
<FromGitter>
<asterite> yes, `match?` would be good to have. Probably `matches?`, though
<FromGitter>
<tenebrousedge> has there been previous discussion of this?
<FromGitter>
<yxhuvud> could it be handled by escape analysis if that is ever implemented? or is the issue that it sets $-variables which wouldn't escape?
<FromGitter>
<yxhuvud> (or which *would* escape? Never can remember which way it is)
HumanG33k has joined #crystal-lang
duane has quit [Ping timeout: 252 seconds]
HumanG33k has quit [Remote host closed the connection]
<FromGitter>
<tenebrousedge> clearly it has borkens
return0e has joined #crystal-lang
return0e_ has quit [Ping timeout: 240 seconds]
<FromGitter>
<wontruefree> is forum.crystal-lang.org down? It is keeps timing out on my computer
<FromGitter>
<tenebrousedge> seems to be, yes
<FromGitter>
<wontruefree> wonder if it is discourse or us
<FromGitter>
<christopherzimmerman> @kinxer took your advice and started working a lot more on documentation now that I have most of the core functionality worked out. Would definitely appreciate feedback on the quickstart guide (https://crystal-data.github.io/bottle/user/quickstart.html).
ht_ has joined #crystal-lang
DTZUZO has joined #crystal-lang
DTZUZO has quit [Quit: WeeChat 2.0]
alex``` has quit [Ping timeout: 265 seconds]
alex``` has joined #crystal-lang
duane has quit [Ping timeout: 276 seconds]
ht_ has quit [Remote host closed the connection]
ht_ has joined #crystal-lang
alex```5 has joined #crystal-lang
alex``` has quit [Ping timeout: 240 seconds]
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
alex```59 has joined #crystal-lang
alex```5 has quit [Ping timeout: 252 seconds]
<FromGitter>
<Daniel-Worrall> what does `--prelude` do in crystal docs?
<FromGitter>
<Daniel-Worrall> I went looking if there's an option to be able to have inline source for docs (maybe expandable box)
<FromGitter>
<Blacksmoke16> it controls like what stuff is required by default
<FromGitter>
<Daniel-Worrall> What kind of method do I need to use `@foo ||= bar` where bar is a method that can return either true or false and `@foo` is instantiated with `nil`
<FromGitter>
<Daniel-Worrall> I want to cache the bool at runtime on request
<FromGitter>
<Blacksmoke16> prob could do `getter foo : Bool { bar }`
<FromGitter>
<tenebrousedge> ^
<FromGitter>
<Blacksmoke16> would be lazily set the first time its called
<FromGitter>
<tenebrousedge> or `getter?`
<FromGitter>
<tenebrousedge> if it's a bool I'd do the predicate
<FromGitter>
<Daniel-Worrall> yeah, I'll be using `getter?`
<FromGitter>
<Blacksmoke16> `getter foo : Bool { bar }` then
<FromGitter>
<Daniel-Worrall> I just didn't put the `?` for the question
<FromGitter>
<Daniel-Worrall> abstract foo and bar and such
<FromGitter>
<Daniel-Worrall> ty guys
<FromGitter>
<tenebrousedge> np
<FromGitter>
<Daniel-Worrall> okay, strictly API structuring question. The method to fetch the output should be called what? `private_foo?`? `fetch_foo?`?
<FromGitter>
<Daniel-Worrall> I would call it `foo?` if I could have public and private methods named the same
<FromGitter>
<Daniel-Worrall> `parse_foo?`?
<FromGitter>
<tenebrousedge> you could have `foo` and `foo?`
<FromGitter>
<tenebrousedge> or `get_foo`
<FromGitter>
<Daniel-Worrall> How would you do it?
<FromGitter>
<tenebrousedge> maybe `_foo`, if we allow initial underscores in method names
<FromGitter>
<tenebrousedge> which looks like a thing
<FromGitter>
<Daniel-Worrall> hm, do you think `_foo` or `_foo?`
<FromGitter>
<Daniel-Worrall> I do like the `_` idea
<FromGitter>
<Blacksmoke16> only if you're 100% sure they wont be nil
<FromGitter>
<Daniel-Worrall> In my example, I'll be using tags anywhere from 1-5 times
<FromGitter>
<Daniel-Worrall> 100%
<FromGitter>
<Daniel-Worrall> According to the API I'm using
<FromGitter>
<Daniel-Worrall> If they're nil, I have much bigger problems
<FromGitter>
<Daniel-Worrall> idk if it'd be worse to be storing a pointer than calling it each time
<FromGitter>
<Daniel-Worrall> seems like a memory impact vs cpu impact question
<FromGitter>
<tenebrousedge> is that likely to be a big performance difference in your app?
<FromGitter>
<Daniel-Worrall> I guess that's my question
<FromGitter>
<Daniel-Worrall> Performance is the top priority
<FromGitter>
<tenebrousedge> unless you have some reason to believe otherwise, assume that the answer is that performance differences are negligible. Write clear code first, then profile it to find hotspots
<FromGitter>
<Daniel-Worrall> what sort of difference to memory does having extra properties and pointers have
<FromGitter>
<Daniel-Worrall> yeah, let's not bog myself down with details
<FromGitter>
<Daniel-Worrall> They are going to be extremely short lived instances so we'll probably take the memory hit
<FromGitter>
<Daniel-Worrall> Pog, I can use private getters too
<FromGitter>
<Daniel-Worrall> Oh, I just realised since I'm using a single line of code in the private methods, I can just put them in the lazy load block
* FromGitter
* tenebrousedge nods
<FromGitter>
<Daniel-Worrall> all the macro deliciousness
<FromGitter>
<Daniel-Worrall> Would `"#string"[1...]` be the right way to chop off the first char
<Yxhuvud>
Daniel-Worrall: I'd tend to refactor if I get chains of not_nil!. You can avoid them by wrapping things in if statements or in methods that you make certain will return only what you want.
alexherbo2 has joined #crystal-lang
Vexatos has quit [Remote host closed the connection]
Vexatos has joined #crystal-lang
<FromGitter>
<Daniel-Worrall> Can I call private methods in a spec?
<FromGitter>
<tenebrousedge> you can open the class and make them public
<FromGitter>
<watzon> That's usually what you'd use `#send` for in Ruby
<FromGitter>
<watzon> But Crystal doesn't have that built in
<FromGitter>
<tenebrousedge> and won't
<FromGitter>
<kinxer> Yeah, I generally just re-open the class in the `spec_helper.cr`
<FromGitter>
<Daniel-Worrall> Right so how would I do that
<FromGitter>
<Daniel-Worrall> for the record, testing private methods is bad practice. I'm only using it to call them for testing other methods
<FromGitter>
<kinxer> 👍
alexherbo25 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
<FromGitter>
<tenebrousedge> @Daniel-Worrall you seem to have a good understanding of general coding principles; I figured you had a good reason for asking
<FromGitter>
<Daniel-Worrall> well ty, I just struggle with some bits. :^)
<FromGitter>
<Daniel-Worrall> The more I ask now, the less I ask later
<FromGitter>
<Daniel-Worrall> I really do wish I had taken comp sci at uni though
<FromGitter>
<tenebrousedge> oh?
<FromGitter>
<Daniel-Worrall> would have given me a much broader understanding
<FromGitter>
<Daniel-Worrall> Formal education has its benefits
<FromGitter>
<tenebrousedge> have you gone through SCIP?
<FromGitter>
<tenebrousedge> or *NAND to Tetris* ?
<FromGitter>
<Daniel-Worrall> Not heard of either of those. Everything is "self-taught".
<FromGitter>
<tenebrousedge> myself as well. There's a lot of MIT and Stanford coursework that's available online
<FromGitter>
<tenebrousedge> https://xuanji.appspot.com/isicp/ this is an interactive version of the classic *Structure and Interpretation of Computer Programs*
<FromGitter>
<tenebrousedge> *NAND to Tetris* is another good foundational course, sort of a more machine-oriented approach
<FromGitter>
<straight-shoota> It essentially says there is a value of type whatever is specified, but the value is actually garbage. So it must not be used until there is a proper value assigned. This is pretty low level stuff and usually meant for performance optimization. The alternative would be to make the variable nilable but then you'd have to have nil checks later.
<FromGitter>
<tenebrousedge> it's also useful for recursive procs
<FromGitter>
<kinxer> @tenebrousedge Interesting. Do you have an example?
<FromGitter>
<TedTran15_twitter> I see, thanks guys. I was thinking about it in the wrong way after reading the docs, for some reason I was thinking it just gave it a random value that was of a certain type and I tried to use the uninitialized value and it resulted in a segfault
<FromGitter>
<tenebrousedge> see the end of the answer
<FromGitter>
<straight-shoota> In the minmax methods of #8490 it essentially reserves a space for storing the comparison value and the loop branch for `i == 0` makes sure that on the first iteration an actual value is assigned and the variable will only be read afterwards (in the second iteration or after the loop).
<FromGitter>
<tenebrousedge> I wouldn't say ill-advised. More like "highly situational"
<FromGitter>
<kinxer> That's a fair point, though that sounds a bit like a positive spin on it. I'm also not sure if there are more concise ways of expressing what the macro is doing, since this is one of my first real forays into macros.
<FromGitter>
<jwoertink> With json, I can do `JSON::Any.new({} of String => JSON::Any)` to create just an empty JSON::Any
<FromGitter>
<jwoertink> what's the equivalent for an array of hashes?
<FromGitter>
<jwoertink> `JSON::Any.new([] of Hash(String, String))`