RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.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
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jemc has quit [Ping timeout: 240 seconds]
ua has quit [Ping timeout: 250 seconds]
ua has joined #crystal-lang
<FromGitter> <girng> the crystal playground helps so much. i use it to work on isolated code, then stick it into my main project
<FromGitter> <Blacksmoke16> Indeed
<FromGitter> <Blacksmoke16> Can run a local version as well
<FromGitter> <girng> yeah, i think @dscottboggs_gitlab helped me with that several weeks ago
<FromGitter> <girng> funny thing is, it's slower than the official playground. prob bcz the online playground is running on native linux not WSL LOL
<FromGitter> <dscottboggs_gitlab> I almost always have a `crystal play` running in the backrgound
<FromGitter> <dscottboggs_gitlab> > native linux not WSL ⏎ ⏎ well, yeah, why would you use windows ;)
<FromGitter> <girng> so i always use the online version lol. but once i go on a native linux i'll def prob use crystal play haha
<FromGitter> <girng> @dscottboggs_gitlab basically my current workflow is innate and navigating the OS's UI is all done subconsciously. i just don't want to change 😱
Creatornator has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> that's super fair
<FromGitter> <dscottboggs_gitlab> linux desktops often don't even have decent support for like tweaking things in the UI. Some of the desktops are great but there's definitely an expectation that you'll be like...ok with using the Bash shell and editing config files to change setttings.
<FromGitter> <dscottboggs_gitlab> Except for elementary OS but that's not really a developer workstation kinda system
<FromGitter> <girng> yeah, and compile times are causing a small hiccup in workflow. around 5-8 seconds now. this makes me want to install a native linux OS on a separate SSD, and just boot into that for development. then i can still boot into windows to test the released version of the game. it's going to be released on windows, but have linux support as well. the game launcher patches the game automatically and downloads the
<FromGitter> ... correct binaries/patch files depending on the OS. so i will always need a windows OS to test everything
<FromGitter> <girng> after looking at the results in my WSL benchmark thread, i really want to see the difference on a native linux OS with this i7 2600 😺
DTZUZO_ is now known as DTZUZO
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
<FromGitter> <gwu_gitlab> can i paste some code and have someone examine it?
<FromGitter> <gwu_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c6cbcfe85b7eb4569fd9475]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
<FromGitter> <Blacksmoke16> yea this blog post is paying off, fixing some bugs im finding along the way :)
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
_whitelogger has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <girng> this is kinda random.. but https://play.crystal-lang.org/#/r/6b6e/edit is it possible to make `||` work with 0?
<FromGitter> <girng> actually, gonna use `default` here http://crystal-lang.github.io/crystal-db/api/0.5.1/DB.html#mapping-macro
<FromGitter> <Blacksmoke16> want to to display 5 if its *not* 0 correct?
<FromGitter> <Blacksmoke16> ok
<FromGitter> <girng> if it is 0, yah
<FromGitter> <girng> like javascript's ||
<FromGitter> <girng> but let me see if this `default` thing works
<FromGitter> <Blacksmoke16> ok
<FromGitter> <girng> lulz, nope the `default` property for db.mapping doesn't work. i guess it's because it comes back as 0, not nil
<FromGitter> <girng> i keep thinking 0 is nil LOLz
<FromGitter> <girng> `default: value to use if the property is missing in the result set, or if it's null`
<FromGitter> <Blacksmoke16> rip
<FromGitter> <girng> well, gonna add a one liner if then lol
rohitpaulk has quit [Remote host closed the connection]
<FromGitter> <grantspeelman> Anyone here able to help me with Jennifer and using converter? ⏎ Please have a look at imdrasil/jennifer.cr#220
<devil_tux> is there an api for validating json structures in Crystal?
<devil_tux> begin//rescue on JSON.parse(*) doesnt play nicely, JSON.parse("test") is not rescued (aka is valid)
<FromGitter> <Blacksmoke16> meaning like that `password` is no blank etc?
<FromGitter> <Blacksmoke16> er no, you mean like missing fields and stuff
<FromGitter> <Blacksmoke16> its not rescued since its valid json
<devil_tux> doesnt seems to be a valid json: enter test @ https://jsonlint.com/
<devil_tux> sorry, here https://jsonlint.com/?json=test
<devil_tux> didnt know sharing the payload is possible
<FromGitter> <Blacksmoke16> well thats not, because you have quotes in your example
laaron- has quit [Remote host closed the connection]
<FromGitter> <Blacksmoke16> You could use the `JSON::Serializable` stuff, https://play.crystal-lang.org/#/r/6b6y
<FromGitter> <Blacksmoke16> then catch the `JSON::MappingError` and parse out the data
<devil_tux> i'm aware of serializable, does it work on generic tho?
<devil_tux> the json structure im not aware of
<FromGitter> <Blacksmoke16> in that case you're out of luck
<FromGitter> <Blacksmoke16> as you would have to know the structure ahead of time
laaron has joined #crystal-lang
<devil_tux> hmm
<devil_tux> how true is schema which match first line to { and last line to }?
<devil_tux> first line == first char
<FromGitter> <Blacksmoke16> pull parse can do that
<devil_tux> ah gotcha
<devil_tux> what method is that again?
<devil_tux> read_begin_object?
<FromGitter> <Blacksmoke16> well sorry, it can consume an obj, but to validate it like that im not sure
<FromGitter> <Blacksmoke16> but yea, would start off with `read_begin_object`
<devil_tux> roger :>
<FromGitter> <Blacksmoke16> nice
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c6ce6d41f14630421ecd588]
<FromGitter> <Blacksmoke16> rip
<FromGitter> <Blacksmoke16> what about it?
<FromGitter> <girng> @Blacksmoke16 oh you found a bug O_o
<FromGitter> <girng> @Blacksmoke16 oh, i just totally forgot about the ternary operator haha
<FromGitter> <Blacksmoke16> nice
<FromGitter> <Blacksmoke16> yea came across that while working on the blog tutorial post
<FromGitter> <Blacksmoke16> guess we're not hashing password for now ha
<FromGitter> <girng> can i have a link to your blog ?
<FromGitter> <Blacksmoke16> is just on dev.to
<FromGitter> <Blacksmoke16> but isnt done yet, ill be sure to link it around when it is complete :)
<FromGitter> <girng> oh this is an interesting site
<FromGitter> <girng> like twitter for developers?
<FromGitter> <Blacksmoke16> sure
gwosix has quit [Ping timeout: 246 seconds]
<FromGitter> <girng> eh, hashtags threw me off
<FromGitter> <girng> i'm signing up
<FromGitter> <girng> they have no crystal hashtag
<FromGitter> <Blacksmoke16> they do
<FromGitter> <Blacksmoke16> #crystal
gwosix has joined #crystal-lang
<FromGitter> <Blacksmoke16> anyway im off to bed
<FromGitter> <girng> hmm they should add it to the new user sign up page, it's not there
<FromGitter> <girng> example, this (https://i.gyazo.com/5a41270b55d6914396f977770f7d512f.png) page, no matches for crystal
<FromGitter> <girng> ok gn
gwosix has quit [Ping timeout: 268 seconds]
<devil_tux> I'm getting Error: unknown argument 'arg' no matter how I run it (crystal run script.cr arg, script.cr -- arg, etc.) or whichever shebang I try
<devil_tux> ah ya I forgot, its 7:40am, hackers are sleeping rn
<FromGitter> <j8r> I dont see the point of having a Crystal Playground vs having a test.cr file to test code?
Vexatos has quit [Ping timeout: 246 seconds]
<FromGitter> <anamba> @j8r being able to see return values on each line maybe?
DTZUZO has quit [Ping timeout: 246 seconds]
<FromGitter> <j8r> Yes it may be useful for some people. I don't really need it
<devil_tux> i cant wrap my head around this https://gist.github.com/duraki/13fe5387744da36fc2d6481741a74ece
<devil_tux> tried recreating on the playground but strangely, it works :s https://play.crystal-lang.org/#/r/6b98
<devil_tux> I'd appreciate any points, lost all my hair through the night
<FromGitter> <j8r> do you use the same Crystal version?
<devil_tux> yup, first thing I checked, I'm on latest release MacOS through brew
<devil_tux> is it possible that `INT` in my case is a method returning struct
<FromGitter> <j8r> works for me on Linux
<devil_tux> err is: undefined method 'value' for Foo.class (compile-time type is BaseClass+.class)
<FromGitter> <j8r> you have copy pasted the playground in a file, and executed it?
<devil_tux> j8r: the code is dummy snippet/translation of business code, let me try to recreate it 1:1
<FromGitter> <j8r> I can't help you much if there is no snippet reproducing the issue :/
<devil_tux> j8r: gotcha! here is a non-working snippet: https://play.crystal-lang.org/#/r/6b9p
<devil_tux> two issues arise, added output for both.. will probably need a run on local machine since `ENV` plays a role
<FromGitter> <j8r> what's the result you expect?
<FromGitter> <j8r> it would also help to reduce the example 😅
<devil_tux> j8r: the example is pretty small imo; crystal spec ./file should iterate through each of CLASSES value, create a new instance and execute `hi` method; CLASSES=Foo crystal spec ./file (with CLASSES env pre-appended), it shall create a new instance of just that class and run hi method
<FromGitter> <j8r> why you use constants and not macro variables?
<devil_tux> does it make a difference? i think I tried that
<FromGitter> <j8r> I don't think too, just a question
<FromGitter> <j8r> sorry I don't really see the problem
<FromGitter> <j8r> I don't use much inheritance btw
<devil_tux> welp, time for some github, right?
<devil_tux> seems pretty off/strange
<FromGitter> <Prutheus> Hello. I have that byte sequence `"[48_u8, 51_u8, 47_u8, 48_u8, 51_u8, 47_u8, 50_u8, 48_u8, 49_u8, 57_u8, 10_u8, 50_u8, 48_u8, 58_u8, 48_u8, 48_u8, 58_u8, 48_u8, 48_u8]”` what is nothign else than that string: `03/03/2019\n20:00:00` … however, if I want to parse that string to time via `Time.parse_utc(t, "%d/%m/%Y\\n%H:%M:%S”)` I get the error: `#<Time::Format::Error:Unexpected char: '\n' at 10:
<FromGitter> ... "03/03/2019>>\n20:00:00”>`
<FromGitter> <Prutheus> how to solve that?
<FromGitter> <maiha> No needs to escape "\n". Try `"%d/%m/%Y\n%H:%M:%S"`
ashirase has quit [Ping timeout: 257 seconds]
ashirase has joined #crystal-lang
<FromGitter> <j8r> devil_tux the forum would be a better place i think
Vexatos has joined #crystal-lang
<FromGitter> <vladfaust> @bararchy btw, GitHub banned that user
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <vladfaust> Guys, could you please thumb up, or better comment, on this issue -- https://github.com/gothinkster/realworld/issues/223
DTZUZO has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> @vladfaust did you mean `ENV` instead of `ARG` in your Dockerfile? https://docs.docker.com/engine/reference/builder/#using-arg-variables
devil_tux has quit [Ping timeout: 246 seconds]
<FromGitter> <alex-lairan> Hi, ⏎ ⏎ I got trouble with HTTPS post. ⏎ ⏎ This is my error : ... [https://gitter.im/crystal-lang/crystal?at=5c6d531de5eeec0d9b989a5f]
<FromGitter> <alex-lairan> ```➜ ~ pacman -Qo /usr/lib/libssl.so ⏎ /usr/lib/libssl.so is owned by openssl 1.1.1.a-1``` [https://gitter.im/crystal-lang/crystal?at=5c6d572235c7a5042281ed15]
<FromGitter> <dscottboggs_gitlab> that's really common for people to have issues with different versions of libssl
<FromGitter> <dscottboggs_gitlab> my system appears to have both 1.0.0 and 1.1.0
<FromGitter> <dscottboggs_gitlab> uhh.... ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c6d598b9e430b308699c1fa]
<FromGitter> <dscottboggs_gitlab> wait shit
sz0 has joined #crystal-lang
<FromGitter> <alex-lairan> Migrate from 0.26 to 0.27 fixed the problem ^^
<FromGitter> <dscottboggs_gitlab> according to `crystal eval 'require "openssl"; puts LibSSL::OPENSSL_VERSION'` my crystal is using v1.1.0, so if they're using semver then there shouldn't be any breaking changes -- I'd file an issue @alex-lairan
<FromGitter> <dscottboggs_gitlab> OH well then there you go!
<FromGitter> <dscottboggs_gitlab> haha
<FromGitter> <dscottboggs_gitlab> are you on manjaro then or just hadn't run `pacman -Syu` in a while?
<FromGitter> <alex-lairan> I use crenv for crystal versions :D
<FromGitter> <dscottboggs_gitlab> oh I see
<FromGitter> <dscottboggs_gitlab> I didn't realize that was a thing
<FromGitter> <alex-lairan> I have production app, I can't migrate each projects each time, so I'm playing with different versions :D
<FromGitter> <bararchy> Is there a safe way to get object in array index? (as in arrray[4]?) that will return a nil and not an exception
Creatornator has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> > I can't migrate each projects each time ⏎ ⏎ meh, I haven't personally run into too many breaking changes in the past several versions of crystal. `SecureRandom` to `Random::Secure`, stuff like that. I just update my crystal version when a new one comes out and update everything. Whatever's best for you though of course, it's cool that there's a crenv project for people who don't have the time
<FromGitter> ... to do all of that.
<FromGitter> <dscottboggs_gitlab> @bararchy `[]?` doesn't work?
<FromGitter> <bararchy> raises an exception on invalid index
<FromGitter> <dscottboggs_gitlab> ...really??
* FromGitter * dscottboggs_gitlab goes to the playground
<FromGitter> <bararchy> hmmmmm
<FromGitter> <bararchy> nvm seems to work on playground
<FromGitter> <bararchy> wtf
<FromGitter> <dscottboggs_gitlab> `crystal --version`?
<FromGitter> <bararchy> my bad, overlooked something XD bussines as usual
<FromGitter> <dscottboggs_gitlab> yeah I do that all the time. :p
<FromGitter> <alex-lairan> @dscottboggs_gitlab not a lot of breaking changes, but a lot of dependency update ;)
<FromGitter> <dscottboggs_gitlab> oh I see, yes, most shards are pretty unstable
hightower2 has quit [Ping timeout: 268 seconds]
<FromGitter> <girng> @vladfaust i gave that a thumbsup
rohitpaulk has joined #crystal-lang
<FromGitter> <girng> only need to use `@instancevariable` inside a class, if you are modifying the value, correct?
<FromGitter> <silmanduin66> Is it possible to upload pictures with crystal / amber ?
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
laaron has quit [Remote host closed the connection]
<FromGitter> <girng> i guess i am correct, https://play.crystal-lang.org/#/r/6be6
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> @girng using `@ivar` directly sets the value, doing `ivar = xxx` calls the setter
<z64> you need to write `self.experience = amount` to call the setter
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6be7
<FromGitter> <Blacksmoke16> ah, beat me to it :p
<FromGitter> <Blacksmoke16> were basically just creating a local variable there
<FromGitter> <girng> alright, thanks. i just really pass the class by reference to methods and use dot notation, instead of modifying the ivars directly in the class
<FromGitter> <girng> but i'm starting to do the latter now
lvmbdv has quit [Ping timeout: 244 seconds]
lvmbdv has joined #crystal-lang
<FromGitter> <girng> what's the difference between line 7 and 8 here? https://play.crystal-lang.org/#/r/6bei if line 7 returns 13, then it's returning the instance variable's value? then why do operations to modify the variable need a `@`?
<FromGitter> <konovod> line 7 calls getter, line 8 returns variable.
<z64> the `property` macro creates a method that is `def experience; @experience; end`; it returns the *value* of the ivar, not a reference the ivar itself
<FromGitter> <girng> awwww, so it's returning the value not a reference, that's why the `@` is needed to change it!!
<FromGitter> <girng> aww makes much more sense now knowing that `def experience; @experience; end;` is basically there :O
azuri5 has joined #crystal-lang
<FromGitter> <konovod> i was hit by this thing (creating local variable instead of calling setter) several times, as e.g. pascal or c# doesn't work this way. And it's sad that it's impossible to detect by compiler. But well, that's how the language works
<FromGitter> <girng> i actually do get an error if i try to modify it without the @, i guess t hat's a good thing because otherwise it would just be changing a value lol
<FromGitter> <girng> "i'm giving my player experience each time i run this method, why isn't his exp values changing!?!?"
<FromGitter> <girng> 😆
<FromGitter> <konovod> yeah
<FromGitter> <girng> reminds me of this one nasty issue blacksmoke or @dscottboggs_gitlab helped me find a solution for a couple weeks ago (or last month?) of assigning a default array literal to a property or whatever
Jenz has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> @girng https://crystal-lang.org/api/0.27.2/Object.html#property%28%2Anames%2C%26block%29-macro
<FromGitter> <dscottboggs_gitlab> I don't recall us talking about that so it probably was @Blacksmoke16
<Jenz> lmao @bew
<FromGitter> <Blacksmoke16> boom https://play.crystal-lang.org/#/r/6bf6
<FromGitter> <Blacksmoke16> reproduced
<FromGitter> <j8r> good example of abusing aliases @bew 👍
<FromGitter> <Blacksmoke16> see if i can reduce it more
<FromGitter> <dscottboggs_gitlab> oh wow that's not good
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6bfc best i can do
<FromGitter> <dscottboggs_gitlab> It'd be convenient to have a `lazy_property propname : PropType` method that expanded to ⏎ ⏎ ```@propname : PropType? = nil``` [https://gitter.im/crystal-lang/crystal?at=5c6d7c0ac4da4a11f588b8d2]
<Jenz> @dscottboggs_gitlab: property? propname : PropType
<FromGitter> <dscottboggs_gitlab> It'd be convenient to have a `lazy_property propname : PropType = default` method that expanded to ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c6d7c48c4da4a11f588bbc9]
<FromGitter> <dscottboggs_gitlab> or something like that
<FromGitter> <dscottboggs_gitlab> I have found myself using that pattern a few times
<Jenz> Oh
<Jenz> Yeah that's quite common
<z64> thats what `getter`, etc. does with a block
<FromGitter> <Blacksmoke16> i lied, https://play.crystal-lang.org/#/r/6bg4 further reduced
<Jenz> Ooh, nice, z64
<Jenz> property too it seems: https://carc.in/#/r/6bg7
<FromGitter> <girng> honestly, i like passing by reference and using dot notation better.. is that bad??
<z64> it's not usually a hard choice of "one or the other"; it entirely depends on what you're designing, whether you're dealing with classes or structs, etc.
rohitpaulk has quit [Ping timeout: 255 seconds]
Jenz has quit [Remote host closed the connection]
<FromGitter> <konovod> @Blacksmoke16 even more reduced) https://play.crystal-lang.org/#/r/6bgt
<FromGitter> <Blacksmoke16> \o/ ill update the issue
azuri5 has quit [Quit: azuri5]
<FromGitter> <Blacksmoke16> cheers
Jenz has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> @z64 oh wow thank you that's so cool
<FromGitter> <girng> @z64 for example, i like the dot notation way (the image on the right). i use classes btw
<FromGitter> <dscottboggs_gitlab> > for example, broadcast_to_game would need created ⏎ ⏎ Not sure what you mean by this part
<FromGitter> <Jens0512> I think I'd try to do this `Client#give_exp`as `Client#exp#=`, maybe I'm weird
<FromGitter> <Jens0512> Having an `Experience` object might be weird
<FromGitter> <dscottboggs_gitlab> but yeah you need to either use @varnames or self.setter to use setter methods because they conflict syntactically with variable assignment
<FromGitter> <girng> @dscottboggs_gitlab i would have to create that method inside the client class
<FromGitter> <girng> because i can't call it from the Client class, because it's a method under the GameServer class
<FromGitter> <girng> but if i pass the client by reference, broadcast_to_game makes more sense under the main GameServer class
azuri5 has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> sounds like it should be a module method maybe?
<FromGitter> <dscottboggs_gitlab> and then `include`d into Client?
<FromGitter> <girng> maybe, i just want to know if there is anything *bad* about the image on the right, and all the passing by reference stuff. is it slow? or does it even matter and just aesthetic / style of programming?
<FromGitter> <girng> i don't use inheritance because it's confusing
<FromGitter> <girng> all i do is have methods littered all over the place, that accept the client and modify it
<FromGitter> <girng> much easier imo
<FromGitter> <dscottboggs_gitlab> or maybe a class method on GameServer? So you could do `GameServer.broadcast from: client, data: value` or something like that?
sagax has quit [Ping timeout: 250 seconds]
<FromGitter> <girng> oh, yeah i guess could do that huh
<FromGitter> <dscottboggs_gitlab> Calling a function which accepts an instance of a class and works on it is basically the same performance-wise as calling a non-inlined method on that class
<FromGitter> <girng> that actually makes more sense
<FromGitter> <Blacksmoke16> thats one thing i dont see as often in crystal as php, like DI in the sense of like having your constructor accept instances of other classes
<FromGitter> <Blacksmoke16> to use within that class
<FromGitter> <dscottboggs_gitlab> As far as I understand, OOP code is compiled to something like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c6d8435c4da4a11f588f8b5]
<FromGitter> <girng> > Calling a function which accepts an instance of a class and works on it is basically the same performance-wise as calling a non-inlined method on that class ⏎ ⏎ sorry can you give an example of the second part? "non-inlined method"?
<FromGitter> <dscottboggs_gitlab> so then a class's methods are just functions that take a pointer to the class as their first argument
<FromGitter> <dscottboggs_gitlab> I'm not sure what the rules are for the crystal compiler but for short functions rather than actually compiling a function call, sometimes it copies the code of the function directly into where the function call would be.
<z64> those kinds of optimizations are done by llvm
<FromGitter> <dscottboggs_gitlab> oh I see
Jenz has quit [Quit: Lost terminal]
moei has joined #crystal-lang
<FromGitter> <girng> i don't like having to switch between @ and no @. it's confusing for me. especially in the case you forget to put a @ivar when you do an operation on it. dot notation does like all this automatically for you.. ⏎ i guess you could just use `@` on every variable in the method of that class, but now it's just starting to look messy
<z64> OOP design, handling mutability/immutability, is a *huge* topic, not limited to crystal code. there isn't any hard & fast rule with how to design any given application
<FromGitter> <girng> actually, without the `property` macro, you would have a lot more "@" visible and the dev would most likely start to normalize that symbol and it becomes a non-issue. however, since i have like 56 property macros in my class, once i see a `@` i'm like wtf is this LOL
<FromGitter> <dscottboggs_gitlab> yeah, I generally just use @ for setters and none for getters.
<FromGitter> <dscottboggs_gitlab> hahah yeah, tbh the @ syntax isn't the best, reminds me a bit of PHP's `$` just not as bad haha
<FromGitter> <girng> lol i remember using the @ symbol in php to suppress certain errors for that variable
<z64> ruby has been using the same style as crystal, probably almost as long as it has existed (circa 1995), with `@vars` and `attr_reader`, `attr_writer`, and `attr_accessor` (crystal getter, setter, and property respectively)
<FromGitter> <dscottboggs_gitlab> yep, I guess you gotta take a bit of bad with the good
<FromGitter> <girng> yah, i like the @ when used in moderation
<FromGitter> <asterite> crystal inlines methods that consist of only literals (1, 'a') or instance var access (`@foo`), then LLVM will further inline stuff
<FromGitter> <girng> taking ⏎ ⏎ > OOP design, handling mutability/immutability, is a huge topic, not limited to crystal code. there isn't any hard & fast rule with how to design any given application ⏎ and ⏎ > Calling a function which accepts an instance of a class and works on it is basically the same performance-wise as calling a non-inlined method on that class ... [https://gitte
<FromGitter> ... r.im/crystal-lang/crystal?at=5c6d8b7e7667931e2fd22a5e]
<FromGitter> <dscottboggs_gitlab> 👍 cool :D
<FromGitter> <dscottboggs_gitlab> @asterite interesting, thanks
sagax has joined #crystal-lang
<FromGitter> <girng> it's akin of asking: what's your fav food? oh you like spaghetti? i don't think spaghetti is that good, i like pizza more! lol.. the developer is gonna eat whatever he wants
<FromGitter> <dscottboggs_gitlab> wait, why are literals functions?
<FromGitter> <girng> crystal book on those?
jemc has joined #crystal-lang
<FromGitter> <kinxer> @dscottboggs_gitlab I think he meant like ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5c6d8ea31f14630421f1505b]
<FromGitter> <j8r> @girng what is the problem with `@`? What you show is more a problem between differentiating method an variables
<FromGitter> <j8r> I always use `@` when possible to show it's an ivar
<FromGitter> <j8r> and maybe in some cases it might be more efficient, don't know
<FromGitter> <j8r> the only case I don't use `@` is when I use memoization like `getter &block`
azuri5 has quit [Read error: Connection reset by peer]
Creatornator has joined #crystal-lang
Creatornator has quit [Client Quit]
<rkeene> How is the websocket server support in Crystal ?
<FromGitter> <dscottboggs_gitlab> most crystal frameworks and the built-in HTTP::Server include native websocket support
Creatornator has joined #crystal-lang
<FromGitter> <girng> https://play.crystal-lang.org/#/r/6biv how can i get the difference between the two numbers? all the google results tell me to do low/highvalue * 100. but i want to get the difference of the actual two numbers. for example, in this example, the result should be 0%.
<FromGitter> <dscottboggs_gitlab> wtf
<FromGitter> <dscottboggs_gitlab> ok one how would the difference between 200 and 500 be 0?
<FromGitter> <girng> that's the problem, iuno how to know
<FromGitter> <dscottboggs_gitlab> no, I'm saying it should be 300?
<FromGitter> <girng> for example, when a player has 200 experience, and they need 500 more exp to level, i wnat to get the difference in percentage of those two
<FromGitter> <girng> so they'd be at 0% and it would go higher if 200 gets closer and closer to 500
<FromGitter> <girng> if that makes sense?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6biw
<FromGitter> <Blacksmoke16> 40% the way there
<FromGitter> <girng> hmmmm
<FromGitter> <dscottboggs_gitlab> oh I see
<FromGitter> <girng> @Blacksmoke16 yeah that's from 0, i'm trying to get the percentage difference from the actual two numbers, starting from 200 (or whatever experience). for example: 200 exp of 500 should be 0%, because they still need 300 more exp to level. hard to explain sorry
<FromGitter> <Blacksmoke16> ah
<FromGitter> <girng> i am prob not using the right math terminology here
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6biz 66.66% the way there
<FromGitter> <Blacksmoke16> eh?
<FromGitter> <Blacksmoke16> naw that doesnt work
<FromGitter> <girng> math really hurts my head
<FromGitter> <girng> i don't think it's "percentage difference" i think it's called something else. need to google some more
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <dscottboggs_gitlab> ok so lets say that you're checking the differenc between level 1 and level 2. You get to level 1 at 200xp and level 2 at 500xp, and you want to measure how much further the user needs to go to get to level 2, from, say, 300xp
<FromGitter> <dscottboggs_gitlab> am I right?
<FromGitter> <girng> yeah 300xp as a percentage. so if they are at 200xp, it's 0%, if they get 10 more xp, then the 0% goes higher and higher until it's 100% (when they reach 500 exp)
<FromGitter> <kinxer> @girng I'm going to try to write out the situation, and I need you to correct me if I'm wrong. You have a `current_exp` and a `desired_exp`. You also have another number, let's say `exp_gain`, and you want to know what of the "distance" between `current_exp` and `desired_exp` is covered by adding `exp_gain`. Is that accurate?
<FromGitter> <kinxer> Oh, okay.
<FromGitter> <girng> yah that's accurate
<FromGitter> <girng> i googled "difference between two numbers as a percent" but they all just show blacksmoke's playground
<FromGitter> <girng> YEAH, "distance between" makes more sense now
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c6daf599155d45d9048b5e7]
<FromGitter> <dscottboggs_gitlab> You're doing the same thing as in @Blacksmoke16's example, but you're subtracting the current level's xp value from the both the XP and the XP goal
<FromGitter> <dscottboggs_gitlab> right?
<FromGitter> <kinxer> That's nice and comprehensive, @dscottboggs_gitlab. Nicely done.
<FromGitter> <dscottboggs_gitlab> thanks :D
<FromGitter> <kinxer> A less-complete example: https://play.crystal-lang.org/#/r/6bji
Creatornator has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> nice that you included the tests
<FromGitter> <dscottboggs_gitlab> no idea if what I wrote compiles lol
<FromGitter> <dscottboggs_gitlab> let alone works
<FromGitter> <dscottboggs_gitlab> I got `error instantiating 'allocate()'` again... :(
<FromGitter> <kinxer> @girng Do those snippets help? Basically, you need to do `(current_total_exp - last_level_exp) / (next_level_exp - last_level_exp)`.
<FromGitter> <dscottboggs_gitlab> oh crap did I get it backwards? I think I did
<FromGitter> <girng> just trying to understand the `last_level_exp` do i need to store that or can i just get that value from a subtraction
<FromGitter> <dscottboggs_gitlab> You need to store the points at which the levels change, perhaps in a `{} of Int => Int` and then you can calculate the current level by the current XP.
<FromGitter> <kinxer> Are you resetting `exp` to zero at every level? We're assuming that you just add to `exp`.
<FromGitter> <dscottboggs_gitlab> or just use zero-indexed levels and store it in an array as in my example
<FromGitter> <dscottboggs_gitlab> true
<FromGitter> <girng> @kinxer nope, i'm just adding to exp you are correct
<FromGitter> <girng> it's impossible to do what i'm thinking
<FromGitter> <girng> without storing the initial EXP value
<FromGitter> <girng> to subtract!
<FromGitter> <girng> so yeah, the snippets help, thank you
<FromGitter> <dscottboggs_gitlab> > the initial EXP value ⏎ ⏎ huh?
<FromGitter> <kinxer> I mean, presumably you have the exp requirements for each level coded or saved somewhere. You just need to get it from there.
<FromGitter> <dscottboggs_gitlab> exactly!
<FromGitter> <girng> yeah so `previous_level_experience` is required
<FromGitter> <girng> or impossible
<FromGitter> <girng> i got it now, thanks!
bmcginty has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> @girng alternatively, https://play.crystal-lang.org/#/r/6bk8
<FromGitter> <dscottboggs_gitlab> you can calculate `next_level_experience` and `previous` or `current_level_experience` from the current XP and the level change points
<FromGitter> <girng> interesting
<FromGitter> <dscottboggs_gitlab> shit did that get the wrong answer??
<FromGitter> <dscottboggs_gitlab> what did I mess up?
<FromGitter> <girng> man, this is working great. AWESOME
<FromGitter> <dscottboggs_gitlab> I'm glad, I love these sorts of little problems
<FromGitter> <girng> i prob make it more confusing than it is. but really, i'm happy ya'll are tolerant of my terrible math skills
<FromGitter> <girng> but i'm learning, i think
<FromGitter> <dscottboggs_gitlab> pay attention in math class ;)
<FromGitter> <girng> yeah no kidding
<FromGitter> <girng> i feel a little more empowered now since i know how to get the distance between two values like that. want to add some more experiences features in the game, skill gem exp, paragon level exp, etc
<FromGitter> <dscottboggs_gitlab> You could even abstract it away by creating an `abstract struct Stat` and then have each statistic inherit from stat. Then in you'd just need to make each skill level an instance of Stat instead of an instane of Int32 or whatever. For each level, you'd only need to add like a `paragon.cr` which contained something like: ⏎ ⏎ ```struct Game::Stats::ParagonStat < Stat ⏎ LEVEL_XP = [ 300.0,
<FromGitter> ... 600.0, 1200.0 ] ⏎ end``` ⏎ ⏎ or similar [https://gitter.im/crystal-lang/crystal?at=5c6db93f00aa630d9ae48a4a]
<FromGitter> <Blacksmoke16> whoa now, dont blow his mind too much in one day :p
<FromGitter> <dscottboggs_gitlab> so then character would be changed from ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c6db9d2ab952d308563cc85]
<FromGitter> <dscottboggs_gitlab> @Blacksmoke16 lol
<FromGitter> <dscottboggs_gitlab> man gitters syntax highlighting is not great
<FromGitter> <girng> O_O
<FromGitter> <dscottboggs_gitlab> lol
<FromGitter> <dscottboggs_gitlab> I seriously love OOP and inheritance
<Yxhuvud> something is wrong with you if you love inheritance :P
<FromGitter> <dscottboggs_gitlab> why do you say that?
<Yxhuvud> Because I prefer my OOP without it. composition is so much nicer, most of the time.
<FromGitter> <girng> :D
bmcginty has quit [Quit: leaving]
<FromGitter> <dscottboggs_gitlab> for me the line is like when it's a part of the project I prefer inhertance but one you involve a library I prefer composition
<FromGitter> <girng> wait, is composition what i was talking about earlier that i liked?
<FromGitter> <dscottboggs_gitlab> hm, alt-click the timestamp of the message you're talking about to link back to it @gring
<z64> composition is writing common pieces of code in `module`s and then using `include` to compose more complex objects with shared behavior
<FromGitter> <dscottboggs_gitlab> because then you can use the `crystal docs` to figure out what methods are available and whatnot, but if you're working with an outside library it might get confusing
<Yxhuvud> a64
<Yxhuvud> z64, no, that is just another way to do inheritance :/
<FromGitter> <girng> ☝️ February 20, 2019 8:32 AM (https://gitter.im/crystal-lang/crystal?at=5c6d81069155d45d90476a32) @dscottboggs_gitlab
<FromGitter> <dscottboggs_gitlab> oh I see. Hm, I don't think so....
<FromGitter> <girng> @dscottboggs_gitlab does creating separate methods that accept a class and modifying it fall under composition?
<FromGitter> <dscottboggs_gitlab> yeah I don't think that's what that is.
<FromGitter> <dscottboggs_gitlab> if you google (well, ddg) "composition vs inheritance" this article (https://reactjs.org/docs/composition-vs-inheritance.html) from React comes up first. I'd be willing to bet they were the ones who brought this debate to the forefront, there have been a lot of interesting new stuff out of the React team IMO
<FromGitter> <dscottboggs_gitlab> I think that was the article I read originally to learn the concept.
<FromGitter> <j8r> so much more flexible is composition. Doing Inheritance in Crystal is basically,at 90%, forcing us to use Classes everywhere
<FromGitter> <j8r> vs modules or structs
<FromGitter> <dscottboggs_gitlab> you can inherit structs?
<FromGitter> <j8r> yes, but abstract structs can't be used
<FromGitter> <dscottboggs_gitlab> huh? why not?
<FromGitter> <j8r> look a this example
<Yxhuvud> composition vs inheritance is a question that is at least a decade older than React.
<FromGitter> <dscottboggs_gitlab> yeah I thought about what I said after I said it and decided it was a bunch of bullshit @yxhuvud lol
<FromGitter> <dscottboggs_gitlab> also wow, that was definitely not the article I originally read about inheritance vs composition and it isn't great
<FromGitter> <girng> is it possible for someone to post 2 small examples in crystal showing 1: composition and 2: inheritance
<FromGitter> <kinxer> (Not related to the current topic, but @dscottboggs_gitlab: https://play.crystal-lang.org/#/r/6bkg)
<FromGitter> <j8r> @dscottboggs_gitlab https://carc.in/#/r/6bkh
<FromGitter> <j8r> see
<Yxhuvud> it is an old concept. It has for example been a topic in the original design patterns book.
<FromGitter> <dscottboggs_gitlab> oh my, I didn't realize
<FromGitter> <girng> i just want to see what the differences are in actual crystal code so i can better understand it
<FromGitter> <girng> or javascript code i guess.. since i know that lol
<FromGitter> <dscottboggs_gitlab> @kinxer Oh, I see!
<FromGitter> <j8r> @girng `include Mod` vs `< Klass` - lol
<FromGitter> <j8r> with `include` you are more free - include a module in: a class, a struct, or another module
<FromGitter> <girng> @j8r oh i remember that. last year or so we had a discussion about this
<FromGitter> <dscottboggs_gitlab> @j8r that's an interesting point...hm.
<rkeene> How do you do varargs in Crystal ?
<FromGitter> <dscottboggs_gitlab> @rkeene https://crystal-lang.org/reference/syntax_and_semantics/splats_and_tuples.html is that what you mean?
<rkeene> It could be -- I'm basically building a function that just relays all its args to another function
<FromGitter> <girng> oh boy i should have never googled inheritance vs composition. stopping now :D
<rkeene> dscottboggs_gitlab, It seems to work
<FromGitter> <dscottboggs_gitlab> @rkeene to forward all arguments you can use `(*args, **options)` as in Python
<FromGitter> <dscottboggs_gitlab> `args` would be a tuple and `options` a namedtuple
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <Sija> 1) if you want to cover all the bases you'd need another definition but with `…, &block)`
<FromGitter> <dscottboggs_gitlab> oh, true
<FromGitter> <malkomalko> I'm working on my spec chops with Crystal. Is there anyway to silence the output of puts?
<FromGitter> <j8r> @malkomalko use a logger
<FromGitter> <dscottboggs_gitlab> was just about to say the same https://crystal-lang.org/api/0.27.2/Logger.html
<FromGitter> <malkomalko> Thank you, I'll take a look at that
<rkeene> if @process.nil? raise "Bad"; else input = @process.input; end undefined method 'input' for Nil (compile-time type is (Process | Nil)) :-(
<FromGitter> <dscottboggs_gitlab> @rkeene ⏎ ⏎ ```if (proc = @process).nil? ⏎ raise "nil proc!" ⏎ else ⏎ input = proc.input ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5c6dca0c9155d45d90496c3f]
<FromGitter> <dscottboggs_gitlab> when checking for nil you have to assign it to a new variable whose type is not nillable
<FromGitter> <dscottboggs_gitlab> so... I've got a problem ⏎ ⏎ https://carc.in/#/r/6bks
<rkeene> dscottboggs_gitlab, But wouldn't it be impossible for it to be nil in the "else" part ?
<FromGitter> <dscottboggs_gitlab> yes but the type of `@process` is still `Process | Nil`, whereas the type of `proc` is nil in the "if" part and `Process` in the "else" part
<rkeene> But it seems like it's unambigious at that point what type it must be
<FromGitter> <dscottboggs_gitlab> Idk, I've grown to appreciate the fact that missing a Nil check or the fact that there is a null check someplace really stands out. But perhaps in the futre the compiler will be able to do that automatically
<rkeene> There's no possible missing null check there though
<rkeene> It's just creating a new variable because the compiler doesn't realize that at that point its types have been pruned
<FromGitter> <Sija> @rkeene wrong, @ivar can change in between executing `if` and its body
<FromGitter> <Sija> that's why you need to use local var instead
<rkeene> Similarly: session = nil; if session.nil? session = Sessions.new(id); end; session = session.as(Sessions); session.puts("ok") undefined method 'puts' for Nil (compile-time type is (Sessions | Nil)) but after the .as() call the type should be reset
<rkeene> Sija, There's no code that could execute during that time in either of these cases
<FromGitter> <dscottboggs_gitlab> it would create a race condition in a multiprocess or concurrent situation
<FromGitter> <Sija> it could
<FromGitter> <Sija> think MT or fibers
<FromGitter> <Sija> it's explicitly described in crystal docs
<rkeene> Fibers are a form of cooperative multithreading, I'd have to yield the thread of execution for them to run -- which I have not done anywhere
<rkeene> And Crystal currently lacks preemptive multithreading
<rkeene> Further, my second example is a local variable
<FromGitter> <dscottboggs_gitlab> ```maybe_session = nil ⏎ session = maybe_session || Session.new ⏎ session.puts "ok"``` [https://gitter.im/crystal-lang/crystal?at=5c6dcd9800aa630d9ae51912]
<rkeene> dscottboggs_gitlab, But the types can be pruned by the .as() call
<rkeene> They just are not
<FromGitter> <Sija> yeah, I'm not sure what's wrong with your 2nd example, it ought to work...
<FromGitter> <dscottboggs_gitlab> rkeene, I agree it's a different way of thinking about things, and it can be challenging, but I think it's worth it as your code comes out better
<rkeene> I think it makes my code worse.
<FromGitter> <dscottboggs_gitlab> I mean that it makes it function better and more reliably at the expense of being slightly more verbose
<rkeene> It cannot affect the resulting function since they would be functionaly equivelant
<rkeene> It's exactly as reliable
<FromGitter> <dscottboggs_gitlab> it affects the compiled output
<FromGitter> <dscottboggs_gitlab> as far as the example with `#as`, the issue is that while the type of sesison is known *before* the assignment, it's being assigned to a value whose type may be one of two types. Once it's a part of that variable, the compiler no longer knows whether it's a Session or Nil, so you have to assign it to a new variable which is definitely a Session
<rkeene> The compiler can know at that point in the compilation that all types other than Sessions have been pruned
<FromGitter> <dscottboggs_gitlab> as @Sija said it will prevent race conditions when crystal is MT, but yes right now it's just an annoyance that it isn't worth it to take out and put back in when we go multi-threaded. Rust has almost exactly the same situation with their Optional and Enum types
<rkeene> Since it does not, I have to workaround it by using additional variables
<FromGitter> <dscottboggs_gitlab> Under the specific circumstances you're citing, but there are many circumstances where that is not the case
<rkeene> I'm only running the compiler on my code, with my circumstances that the compiler unambigiously knows.
<FromGitter> <dscottboggs_gitlab> but the compiler has to be able to interpet everyone's code right. What if instead of it being `@sessions` we were talking about, it was some property of a property of `@sessions`? You might assign it, and then on the very next line, ask for the response, but maybe an event occured in some property of `@sessions` that change the value of the property you were referring to to a different type? Crystal
<FromGitter> ... is full of event-driven, IO-oriented code that would be vulnerable to race conditions if it weren't for that sort of enforcement by the compiler
<FromGitter> <dscottboggs_gitlab> And types can be infinitely complex in crystal using unions, not just nullable
<rkeene> The first example just prunes out the Nil type, the second example prunes out all the types except for Sessions.
sagax has quit [Ping timeout: 246 seconds]
sz0 has quit [Quit: Connection closed for inactivity]
<rkeene> When doing Process.new(), is it possible to register an event when "input" becomes valid or will never become valid (i.e. from an error creating the pipes) ?
<rkeene> process = Process.new(command: "tclsh", clear_env: true, input: Process::Redirect::Pipe, output: Process::Redirect::Pipe, error: Process::Redirect::Pipe); process.input.each_line {|line| @peer.send(line) }; gives me a bad file descriptor on the read(2) system call
<rkeene> Nevermind, that needs to be on the output channel