RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.26.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> <girng> @Heaven31415 wow, taking a look now
<FromGitter> <girng> @Heaven31415 where can I find your main AI class
silmanduin has joined #crystal-lang
<FromGitter> <Heaven31415> It's very small right now, but gonna expand it soon when I will add scripting to my game :P
<FromGitter> <girng> like a custom scripting language for ai only?
<FromGitter> <girng> that crystal interprets?
<FromGitter> <Heaven31415> I hope nobody will kill me for linking to some other language here : P
<FromGitter> <girng> that's really interesting tbh
<FromGitter> <Heaven31415> Wren is a scripting language and I'm planning to embed it's interpreter in my game
<FromGitter> <girng> so it's kinda like lua?
<FromGitter> <girng> that syntax reeminds me of crystal lol
<FromGitter> <Heaven31415> Yes, but it's pure OOP and a bit faster than lua (not counting lua jit)
<FromGitter> <girng> They have Fiber.yield hahhh
<FromGitter> <Heaven31415> and they have blocks
<FromGitter> <Heaven31415> I already successfully exposed some crystal classes and structs to this interpreter and everything works fine
<FromGitter> <Heaven31415> even was able to use crystal file from Wren :P
<FromGitter> <girng> what does weakref do in your ai carrier?
<FromGitter> <Heaven31415> every unit in my game has ai and every ai has access to unit
<FromGitter> <girng> "to unit" what's this mean?
<FromGitter> <girng> what unit?
<FromGitter> <Heaven31415> it's a base object in my game
<FromGitter> <girng> ohhh
<FromGitter> <Heaven31415> Ship is an example of Unit
<FromGitter> <girng> so the WeakRef just store references basically?
<FromGitter> <Heaven31415> exactly, but as it's name says it's a WeakRef
<FromGitter> <Heaven31415> without it, unit points to ai, ai to unit
<FromGitter> <Heaven31415> and garbage collector cannot clear it properly
<FromGitter> <girng> interesting, in Godot engine there is a weak ref but i've never had to use it. i was just curious to see it used in crystal
<FromGitter> <Heaven31415> Compiler will tell you
<FromGitter> <Heaven31415> It told me everything about this problem :P
<FromGitter> <Heaven31415> I didn't even had to think about it
<FromGitter> <girng> LOL
<FromGitter> <Heaven31415> It can detect this kind of problem I guess
<FromGitter> <girng> Ayee. I think the compiler teaches me more than what I learned on my own rofl!
<FromGitter> <Heaven31415> Ok, I'm mistaken, compiler didn't detect that
<FromGitter> <Heaven31415> You will get a warning from GC when this kind of situation happen XD
<FromGitter> <girng> Do you use enums in your ai?
<FromGitter> <Heaven31415> not in my ai, but I have few of them in my game
<FromGitter> <girng> ic, just curious cause of the enemy state. in that video i linked, he has patrol/chase states as enums
<FromGitter> <girng> i'm gonna do patrol/chase/attack, and then refine attack, to make the engagement level higher for the player
<FromGitter> <Heaven31415> sure, make a video or something when you are done, so people can see it :P
<FromGitter> <Blacksmoke16> make a nested enum, then ested enum would switch to decimals 1, 2, 3.1, 3.2 etc /s
marmotini has joined #crystal-lang
<FromGitter> <Heaven31415> @girng if you are on Ubuntu you can easily play my game if you want
marmotini_ has quit [Ping timeout: 246 seconds]
<FromGitter> <girng> you can nest enums?
<FromGitter> <Blacksmoke16> idk, prob not :p
<FromGitter> <girng> lol :P
non-aristotelian has quit [Quit: non-aristotelian]
silmanduin has quit [Quit: WeeChat 2.2]
akaiiro has quit [Remote host closed the connection]
<FromGitter> <girng> how many bits does a boolean take up compared to 1 enum property?
<FromGitter> <girng> > An enum is a set of integer values, where each value has an associated name. For example: โŽ nvm
DTZUZO_ has quit [Ping timeout: 245 seconds]
<FromGitter> <dscottboggs_gitlab> > how many bits does a boolean take up compared to 1 enum property? (in crystal lang)
<FromGitter> <girng> can i initalize a class by a string?
<FromGitter> <girng> that's in a variable
<FromGitter> <girng> actually that might be a bad idea nvm
<FromGitter> <girng> inheritance is powerful af
_whitelogger has joined #crystal-lang
ua has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 272 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
marmotini has quit [Ping timeout: 244 seconds]
rohitpaulk has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
sevensidedmarble has quit [Ping timeout: 276 seconds]
sevensidedmarble has joined #crystal-lang
<FromGitter> <proyb6> We need more LibC function: strchr, strrchr
rohitpaulk has quit [Ping timeout: 244 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 272 seconds]
rohitpaulk has joined #crystal-lang
Raimondii has joined #crystal-lang
ashirase has quit [Ping timeout: 272 seconds]
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
ashirase has joined #crystal-lang
<FromGitter> <yxhuvud> Proyb6: why? Are those not doing stuff that is trivial and without overhead to implement in pure Crystal?
<FromGitter> <fusillicode_twitter> @vladfaust sorry for the bother but does validations actually support sharing validations (not rules, actual validations) across structs?
<FromGitter> <fusillicode_twitter> just to give a little bit of context: โŽ โŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bcaf329271506518d3f7beb]
<FromGitter> <vladfaust> Didn't you forget to call `previous_def`in `def validate`?
<FromGitter> <fusillicode_twitter> ...I bet I forget considering how dumb I am...let me check
<FromGitter> <fusillicode_twitter> mmm, even with an explicit `def validate previous_def` it seems that there's something wrong ๐Ÿค”
<FromGitter> <fusillicode_twitter> https://play.crystal-lang.org/#/r/5a27
<FromGitter> <vladfaust> Alright, to not bother others, please join https://gitter.im/vladfaust/Lobby for discussing my shards
<FromGitter> <fusillicode_twitter> ๐Ÿ‘
<FromGitter> <vladfaust> Lol. Twitter asked to add a birth day to crystal jobs account. Quoting "even if it's your cat or business". I set Sep 22nd 2018 and now it's blocked: "Twitter requires all users to be over the age of 13 on order to create an account."
<FromGitter> <fusillicode_twitter> Lol but don't worry Twitter is not alone. Apple requires that too even for companies accounts
<FromGitter> <fusillicode_twitter> And in the same way, if your company is "too young" than you're screwed XD
<FromGitter> <vladfaust> :(
<FromGitter> <proyb6> @yxhuvud I was thinking whether I could extract part of the string without creating a new string in C โŽ โŽ ```result << full_url[5..-1] #Crystal code``` โŽ โŽ If that's possible in C lib strstr without the "needle" string in the haysack url. PHP strstr has a similar API ... [https://gitter.im/crystal-lang/crystal?at=5bcafd6d271506518d3fba48]
lele_ has left #crystal-lang ["Leaving"]
<FromGitter> <bajro17> how to get only first character
<FromGitter> <bajro17> I know I can remove it with "string".lchop and how to get it?
<FromGitter> <bajro17> can I do like [0]
<FromGitter> <bajro17> it work :)
<FromGitter> <bajro17> I find solution :)
rohitpaulk has quit [Ping timeout: 246 seconds]
<FromGitter> <proyb6> is it correct appear to be UInt? How do I print the string in result? โŽ โŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bcb1df0c08b8b306743ffba]
<FromGitter> <proyb6> I'm curious what is the actual code to offset result by len of find as in: โŽ โŽ ```C code: โŽ result += strlen(find);``` [https://gitter.im/crystal-lang/crystal?at=5bcb1eca069fca52a56691da]
<oprypin> proyb6, i have no idea what you're saying
<oprypin> the code seems to be valid, though of course nobody should actually be calling these C functions directly
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
marmotini_ has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <ljuti> Question about specs. I end up writing a lot of type checks in the specs. Is this normal or am I doing something wrong?
rohitpaulk has quit [Ping timeout: 260 seconds]
marmotini_ has quit [Ping timeout: 252 seconds]
<FromGitter> <fusillicode_twitter> mmm
<FromGitter> <fusillicode_twitter> Actually I didn't find myself in the same situation @ljuti ๐Ÿค”
<FromGitter> <fusillicode_twitter> and right now I'm writing a few spec myself ๐Ÿ˜…
<FromGitter> <ljuti> For example, I have a class that builds bunch of object
<FromGitter> <ljuti> Some of those objects in the class are required, some may be optional, depending on the data the class was initialized with
<FromGitter> <fusillicode_twitter> ok clear
<FromGitter> <ljuti> For example, thereโ€™s a contact object inside the class
<FromGitter> <fusillicode_twitter> that may or may not be present right?
<FromGitter> <ljuti> Unless I verify first in the spec that the contact object exists (itโ€™s required), the following expectation will fail
<FromGitter> <ljuti> ```expect(contact.name).to eq(โ€œLauriโ€)```
<FromGitter> <fusillicode_twitter> I see
<FromGitter> <ljuti> Or more appropriately, with subject. I use spec2
<FromGitter> <ljuti> So, this works fine in spec
<FromGitter> <ljuti> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bcb32e7435c2a518ed8a0a5]
<FromGitter> <fusillicode_twitter> okok, well I think that your "type checks" can be simply boiled down to different context
<FromGitter> <fusillicode_twitter> well your example can be rewritten by checking only for the actual presence of the Contact
DTZUZO has joined #crystal-lang
<FromGitter> <fusillicode_twitter> not its type
<FromGitter> <ljuti> Yeah
<FromGitter> <fusillicode_twitter> something like `expect(contact.name).to eq("Lauri") unless subject.contact.nil?`
<FromGitter> <ljuti> Maybe Iโ€™m crossing the boundary of class responsibilities when I try to peek into the class
<FromGitter> <fusillicode_twitter> well this can also be true
<FromGitter> <ljuti> ```expect(subject.contact).to be_a(Contact)```
<FromGitter> <ljuti> This works fine
<FromGitter> <fusillicode_twitter> wait how can it work?
<FromGitter> <fusillicode_twitter> `subject.contact` should be `(Contact | Nil)`
<FromGitter> <fusillicode_twitter> I mean if it is optional then it means that it can be `nil`
<FromGitter> <ljuti> If the `Contact` object wasnโ€™t properly built, the method would return `nil` or raise an exception actually, because `Contact` is required
<FromGitter> <fusillicode_twitter> mmm
<FromGitter> <fusillicode_twitter> well then in your specs you have 2 different contexts
<FromGitter> <fusillicode_twitter> the happy path with the Contact
<FromGitter> <fusillicode_twitter> the unhappy one without it
<FromGitter> <fusillicode_twitter> I think that the type checks may be factored out in some setup helpers that you can use to model the 2 different contexts
<FromGitter> <ljuti> Yeah
<FromGitter> <ljuti> And maybe I shouldnโ€™t peek into the other classes in specs that donโ€™t concern the implementation of those classes :)
<FromGitter> <fusillicode_twitter> true that ;)
rohitpaulk has joined #crystal-lang
marmotini_ has joined #crystal-lang
<Yxhuvud> @proyb6: but strchr doesn't work on crystal strings (due to encodings and multibyte characters etc). They might work on Slices, but then it takes like 3 lines of code to reproduce the method without involving libc.
<FromGitter> <proyb6> I see Bew mentioned Slices is not utf8 friendly, how do you suggest it can handle?
<oprypin> why would it not be friendly
<oprypin> what are you actually trying to do?
<oprypin> 2018-10-16 10:48:47 <bew> @proyb6 you can try using `Slice`, you can get a slice from a String with `String#to_slice`, but note that it'll not play nicely with UTF-8
<oprypin> ok yeah, that's misleading
<FromGitter> <proyb6> I have previously want to find if there is alternative to return only "proyb" to HTTP server response without creating new string? โŽ ```context.response << "/user/proyb"[5..-1]```
<FromGitter> <proyb6> Yeah, I keen to try vanilla :)
<oprypin> proyb6, there is no way to return a string without creating the string
<FromGitter> <dscottboggs_gitlab> do these numbers at the end of this output mean anything usefult?
<oprypin> proyb6, are you coming from PHP by chance?
<FromGitter> <proyb6> Haven't touch PHP for a decade
<oprypin> ok
marmotini_ has quit [Ping timeout: 252 seconds]
<FromGitter> <dscottboggs_gitlab> I was trying to log to the console and got that instead
<FromGitter> <proyb6> Is Bew suggest string_view in C++17 possible?
<oprypin> there is no string view in crystal. Slice is a bit like that but then what you're working with is not a string in the normal sense
<oprypin> in C++ only bytestrings are first-class, and in Crystal only Unicode strings are first-class
<FromGitter> <proyb6> I see
<FromGitter> <dscottboggs_gitlab> well yeah but it has #each_codepoint and to_slice so you can sort of use either
marmotini_ has joined #crystal-lang
<FromGitter> <proyb6> Let me see, like this? โŽ โŽ ```"".each_codepoint do โŽ ... โŽ end``` [https://gitter.im/crystal-lang/crystal?at=5bcb46af435c2a518ed92219]
<oprypin> proyb, how about this one: `if path =~ %r{/user/(\w+)}; puts $1; end`
<FromGitter> <dscottboggs_gitlab> ```"some string".each_codepoint do |char| โŽ ... โŽ end``` [https://gitter.im/crystal-lang/crystal?at=5bcb46cbae7be940168a22a9]
<oprypin> this is neither here nor there. there is still no way to produce a string `"proyb"` without creating it.
<FromGitter> <dscottboggs_gitlab> oooh nice I didn't know about %r{}
<FromGitter> <proyb6> @oprypin I tried a similar one in gist which is slower, loss of iirc 10K req/s
<FromGitter> <proyb6> with the %r%
<oprypin> https://carc.in/#/r/5a34 - in action. yeah, it's not micro-super-fast but nobody cares about that
<oprypin> as soon as your application starts doing anything real, this action will take less than 0.01% of the response time
<FromGitter> <dscottboggs_gitlab> oprypin where does $1 come from in that?
<FromGitter> <proyb6> yeah, I assume the range in [5..-1] is close to Go lang in my single core test on macOS.
<oprypin> dscottboggs_gitlab, cant find docs for it :/ it's a special global-like variable that `=~` sets
<oprypin> oh, that's because it's not in docs lol
<oprypin> dscottboggs_gitlab, https://crystal-lang.org/api/0.26.1/Regex.html look for `$1`
<oprypin> maybe this will be useful too https://github.com/crystal-lang/crystal/issues/4715
<oprypin> (as long as you keep in mind that `$0` was actually removed, as requested there)
<FromGitter> <Schniz> @straight-shoota thanks for the help with the nightly :) your script is awesome
<FromGitter> <Schniz> also, @vladfaust I just made a simple redirection service for circleci artifacts, https://circleci-artifacts.now.sh/ - it should be easy to distribute documentation that is built using `crystal docs`
<FromGitter> <dscottboggs_gitlab> oprypin I'm glad they removed $0 and kept $1...$N
<oprypin> well it's $0..$N now :p
<FromGitter> <dscottboggs_gitlab> well that's fair, it's not so confusing now
<FromGitter> <dscottboggs_gitlab> wouldn't that cause weird bugs with stuff that was written where `$0==PROGRAM_NAME`?
<FromGitter> <dscottboggs_gitlab> Is there a way to debug crystal code at all?
<FromGitter> <proyb6> @oprypin How do you suggest about Slice?
<FromGitter> <j8r> $1 could also be removed for Regexes, its a bit too magical
<FromGitter> <j8r> Ans I don't know any other place where it's used
<FromGitter> <dscottboggs_gitlab> Oh! actually, I got it working, surprisingly!
<FromGitter> <dscottboggs_gitlab> I think the last time I tried to debug I got a weird bug that only showed up when I tried building the debug version and that's why I gave up but this time it worked
marmotini_ has quit [Ping timeout: 252 seconds]
<oprypin> proyb6, you have not provided any appropriate use case for Slice
<oprypin> please just use string
marmotini_ has joined #crystal-lang
<FromGitter> <proyb6> That's the best suggestion to use string. Thanks!
Yxhuvud has quit [Remote host closed the connection]
Yxhuvud has joined #crystal-lang
zorp has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
akaiiro has joined #crystal-lang
Yxhuvud has quit [Remote host closed the connection]
Yxhuvud has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
akaiiro has joined #crystal-lang
akaiiro has quit [Ping timeout: 252 seconds]
DTZUZO has quit [Ping timeout: 245 seconds]
wontruefree has joined #crystal-lang
wontruefree has quit [Client Quit]
<FromGitter> <j8r> @ezrast what do you mean to access matched in case/when?
marmotini has joined #crystal-lang
marmotini_ has quit [Ping timeout: 268 seconds]
<FromGitter> <bajro17> can someone tell me why this dont work its so weird
<oprypin> haha weird indeed
<oprypin> bajro17, `':' != ":"`
<oprypin> thats why i prefer `starts_with?`
<FromGitter> <bajro17> I was think in crystal single ' is not allowed at all
<FromGitter> <bajro17> f***g golang again I mix
<FromGitter> <bajro17> I'm so sorry
<FromGitter> <bajro17> this happen already few time in my brain golang and crystal mix
<FromGitter> <bajro17> :(
<oprypin> np
<FromGitter> <j8r> @bajro17 you also code in go?
<FromGitter> <bajro17> yes
<oprypin> it would be possible for the compiler to detect this and say "this condition can never be true"
<FromGitter> <j8r> this is more a the role of a static analysis tool like ameba
<FromGitter> <bajro17> @j8r you need something about golang?
<FromGitter> <j8r> @bajro17 nope, wondering on what projects you work :)
<FromGitter> <bajro17> oh my bro honestly I killing my self
<FromGitter> <bajro17> work on 6 different projects at once
<FromGitter> <bajro17> golang, laravel, crystal
<FromGitter> <vladfaust> @Schniz thanks!
<FromGitter> <bajro17> then brain sometimes disappoint me and mix all stuff in one big mess
<FromGitter> <j8r> humans are notoriously bad for multi tasking
<FromGitter> <bajro17> yes I know but need money for marriage
<FromGitter> <bajro17> hahah
<FromGitter> <j8r> @bajro17 congrats ๐Ÿ˜ฎ
<FromGitter> <bajro17> Thank you so much @j8r <3
<FromGitter> <j8r> you marry Crystal finally , lol
<FromGitter> <bajro17> hahahah she is not crystal but almost perfect like Crystal hahha
<FromGitter> <bajro17> please dont screenshot this :D
<oprypin> it's permanently saved on both sides so no big deal
<FromGitter> <bajro17> I must pay everything its tradition
<oprypin> ok that's unhealthy
<FromGitter> <j8r> so you pays with money, she pays "in nature" ๐Ÿ˜
<FromGitter> <bajro17> hahahha
<FromGitter> <bajro17> it go something like that :D
<FromGitter> <j8r> in some other countries that's the opposite, with the dowry
<FromGitter> <j8r> in country sound like a male dowry
<FromGitter> <bajro17> yes for example I know Nigeria female parents need buy house for daughter when she marry
<FromGitter> <ezrast> @j8r I updated my comment with an example
<oprypin> that changed my opinion from almost-thumbs-down to actually thumbs-down
<FromGitter> <j8r> @ezrast what about md =
<FromGitter> <Heaven31415> Hi
<FromGitter> <j8r> hum not sure, wait @ezrast
marmotini has quit [Ping timeout: 260 seconds]
<FromGitter> <j8r> @ezrast there is https://carc.in/#/r/5a4z
Yxhuvud has quit [Remote host closed the connection]
Yxhuvud has joined #crystal-lang
<FromGitter> <ezrast> I mean, that's the code the `case` statement is syntactic sugar for, yeah
<FromGitter> <ezrast> If you think that's just as good then might as well remove `case` from the language entirely
<FromGitter> <j8r> agree, nice yep
<FromGitter> <j8r> the point is: does somebody can explain what is this dollar?
<FromGitter> <j8r> i'm feeling everyone use it without knowing what this magic really comes from
<oprypin> well i know where it comes from
<FromGitter> <j8r> I'm talking the average Crystal dev, or beginner :)
<oprypin> just add it to docs
<FromGitter> <j8r> how does it works?
<oprypin> > a variable that leaks by one scope level https://carc.in/#/r/2d82
<oprypin> > `$1`, `$2`... โ€” rewritten to `$~.not_nil![1]`
<FromGitter> <j8r> thanks, feels... a bit weird IMO
<FromGitter> <ezrast> I wouldn't mind being able to do something along the lines of https://carc.in/#/r/5a53
<FromGitter> <ezrast> not that syntax of course
marmotini has joined #crystal-lang
marmotini has quit [Ping timeout: 252 seconds]
<FromGitter> <j8r> i suspect some magic used for `when /regex/`
<livcd> will the Windows support be ready until this christmas ? :D
<FromGitter> <j8r> no
<FromGitter> <Heaven31415> if you help, it can be!
<oprypin> j8r, there is no more magic, just that `===` also contains `$~ = something` inside it
<livcd> what is the biggest blocker ?
<FromGitter> <Heaven31415> I think you should ask @RX14
<FromGitter> <j8r> @ezrast what do you think of https://carc.in/#/r/5a6d
<FromGitter> <Heaven31415> @oprypin Hey, if an object foo, has an instance variable x, is it okay to access it like this? `foo.@x`, because it looks to me like direct of instance variable without need to getter.
<oprypin> Heaven31415, it will work but it is not "okay"
<FromGitter> <Heaven31415> it might break in the future?
<FromGitter> <Heaven31415> or you just mean, that it's not the right way :P
<oprypin> it might
<oprypin> actually https://github.com/crystal-lang/crystal/issues/6066 concluded with not removing it
<oprypin> but it is still always seen as a last resort
<FromGitter> <Heaven31415> thanks for sharing that issue, never seen that
ashirase has quit [Read error: Connection reset by peer]
ashirase has joined #crystal-lang
ua has joined #crystal-lang
<oprypin> j8r, im telling you, it's not a global variable https://carc.in/#/r/5a75
<FromGitter> <j8r> yep, I updated the example
<oprypin> in contrast with https://carc.in/#/r/5a79
<FromGitter> <j8r> but that's not ideal to modify String's ivar
<FromGitter> <j8r> There is no best solution for now :(
<FromGitter> <Heaven31415> Will it be possible in the future or is it even wanted to add type restrictions to macros? So I can for example create a macro which will only take NumberLiteral and otherwise fail.
<oprypin> Heaven31415, the macro type system is a bit too sketchy to have that work well. but nothing prevents you from writing your own check
<FromGitter> <Heaven31415> Maybe standard library should have this kind of facility? Something like assert which will just ensure that you have a proper type of AST node.
<FromGitter> <bajro17> is it possible to make array of touples with fixed size
<FromGitter> <j8r> of course
<FromGitter> <bajro17> how to declare array is this correct [] of Tuple
<oprypin> [] of {Int32, Int32, String}
<oprypin> as usual, maybe you want to share your end goal
<FromGitter> <bajro17> Thank you it look good :)
<FromGitter> <j8r> https://carc.in/#/r/5a7g
<FromGitter> <bajro17> I will when finish this router I want make it on my way
<FromGitter> <j8r> do use you radix?
<FromGitter> <bajro17> I know there is so much other but I want make my to understand how everything work
<FromGitter> <bajro17> no I dont use radix I want my :D
<FromGitter> <bajro17> to I can understand everything how work because I mostly do web development
<FromGitter> <bajro17> its good sometimes use frameworks but if I want learn crystal good and do web I want know how every line of code work
<FromGitter> <j8r> what do you use instead of a radix tree? Often its used in HTTP router
<FromGitter> <bajro17> I build my own tree this is reason why all time ask about regex or some other silly things :D
<FromGitter> <bajro17> also is it possible with tuple something like {...String}
<FromGitter> <bajro17> to I can add how much I want strings?
<oprypin> no, that's against the definition of a tuple. then you have to use an array
<FromGitter> <dscottboggs_gitlab> > which will just ensure that you have a proper type of AST node. โŽ โŽ I feel like if your macro is this sketchy it shouldn't be a macro
<FromGitter> <bajro17> no problem then array of array will do job
<FromGitter> <dscottboggs_gitlab> Maybe you want StaticArray @bajro17 ?
<oprypin> "add how much I want strings" - probably not
<FromGitter> <bajro17> url can be like "blog/1/edit"
<FromGitter> <dscottboggs_gitlab> sorry I didn't read close enough I thought you were talking about an array of fixed-length arrays
<FromGitter> <bajro17> but also someone can be little crazy and do like "blog/post/1/comment/2/freakinguser/4"
<FromGitter> <Heaven31415> https://play.crystal-lang.org/#/r/5a7r I tried to implement checking macro type
<FromGitter> <Heaven31415> @dscottboggs_gitlab Well I'm using macro[] as a syntax sugar for constructor
<FromGitter> <j8r> @bajro17 for what do you use array of array?
* FromGitter * dscottboggs_gitlab shrugs
<oprypin> Heaven31415, why not just use constructor directly O_o
<FromGitter> <dscottboggs_gitlab> I guess it could be either way
<FromGitter> <dscottboggs_gitlab> but your example is a runtime error as opposed to a compile-time error
<oprypin> dscottboggs_gitlab, the example is a compile-time error
<FromGitter> <Heaven31415> You can construct with ordinary constructor too, it's a tad bit shorter with macro[]
<FromGitter> <dscottboggs_gitlab> oh, that's really cool, I didn't realize you could raise a compile-time error in a macro, that makes a lot of sense
<oprypin> Heaven31415, shorter does not mean better
<FromGitter> <Heaven31415> and this class is heavily used that's why every letter count for me
<oprypin> oh well
<oprypin> but still, why check in the macro if you're gonna get compile time errors for wrong argument anyway?
<oprypin> also like, it could just be `def self.[](x); return self.new(x); end`
<FromGitter> <Heaven31415> This is really good
<FromGitter> <Heaven31415> I was checking in macros to get a easier to read error message
<FromGitter> <bajro17> @j8r to I can have something like router[["GET","blog/:id", "blog.show"],["PATCH","blog/:id/edit", "blog.edit"],["DELETE","blog/:id/delete", "blog.delete"]]
<FromGitter> <dscottboggs_gitlab> why not just use JSON, YAML, TOML or a Hash representation of your endpoints and use the appropriate serialization?
<FromGitter> <bajro17> @dscottboggs_gitlab I dont know what is faster I think array is faster then do extra jobs
<FromGitter> <bajro17> with parsing
<FromGitter> <dscottboggs_gitlab> you're probably right, but I think readability is more important than a minor speed bump for something that will only be parsed once
<FromGitter> <dscottboggs_gitlab> this is actually one of my worries with this language, with how flexible it is, is that the code will often be obscured by strange syntactical choices like in C++
<FromGitter> <bajro17> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bcb98da069fca52a569a490]
<FromGitter> <bajro17> I think its not so bad
<FromGitter> <j8r> @bajro17 why not an array of objects? (like Array(Route))
<oprypin> good idea
<FromGitter> <j8r> Array(Array) will certainly hurt performance if you have lots of routes
<FromGitter> <bajro17> @j8r then to not use array at all?
<oprypin> we're telling you that you should use array of (something that is not an array)
<oprypin> `[Route.new("GET","blog/:id", "blog.show"), Route.new("PATCH","blog/:id/edit", "blog.edit"), Route.new("DELETE","blog/:id/delete", "blog.delete")]`
<oprypin> not recommended but better than array of arrays: `[{"GET","blog/:id", "blog.show"}, {"PATCH","blog/:id/edit", "blog.edit"}, {"DELETE","blog/:id/delete", "blog.delete"}]`
<FromGitter> <j8r> If possible. But here, there is a recurring schema: `http_verb`, `path`, `action`, and using schemas are more efficient
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter> <j8r> the data can be more efficiently accessed by avoiding to search in an array
<FromGitter> <bajro17> maybe this is best solution
<FromGitter> <dscottboggs_gitlab> would SomeObject with `property` methods, or a namedtuple with the equivalent properties, be more efficient?
<FromGitter> <j8r> and if `Route` is a struct, you'll save even more heap memory, and less work for the GC :)
<FromGitter> <bajro17> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bcb9bed82893a2f3b12f827]
<FromGitter> <bajro17> I can to avoid declare method
<FromGitter> <dscottboggs_gitlab> I thought class/Objects were more efficient than structs because the former were passed by reference an the latter by copy?
<FromGitter> <bajro17> in documentation write better use struct when its possible
<oprypin> dscottboggs_gitlab, there is no blanket reply. short story is that `struct` and `NamedTuple` end up being represented in memory exactly the same. avoid namedtuple if at all possible.
<FromGitter> <bajro17> because its more efficient
<FromGitter> <Heaven31415> because structs are allocated on stack if they are not in array or something similar as opposed to classes which are always allocated on heap which is slower
<oprypin> `class` is passed by reference, and a reference is a level of indirection, it also requires allocation and garbage collection
<FromGitter> <dscottboggs_gitlab> @bajro17 I like it, because if you wanted to be even more explicit you could use named arguments, or you could choose ordered for conciseness or efficiency
<oprypin> `struct` is local and direct, but needs to be passed by copy
<FromGitter> <dscottboggs_gitlab> oh I see
<oprypin> choose whatever is appropriate.
<FromGitter> <dscottboggs_gitlab> so most of the time for few properties a struct would be better but as it gets more complex it could be better to use a class?
<oprypin> number of properties is usually not a good metric, and also if that makes you feel like changing from `struct` to `class` then maybe it should have been a `class` in the first place
<FromGitter> <j8r> @dscottboggs_gitlab generally, that depends if you want to share a modifiable object.
<oprypin> the way i approach it is just make it a class, unless i see "oh yeah, this totally feels like a struct". what this "feels" means, i cannot tell you exactly, but you know, `struct Point; property x, y; end` is the typical example
<FromGitter> <j8r> on my side its not really common, so I nearly always use structs. But maybe yes in you case
<oprypin> if it's mutable, can't be a struct
<FromGitter> <dscottboggs_gitlab> > *<oprypin>* if it's mutable, can't be a struct โŽ โŽ ahhh I see
<FromGitter> <j8r> @dscottboggs_gitlab working on https://github.com/crystal-lang/crystal-book/pull/290
<FromGitter> <j8r> you may be interested
<FromGitter> <bajro17> this is what I have until now
<FromGitter> <bajro17> if someone can review it and see if there is any possible improvement
<FromGitter> <bajro17> I find most of this code in one shard I cant remember where
<FromGitter> <bajro17> now work on this params
<FromGitter> <bajro17> to I can call it also from โŽ โŽ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bcb9f2bae7be940168c504c]
<FromGitter> <bajro17> I think easiest way will be just to include https://crystal-lang.org/api/0.26.1/HTTP/Params.html
<FromGitter> <dscottboggs_gitlab> I actually like that a little better than kemal's way of doing things where you have macros affecting a global value. this lets you have multiple routers if you want in one module.
<FromGitter> <bajro17> this is simples code I can find
<oprypin> i brought it up because most frameworks are insanely complicated
<FromGitter> <bajro17> I just search some simple code to I can understand it much is possible
<FromGitter> <bajro17> yes exactly so complicated
<FromGitter> <j8r> @bajro17 i think there is something like a tree for routing, and then handle the verbs
sagax has quit [Ping timeout: 252 seconds]
<FromGitter> <bajro17> I can maybe make it like this https://play.crystal-lang.org/#/r/5a83
<FromGitter> <bajro17> and from this :id to make ?id=1
<FromGitter> <bajro17> and then with http params easy parse it
zorp has quit [Remote host closed the connection]
zorp has joined #crystal-lang
zorp has quit [Ping timeout: 252 seconds]
zorp has joined #crystal-lang