<FromGitter>
<Blacksmoke16> https://play.crystal-lang.org/#/r/5h5h shouldn't this return like `[name]` since the macro should only get expanded when it is inherited and types are resolved?
<FromGitter>
<Blacksmoke16> paging @asterite
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
non-aristotelian has quit [Quit: non-aristotelian]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 246 seconds]
jemc has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
jemc has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 272 seconds]
_whitelogger has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
<FromGitter>
<codenoid> hi folks
rohitpaulk has joined #crystal-lang
<FromGitter>
<codenoid> how to get minute of `current datetime-somedatetime older than datetime`
<FromGitter>
<schoening> Hey, could I get some help with connecting to my mysql database? This is not super helpful: ⏎ ⏎ ```DB.open "mysql://root:@localhost:3306/korekort" do |db|``` ⏎ ⏎ Not sure what I am doing wrong, Its an empty password on root. I also tried with *root:''@localhost* [https://gitter.im/crystal-lang/crystal?at=5be6956262866f7473779bf6]
rohitpaulk has quit [Ping timeout: 244 seconds]
<FromGitter>
<schoening> Huh.. now it worked: "mysql://root@localhost/koerekort". Go figure..
<FromGitter>
<codenoid> weird
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
<FromGitter>
<schoening> What is the best practice using an sql database in crystal? Should I DB.open on every request or store it in a variable and reuse it?
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 276 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
_whitelogger has joined #crystal-lang
rohitpaulk has joined #crystal-lang
Yxhuvud has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 272 seconds]
ashirase has quit [Ping timeout: 272 seconds]
ashirase has joined #crystal-lang
<FromGitter>
<swinSpo> hi, whats this syntax here?
<FromGitter>
<r00ster91> here the `fetch` method uses the return value of the block (`:default_value`) and does something with it. In this case the return value is being returned when the index argument is out of bounds.
<FromGitter>
<r00ster91> of course the block doesn't neccesarily has to return a symbol. It could also for example return an integer: `123` or a string: `"hello"`. ⏎ ⏎ ```{ "hi" }``` ⏎ ⏎ A symbol is a type just like an integer or a string. [https://gitter.im/crystal-lang/crystal?at=5be6bc3e7326df140ee37084]
<FromGitter>
<swinSpo> @r00ster91 I mean what is this
<FromGitter>
<r00ster91> strings are created at run-time
<FromGitter>
<swinSpo> why are strings not interpreted at compile time?
marmotini_ has quit [Ping timeout: 252 seconds]
<FromGitter>
<r00ster91> because then you couldnt do much with the strings at run-time. ⏎ you wouldn't be able to for example split them: `"hello, world".split(',')`
<FromGitter>
<swinSpo> Interesting! I'll keep it in mind
<FromGitter>
<swinSpo> Although, you can't + them
<FromGitter>
<swinSpo> ```puts :"a" + :"b"```
<FromGitter>
<j8r> I would use an Enum instead of Symbols
<FromGitter>
<swinSpo> so returning them from your library seems to be not that user friendly?
<FromGitter>
<j8r> Usually `Symbol` can be avoided
<FromGitter>
<Timbus> please delete symbols
<FromGitter>
<Timbus> :(
<FromGitter>
<r00ster91> Yeah. Enums are much safer than symbols. Because enums give you the errors at compile-time while symbols give you the errors at run-time
<FromGitter>
<swinSpo> @j8r Enums are one of my favourites of the language
<FromGitter>
<swinSpo> they are "real" enums
<FromGitter>
<r00ster91> symbols are very similar to enums
ua has quit [Ping timeout: 252 seconds]
<FromGitter>
<j8r> But you haven't compile time safety with symbols
<FromGitter>
<j8r> You can write whatever name
<FromGitter>
<swinSpo> Many languages have "fake" enums
rohitpaulk has joined #crystal-lang
<FromGitter>
<swinSpo> i noticed that in Go and typescript for example
<FromGitter>
<r00ster91> @swinSpo you could `+` the symbol names like this: `:a.to_s + :b.to_s`
<FromGitter>
<swinSpo> @r00ster91 ahh I see.. although that is still "unfriendly" i guess and you end up with a string anyway
<FromGitter>
<Timbus> didnt know you could add methods to enums.. neat
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter>
<Timbus> ... shouldn't it be `self.action` though.. its not an instance
<FromGitter>
<j8r> @Timbus agree Symbols could be deleted. I've done a parser using Enum instead od Symbols like in JSON::Lexer
<FromGitter>
<j8r> @Timbus you can do `Animals::Rooster.action` - it works
<FromGitter>
<Timbus> I dont mind the syntax symbols provide, but they can just be immutable strings under the hood, and yeah cast to an enum when used in params
<FromGitter>
<j8r> you can also mimic class instantiation with `def self.new(animal : String)` with a case inside
<FromGitter>
<Timbus> I understand it works, I just mean.. it feels like it should be declared like a 'class method'
marmotini_ has joined #crystal-lang
<FromGitter>
<j8r> but class method is for `Animal` here, and instance methods for `Animal::Dog`
<FromGitter>
<Timbus> oh. true.
<FromGitter>
<j8r> enums are a bit special...
marmotini_ has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
marmotini_ has joined #crystal-lang
<FromGitter>
<j8r> I am not against Symbols too, but every time I see them there is a better way to do without them.
rohitpaulk has quit [Ping timeout: 260 seconds]
<FromGitter>
<Timbus> the only reason im not screaming about them daily is because they aren't as easy to accidentally put into a hash, as they are in ruby
<FromGitter>
<Timbus> "now do i access this hash with a string or a symbol? or both?" -- my daily ruby adventures
<FromGitter>
<r00ster91> I would like to always use enums. My problem is just that it can get pretty long and annoying sometimes to access one member. `Module1::Module2::Enum::Member` instead of just `:member`
<FromGitter>
<Timbus> but you can already do that most of the time
rohitpaulk has joined #crystal-lang
<FromGitter>
<proyb6> Is this site feel like Github?
<FromGitter>
<j8r> this complicates the `PullParser`, `Mapping` and `Serializable`
marmotini_ has quit [Ping timeout: 264 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<Blacksmoke16> https://play.crystal-lang.org/#/r/5h5h shouldn't this return like `["name"]` since the macro should only get expanded when it is inherited and types are resolved?
<oprypin>
Blacksmoke16, the `@type` is not set to anything, you're executing it at top level
<FromGitter>
<fastcona> I notice Crystal uses port_resuse but it's way slower compare to Golang fasthttp?
<FromGitter>
<fastcona> Can we invest in making Crystal faster for networking when everything we do are all on the web?
<oprypin>
or can we just not do everything on the web
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<j8r> @fastcona if an issue doesn't exist, you can open one
<FromGitter>
<fastcona> I think Crystal as a great language for indie game and anyone have high network latency issues?
<FromGitter>
<j8r> depends of the game, on the targeted platforms
<FromGitter>
<j8r> not mobile nor Windows. Maybe for Unix, on the server side
<oprypin>
btw you could make a game also on windows if you really wanted
<oprypin>
i'm just really concerned about shipping the game to customers (which may actually be worse on linux)
<FromGitter>
<j8r> hum no @oprypin, a statically linked binary and done
<oprypin>
lol
<FromGitter>
<j8r> or, another option is flatpak and appimage
jemc has quit [Ping timeout: 268 seconds]
<FromGitter>
<pitosalas> another question: is there an equivalent way to do String#join from Ruby?
<oprypin>
ask a direct question, no ruby pls
rohitpaulk has joined #crystal-lang
<FromGitter>
<pitosalas> ouch. this is not a ruby question… it’s a crystal question. but anyway, I realize that my question was wrong, I meant join of an array with Strings which does exist. (p.s. since Crystal is based on ruby it does seem a little harsh to call out referring to ruby in a question.)
<FromGitter>
<Blacksmoke16> `#.join`
<FromGitter>
<Blacksmoke16> or `.join(", ")`
rohitpaulk has quit [Ping timeout: 268 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
jemc has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter>
<j8r> Crystal isn't based on Ruby @pitosalas . Everyone believing that won't use Crystal effectively.
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<j8r> For example, avoid Symbols, use enums. Use structs instead of Hash/NamedTuples when possible. IO are also more used, for example string building. The inspirations are taken from C#, Go and more
<Yxhuvud>
j8r: while there exist many differences, thinking that the stdlib APIs are not based on ruby is extremely silly. And Array#join exist in crystal too, and it is a perfectly fine alternative in many cases. Sometimes a stringbuilder is a better choice, but using join to build a new string out of already existing strings is a perfectly fine usecase.
<Yxhuvud>
you are right in that many ideoms differ, though. But that wasn't the question here.
jemc has quit [Ping timeout: 272 seconds]
<oprypin>
k
<Yxhuvud>
pitosalas: I wonder a bit why you didn't try it out before asking though. it is not as if it takes a lot of work to put `["hello", "world"].join` through the compiler. But if that doesn't give a successful result (it very often will), please do ask then (but probably more like: I won't to achieve FOO. In ruby I'd do BAR, what is the crystal way?)
<Yxhuvud>
*want
ua has joined #crystal-lang
<FromGitter>
<j8r> yes, we can better help if people provides examples
<FromGitter>
<j8r> @Blacksmoke16 you're using annotations?
<FromGitter>
<j8r> what's the code?
<FromGitter>
<Blacksmoke16> too much to say whats causing it atm
<FromGitter>
<Blacksmoke16> working on getting it narrowed down
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
<FromGitter>
<pitosalas> @j8r Your example is good and actually useful. But surely you're not saying that Crystal isn't based on Ruby, seriously?
<FromGitter>
<pitosalas> @FromIRC You're right, my bad. But truly I thought I had tried it. I was just confused about the type of the variable that I was doing the join on.
<FromGitter>
<Blacksmoke16> i think the point he was trying to make was that just because it looks like ruby and has some similar methods, it shouldnt be used the same or viewed the same thing as ruby
<FromGitter>
<pitosalas> @Blacksmoke16 Absolutely …. I am learning that. And I think you said it better ;)
<FromGitter>
<Blacksmoke16> the point of the slogan is C is a fast language and Ruby is a very readable language
<FromGitter>
<Blacksmoke16> mhm
rohitpaulk has quit [Ping timeout: 252 seconds]
ua has joined #crystal-lang
<FromGitter>
<j8r> the syntax is clearly inspired by Ruby of course @pitosalas . "Based" for me means extending, superset, which is false - no backward compatibility
<FromGitter>
<oprypin> test message, please ignore
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter>
<pitosalas> On another question: I am trying to parse a String date. This example from the doc doesn’t work, has the syntax been changed?
<FromGitter>
<Blacksmoke16> you're not providing it a location that the time is, so it errors
<FromGitter>
<Blacksmoke16> which the `parse!` method pulls it from the string
<FromGitter>
<Blacksmoke16> while `parse_utc` assumes it to be utc tz
rohitpaulk has quit [Ping timeout: 250 seconds]
<FromGitter>
<pitosalas> Oh I didn’t see that “!” in your sample
<FromGitter>
<pitosalas> I got my sample In the doc for Time near the top under “Formatting and Parsing Time” … so that’s incorrect then?
<FromGitter>
<Blacksmoke16> looks like it yea
<FromGitter>
<Blacksmoke16> `parse_utc` is what you would want assuming the string is UTC
<FromGitter>
<Blacksmoke16> there are also other method for parsing specific rfc strings
<FromGitter>
<pitosalas> @Blacksmoke16 one more thing: how do I interpret the error message mentioning an overload? "Overloads are: ⏎ Time.parse(time : String, pattern : String, location : Location)"
<FromGitter>
<pitosalas> @Blacksmoke16 thanks… It is the use of the word “overload” which is quite misleading. Thanks for all your help.
<FromGitter>
<Blacksmoke16> np
Yxhuvud has quit [Ping timeout: 260 seconds]
pabs has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
Yxhuvud has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 250 seconds]
<FromGitter>
<dscottboggs_gitlab> @j8r the original version was written in ruby using ruby syntax, and then developed and evolved from there, or am I wrong?
<oprypin>
dscottboggs_gitlab, what does that have to do with anything?
<FromGitter>
<dscottboggs_gitlab> sorry I was reading a discussion from earlier, he was saying Crystal wasn't based on ruby
<FromGitter>
<dscottboggs_gitlab> As I understood it crystal was a hard fork of ruby
<oprypin>
no
<FromGitter>
<dscottboggs_gitlab> oh
<oprypin>
compiler was initially implemented in Ruby
<oprypin>
but imagine if it was implemented in C++, then what would *that* have to do with anything?
<FromGitter>
<dscottboggs_gitlab> that's fair
<oprypin>
and i'm not even saying that we should ignore the Ruby roots, I just mean that when someone asks Ruby-specific questions, they artificially exclude some people from being able to answer.
<FromGitter>
<dscottboggs_gitlab> true, I've never written ruby
<FromGitter>
<dscottboggs_gitlab> I tried not long ago to just write some using my knowledge of crystal and it did not go as well as I thought it would haha
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
<FromGitter>
<j8r> @dscottboggs_gitlab Thanks, just merged your PR
<FromGitter>
<dscottboggs_gitlab> :D cool!
<FromGitter>
<j8r> How can I "force" calling a macro inside a macro, instead of a method? https://carc.in/#/r/5hdw
<oprypin>
cant
<FromGitter>
<j8r> I'll directly call the Module then, and tag the macro as `:nodoc:` :/