Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 11:26
    mamantoha synchronize #11750
  • 11:01
    mamantoha synchronize #11750
  • 10:54
    mamantoha synchronize #11750
  • 10:48
    mamantoha edited #11750
  • 10:48
    mamantoha edited #11750
  • 10:48
    mamantoha opened #11750
  • Jan 16 23:10
    skurhse closed #11739
  • Jan 16 19:55
    Blacksmoke16 unlabeled #11749
  • Jan 16 19:55
    Blacksmoke16 labeled #11749
  • Jan 16 19:25
    wolfgang371 closed #11749
  • Jan 16 18:41
    wolfgang371 opened #11749
  • Jan 16 18:41
    wolfgang371 labeled #11749
  • Jan 15 22:21
    Blacksmoke16 labeled #11748
  • Jan 15 21:50
    BrucePerens edited #11748
  • Jan 15 21:49
    BrucePerens labeled #11748
  • Jan 15 21:49
    BrucePerens opened #11748
  • Jan 15 19:05
    straight-shoota labeled #11747
  • Jan 15 19:05
    straight-shoota labeled #11747
  • Jan 15 19:05
    straight-shoota opened #11747
  • Jan 15 13:30
    straight-shoota labeled #11745
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
mfiano
@mjfiano:matrix.org
[m]
Ok, well it works explicitly listing each file in toposorted order. I'll work on organizing by concept next.
Unrelated:
What is an easy way to test the expansion of a macro you're in the process of writing? The crystal vim plugin has a function for this but it is bugged half the time. So I guess, what is the builtin way, and is there any 3rd party improvement, or utilities for writing macros in general?
George Dietrich
@Blacksmoke16
wouldn't that just be testing the functionality it generates?
dont really need to test the macro part of it specifically
mfiano
@mjfiano:matrix.org
[m]
I would like to see the generated code is what it is supposed to be before testing functionality. I've caught subtle errors that way in my years of macro writing.
George Dietrich
@Blacksmoke16
ohh i see
add a {{debug}} to the end of the macro
mfiano
@mjfiano:matrix.org
[m]
I see. Not sure how I missed that in the api docs. Would have been nice when I wrote the macros earlier.
Very nice
Are there any common general utility libraries for Crystal?
Things that got rejected for the stdlib, or things useful for everyday programming that didn't make it into the language yet for some reason or other?
George Dietrich
@Blacksmoke16
Like what?
There are some, but depends on what you are doing exactly
I'd definitely suggest using https://github.com/crystal-ameba/ameba tho
mfiano
@mjfiano:matrix.org
[m]
I have that and debug.cr so far. I meant like general purpose utilities. Lisp has "alexandria", which includes necessities like correct macro writing macros such as once_only I discussed before, pattern matching stuff, etc etc
George Dietrich
@Blacksmoke16
Can't say I've heard of debug.cr. I also use Athena's spec component sometimes, but other than that nothing comes to mind stdlib usually has everything I need.
mfiano
@mjfiano:matrix.org
[m]
debug.cr is basically pp! but with color, line numbers, etc, and can use in the middle of expressions
George Dietrich
@Blacksmoke16
Fair enough