ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
jmd_ has joined #crystal-lang
<rocx> b'guh. wasn't there an update not too long ago that said the compiler could "downgrade" integer types (eg. turning `3` into a `UInt8` if i declared the type to be such?
<FromGitter> <Blacksmoke16> in some cases yea
<rocx> urgh. i decide to use UInt8s just to save a smidge of memory and turns out it's a lot of type annotating and .to_u8 calls.
<FromGitter> <Blacksmoke16> unless you have a reason to do it, better to just use Int32
<rocx> shaving a whole three bytes per integer but that might just be munchkining on memory.
<FromGitter> <Blacksmoke16> benchmark it and find out
<FromGitter> <Blacksmoke16> otherwise its just premature optmization
<rocx> and we all know premature optimization is the root of all evil.
<FromGitter> <moe:busyloop.net> crystal tries to help you resist the munchkining, by making it annoying
<rocx> fair. then again, having a type system like this be annoying before running the code would have saved me the months of all the jira tickets saying "unexpected method for NilClass".
<FromGitter> <Blacksmoke16> there's also a compile time flag you can use to make it more strict
<FromGitter> <Blacksmoke16> allows it to autocast number literals, but not expressions
<FromGitter> <Blacksmoke16> e.g. `foo 10` would work but not `foo 5 +5`
<FromGitter> <moe:busyloop.net> ah yea, good ol' masochist mode
<FromGitter> <moe:busyloop.net> for next april we should add a go-lang mode that forces you to put `if err` after each line :p
* rocx shudders
ur5us has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
Sankalp- has joined #crystal-lang
Sankalp has quit [Ping timeout: 268 seconds]
Sankalp- is now known as Sankalp
ur5us has quit [Ping timeout: 260 seconds]
jmd_ has quit [Ping timeout: 265 seconds]
Sankalp has quit [Ping timeout: 265 seconds]
Sankalp has joined #crystal-lang
_ht has joined #crystal-lang
_ht has quit [Quit: _ht]
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
bittin_ has joined #crystal-lang
bittin_ has quit [Ping timeout: 260 seconds]
jmdaemon has joined #crystal-lang
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
_ht has joined #crystal-lang
<FromGitter> <azurelmao> I've come across a weird issue. I'm using the Crystal IDE plugin for IntelliJ and the run command works fine
<FromGitter> <azurelmao> But when I tried to run it in the terminal, it doesn't
<FromGitter> <azurelmao> says it can't find a required file, and that i should chrck whether im running the compiler in the same directory as my shard.yml
<FromGitter> <azurelmao> which I am
ur5us has joined #crystal-lang
_ht has quit [Quit: _ht]
<FromGitter> <Blacksmoke16> whats the exact error?
<FromGitter> <plambert> Is it possible to write a module Foo, such that it can wrap the initialize() methods of any class that includes it?
<FromGitter> <Blacksmoke16> got an example?
<FromGitter> <moe:busyloop.net> `included`-hook is probably what you're looking for. ⏎ https://crystal-lang.org/reference/1.6/syntax_and_semantics/macros/hooks.html
<FromGitter> <moe:busyloop.net> depending on what you mean by "wrap" in detail, some additional gymnastics with or without macros may be needed
<FromGitter> <plambert> Basically, I want my "singleton" module to make sure every initialize method ends (or starts) with `@@singleton ||= self`
<FromGitter> <plambert> I think I could do it by re-implementing `new`, since there's only one of those… but it seemed like there should be a way to do it to the initialize methods themselves…
<FromGitter> <plambert> (This is a learning project, so while I'm happy to hear of better ways to do this, or of existing shards I could use, I also still want to figure out if it's possible to do this…) :)
<FromGitter> <Blacksmoke16> try something like
<FromGitter> <plambert> I'm trying to extract the singleton parts of that class into a module, since I'll be doing all the same things to many classes in this project. And it's all easy, except the `@@singleton ||= self`
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=63868473bcdb0060b8446cbc]
<FromGitter> <plambert> Cool
<FromGitter> <Blacksmoke16> tho might need to include it after the concrete one?
<FromGitter> <plambert> And if there are multiple initialize() methods with arbitrary arguments?
<FromGitter> <Blacksmoke16> prob out of luck
<FromGitter> <plambert> So… in the docs say "don't forget to add @@singleton ||= self"
<FromGitter> <plambert> (And maybe give it a fancy name like register_singleton)
<FromGitter> <plambert> :)
<FromGitter> <plambert> I love Crystal's macros, but eventually they become a source of great neurological recursion, and I can't figure them out. :)
<FromGitter> <plambert> Thank god for `{{ debug }}`
<FromGitter> <Blacksmoke16> could try having an abstract parent class where they could just call `super`
<FromGitter> <Blacksmoke16> tho that might set the class var of all children and not just that one
<FromGitter> <azurelmao> > whats the exact error? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=63868b02f9491f62c9d7c5d6]
<FromGitter> <Blacksmoke16> and you have a `src/Server.cr`?
<FromGitter> <Blacksmoke16> tho fwiw, file names should be all lowercase
<FromGitter> <azurelmao> Server is in the src folder, the same as crystal-cave.cr
<FromGitter> <azurelmao> yeah I know, but I don't like some naming conventions
<FromGitter> <Blacksmoke16> if its in the same dir, you need to do like `./server`
<FromGitter> <Blacksmoke16> so `require "./Server"`
<FromGitter> <azurelmao> weird
<FromGitter> <azurelmao> the IDE plugin doesn't complain when it's just "Server"
<FromGitter> <Blacksmoke16> well you're the first i heard using that plugin so apparently it needs some work 😅
<FromGitter> <Blacksmoke16> its basically assuming its a shard and is looking for it in `lib/`
<FromGitter> <azurelmao> lol, I use it cause I already have IntelliJ for minecraft mods
<FromGitter> <Blacksmoke16> like whats the output of `crystal env CRYSTAL_PATH`
<FromGitter> <Blacksmoke16> as that's where it will look
<FromGitter> <azurelmao> `CRYSTAL_PATH=lib:/usr/bin/../share/crystal/src`
<FromGitter> <Blacksmoke16> so the error is correct in that it cant be found, hence needing to use `./Server`
<FromGitter> <azurelmao> so I should move my other files to lib/ ?
<FromGitter> <Blacksmoke16> no
<FromGitter> <Blacksmoke16> you should require it via `require "./Server"`
<FromGitter> <Blacksmoke16> and not `require "Server"`
<FromGitter> <azurelmao> kinda looks ugly but alright
<FromGitter> <azurelmao> thank you
<FromGitter> <Blacksmoke16> np
gordea has joined #crystal-lang