Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 19:53
    straight-shoota synchronize #11207
  • 17:04
    straight-shoota synchronize #11139
  • 17:04
    straight-shoota synchronize #11207
  • 17:02
    straight-shoota synchronize #11297
  • 17:02
    straight-shoota synchronize #11207
  • 12:49
    straight-shoota closed #10889
  • 12:49
    straight-shoota closed #6498
  • 12:44
    straight-shoota closed #10377
  • 12:43
    straight-shoota closed #11265
  • 12:43
    straight-shoota closed #4704
  • 12:43
    straight-shoota closed #11262
  • 12:43
    straight-shoota closed #11253
  • 08:06
    straight-shoota synchronize #11343
  • 07:58
    straight-shoota closed #11344
  • 07:58
    straight-shoota closed #9519
  • 07:57
    straight-shoota synchronize #11289
  • 07:57
    straight-shoota synchronize #11325
  • 07:56
    straight-shoota synchronize #11321
  • 07:55
    straight-shoota synchronize #11288
  • 07:55
    straight-shoota synchronize #10889
Benjamin Wade
@RespiteSage
In this particular case, you could use dogs = animals[Dog].transform_values &.as(Dog) on your last line.
George Dietrich
@Blacksmoke16
whats the end goal of this? what are you wanting to do?
Andrius Chamentauskas
@andriusch
ah got it, makes sense that Hash(Int32, Dog) < Hash(Int32, Cat) is not true
I want to store objects based on their type & id in a hash
all objects would inherit from some class, so it made sense to me to use Hash(Animal.class, Hash(Int32, Animal)) as type definition
From IRC (bridge bot)
@FromIRC
<riza> if you're using ints as keys, why not an array?
<riza> Hash(Animal.class, Array(Animal))
George Dietrich
@Blacksmoke16
and do what with this hash? like whats the end goal?
Andrius Chamentauskas
@andriusch
I don't want to use array since ids are not sequential, I don't think array would solve my problem though
George Dietrich
@Blacksmoke16
are the ids not related to the instance?
like cat.id
Andrius Chamentauskas
@andriusch
not exactly, more like each id can have multiple types of objects associated to it
e.g. an object with id = 1 can have a cat & a dog associated to it
object with id = 2 only has a cat
while object with id = 3 has an opposum
George Dietrich
@Blacksmoke16
would it be easier to use a struct instead of a hash, then you could give a name to these IDs, with getters to get the related animals?
Andrius Chamentauskas
@andriusch
once the objects are stored I want to be able to retrieve:
an object based on type & id
all objects based on type
there could potentially be >100 type of objects, I don't really want to define 100 properties on struct
and same for ids
George Dietrich
@Blacksmoke16
hmm fair enough
Ary Borenszweig
@asterite
You can just make it so that a Dog and a Cat are not equal by ==, and that they also have different hash values. Then you can simply have Set(Animal)
Oh, but you need to be able to retrieve all dogs and cats, I see...
Andrius Chamentauskas
@andriusch
thanks for your help, I guess I'll go with animals[Dog].transform_values &.as(Dog) since it doesn't seem there are better alternatives
George Dietrich
@Blacksmoke16
yea prob best you're going to get. Hashes can be kinda annoying to work with but i cant really think of another way
mfiano
@mjfiano:matrix.org
[m]
So it's a long shot but figure I'll ask anyway: My biggest problem seems to be trying to come up with an ordering that compiles with regard to requireing the proper files where they are needed. It seems to get really confused sometimes when I include or extend a module. I sort of wish I could just require "./project/* in a project.cr file in src/, but a real solution seems to be repeating the same requires in different files. I have no idea what I'm doing wrong, if anything, because I'm really not used to programming in such an OOP way, and mixins even less so. Has anyone ran into these sorts of problems before, and how did you get used to it/find something that works? Can anyone recommend some tutorials for Crystal or Ruby or similar for structuring a project in a nice way?
mfiano
@mjfiano:matrix.org
[m]
Also sometimes it blows up when I use include by itself, and I have to wrap it in macro included fairly often.
It's quite maddening, because I don't see anything wrong with a fairly simple project.
George Dietrich
@Blacksmoke16
i found what works for me is to just require everything manually within your main entrypoint file
mfiano
@mjfiano:matrix.org
[m]
That's what I first tried, and infact I'm reading that file right now lol
George Dietrich
@Blacksmoke16
with external libs at the top, then one off files, then globs
that covers most things, are still a few cases where i may need to require something in a specific file. For example the exceptions dir, most of them require http_exception i could have prob added that as a one off require before the directory but :shrug: didn't think it was worth it
so i guess tl;dr is like, global things in main file, then sometimes specific requires within directories as needed

Also sometimes it blows up when I use include by itself, and I have to wrap it in macro included fairly often.

got an example of this?

mfiano
@mjfiano:matrix.org
[m]
So would you say that you recommend explicitly listing every file and very rarely use the glob except for collections of order independent submodules?
George Dietrich
@Blacksmoke16
pretty much yea
mfiano
@mjfiano:matrix.org
[m]
I have always preferred to do a serial load order myself in Lisp, manually toposorting it as I develop so that sounds like what I prefer
George Dietrich
@Blacksmoke16
however you do it, just need to ensure things are required before they're used, that's the key point
having every file require everything it needs is a bit overkill
mfiano
@mjfiano:matrix.org
[m]
Maybe doing it that way will solve a lot of my problems. The setup that has been giving me grief is a main file doing require "./origin/*, and then trying to get the requires right in that directory. That sounds like a recipe for failure now that I actually typed it out 😆
George Dietrich
@Blacksmoke16
totally could still use the glob, but require the common things before
mfiano
@mjfiano:matrix.org
[m]
True, I haven't come up with a hierarchy I like yet (only a handful of files)
So mostly working with a flat directory
George Dietrich
@Blacksmoke16
is suggested to group things by namespace
i.e. exceptions live in Athena::Routing::Exceptions namespace
etc
mfiano
@mjfiano:matrix.org
[m]
and that maps to src/athena/routing/exceptions/?
George Dietrich
@Blacksmoke16
technically src/exceptions
i dont use that extra directory, but otherwise would be like src/athena/exceptions
i guess i kinda use the org/repo name as the first two components to that