<postmodern>
so I'm looking to port some ruby code that maps some not-so-great JSON. Using the @[JSON] annotations, do I have to create a class for _every_ JSON element, or can I create deep mappings that go into other JSON arrays/hashes?
<postmodern>
Daniel-Worrall, that is a cool website! However... it appears to generate classes for all of the intermediate "*_data" JSON Hashes, which I kind of want to omit as it adds unnecessary objects/depth to the data structure.
<FromGitter>
<watzon> Yeah unfortunately there's currently no way to do deep mapping of any kind without creating each individual object as a class
<postmodern>
darn. i guess i'd have to use macros to create deep-aliases to skip past the foo_data objects
<Andriamanitra>
you'd probably be done by now if you had just written those classes :p
hightower2 has joined #crystal-lang
<yxhuvud>
It should also be possible to parse into JSON::Any and then work with that. It is probably not very nice though.
<postmodern>
yeah last time i looked at parsing YAML manually, there's a way to manually coerce each field into the type i want. So in theory I should be able to write my own explicit from_json mapping methods?
hightower2 has quit [Ping timeout: 240 seconds]
sagax has joined #crystal-lang
<repo>
but... why?
<repo>
you say you want to omit unnecessary depth to the data structure, that you said was deeply nested. how is the depth unnecessary?
<postmodern>
repo, because it's annoying as heck to have to write vendor.vendor_data[0].product.product_data[0]. etc
<postmodern>
repo, and if you look at the above .json link, you'll note that the "*_data" JSON Hashes don't really serve a purpose and could be inlined into the parent Hash.
<repo>
i'm pretty sure you'd never do that but rather iterate ever so deeper into your structure thus bringing deeper and deeper objects into scope and calling methods on them directly
<repo>
you could easily add methods and/or delegate to nested objects to access their data from above
<postmodern>
repo, right i want to skip past the unnecessary JSON Hashes, but it looks like i'll have to write that code explicitly instead of using JSON::Serializable
<repo>
how so?
<repo>
just leave them out?
<repo>
you don't have to add each and every key to your classes attributes
<repo>
e.g.: `class Foo; include JSON::Serializable; getter foobar : String; end; Foo.from_json(%|{"foobar":"foo","bar":"baz"}|)` is completely valid
<repo>
(not if you add `JSON::Serializable::Strict` i think it was)
<postmodern>
repo, because i need to pull in the elements of "foo" and "foo_data" Hash into a single class Foo, instead of having two classes Foo and FooDatum. See the above linked ruby code as an example.
Volk has joined #crystal-lang
<FromGitter>
<asterite> postmodern: you could have a generic type that represents an array with one element. Or a custom deserializer maybe
<FromGitter>
<naqvis> postmodern: As Ary said above, you'd better go with custom deserializer ⏎ https://carc.in/#/r/a98j
<postmodern>
naqvis, awesome, that looks compareable to what i have in ruby
<FromGitter>
<naqvis> 👍
<FromGitter>
<naqvis> @asterite quick question on scope of nested classes. Language allows nested classes, but why it doesn't give exposure of its enclosing class to nested class? I mean one can not access enclosing class members/methods from inside nested class. Is there any specific reason behind this restriction?
<raz>
hum, interesting idea. 🤔 i imagine the reason might be because ruby also doesn't do this (afaik). but it could indeed be a way to make nesting more useful than for mere namespacing.
<yxhuvud>
If you want that, you have inheritance. No need to mix them up.
<yxhuvud>
(IMO it would make nesting a lot *less* useful).
<FromGitter>
<asterite> @naqvis do you have a code example so I can understand it better? Do it mean for it to work like in Java?
<raz>
hm, not sure how it would make it less useful, but agree it might add more confusion than utility
<FromGitter>
<asterite> Oh, I see, it's just about class members and methods. Hmm... the answer is that's not how Ruby works, so that's not how Crystal works.
<FromGitter>
<HertzDevil> the ability to do that in java is most certainly a byproduct of its lambda-like initializers imitating closures
<FromGitter>
<jrei:matrix.org> anyone familiar with https://github.com/ysbaddaden/pool, I have few questions regarding the implementation
<FromGitter>
<jrei:matrix.org> different fibers could use the same instance, one after the other is done (for example, requests in HTTP::Server)
<FromGitter>
<jrei:matrix.org> sounds like to be mainly an optimization, according to the code comment
<FromGitter>
<jrei:matrix.org> Not sure it is worth is, Deque push and unshift should be fast
<FromGitter>
<naqvis> yxhuvud I don't know how nested classes make things less useful or cause confusion? imho nested classes ⏎ ⏎ 1) is a way of logically grouping classes that are only used in one place ⏎ 2) increases encapsulation ⏎ 3) lead to more readable and maintainable code ... [https://gitter.im/crystal-lang/crystal?at=5fff1fffd5f4bf2965e41043]
<yxhuvud>
naqvis: if they magically inherited behaviour from the outer classes like you suggested, then that would be hurtful is what I claim.
<FromGitter>
<naqvis> its just scope issue, does blocks/closures usage hurt programmers?
<FromGitter>
<naqvis> Thanks Ary and raz for explaining that this behavior is inherited from Ruby
riffraff169 has left #crystal-lang [#crystal-lang]
<yxhuvud>
it is not just a scope issue, what if the methods would refer to instance variables etc?
<straight-shoota>
ehm, is this about instance methods? That can't work
<FromGitter>
<naqvis> that's what i explained above the benefits of nested classes. Consider two top-level classes, A and B, where B needs access to members of A that would otherwise be declared private. By hiding class B within class A, A's members can be declared private and B can access them. In addition, B itself can be hidden from the outside world.
<FromGitter>
<naqvis> that's what "increases encapsulation"
<straight-shoota>
okay that's just about visibility then
<straight-shoota>
I associated ivar access with Java's inner classes
<FromGitter>
<naqvis> yeah, java treat nested classes in this way
<FromGitter>
<naqvis> question was raised, as language does allow declaring class inside an class, but it doesn't offer any benefit other than just a namespacing
<straight-shoota>
Crystal's nested types is like Java's static classes
<straight-shoota>
the namespacing gives nested classes access to the parent namespace
<straight-shoota>
you can call private Foo.foo from Foo::Bar.bar
<FromGitter>
<deepj> Thanks. That I tried without any successful result + (it describes using LLVM 10 under Rosetta 2. I have Homebre for ARM only + LLVM 11). So I'm looking for someone who has been successful with a compilation on ARM only environment.
<raz>
i'd love to beta-test an arm build when one becomes available (but lack the llvm-fu to realistically help with getting it to work myself)
<FromGitter>
<Blacksmoke16> my understanding is arm is supported but m1 is not 100% the same as normal arm
<FromGitter>
<Blacksmoke16> hence why it doesnt work atm
<FromGitter>
<jrei:matrix.org> normal ARM?
<FromGitter>
<Blacksmoke16> non apple*
<FromGitter>
<jrei:matrix.org> The C bindings should be fairly similar to those of x86-64 mac
<FromGitter>
<jrei:matrix.org> both are 64bit and same OS
<FromGitter>
<jrei:matrix.org> like for Linux
<FromGitter>
<Blacksmoke16> right, fairly similar but not the same. Hence why it doesnt work out of the box?
<FromGitter>
<jrei:matrix.org> that's expected, the opposite would have been surprising
<_ht>
Can I run the crystal compilere from a Spec.before_suite? I need to compile a test program for system/integration tests.
<_ht>
Or should I do this via Process and just run the Crystal compiler as a system command?
<FromGitter>
<Blacksmoke16> could you build the binary via `shards build` then use that binary in your specs?
<FromGitter>
<Blacksmoke16> depends on exactly what you want to test tho
<straight-shoota>
_ht sure, you can run system command in spec hooks, why not? =)
<straight-shoota>
I use make for such integration tests, though
<raz>
+1 for make
<_ht>
straight-shoota: THere might be a more crystallic way of doing things
<straight-shoota>
`make test` builds the binary and then runs integration specs
<_ht>
That sounds like something I should investigate.
<straight-shoota>
and unit tests before that
<_ht>
WOuld you prefer "make" over "shards build", like Blacksmoke16 suggested?
<_ht>
Or are they totally different things?
<FromGitter>
<Blacksmoke16> pretty sure make would call that
<straight-shoota>
although I might prefer `crystal build` directly
deavmi has joined #crystal-lang
<_ht>
And then stop using "Shards / crystal" as the main build / test tool and move to this more generic make program
<straight-shoota>
because `shards build` has indirection (which file is build) that you really don't want in a makefile
<straight-shoota>
I use make for every Crystal project
<raz>
+2
<FromGitter>
<Blacksmoke16> and ofc could use make in CI
<raz>
i use make for every project, period
<FromGitter>
<Blacksmoke16> then an use it there and manually
<FromGitter>
<Blacksmoke16> can*
<straight-shoota>
raz +1, just wanted to emphasize on Crystal =)
<raz>
it's a good lowest common denominator to have `make test`, `make dev` etc. make something useful regardless of whether you're in a crystal, ruby, node or erlang project
<_ht>
All right, thanks! These makefiles look readable enough to not be afraid of start using it :-)
<straight-shoota>
yeah, Makefiles can really get out of hand when you look at some of bigger C projects
<straight-shoota>
but when you do only "simple" stuff with it, it's really great
<FromGitter>
<Blacksmoke16> isnt there something that builds the makefile
<FromGitter>
<Blacksmoke16> automake or something
<straight-shoota>
sure, but the only reason such stuff exists is *because* the Makefiles are too complex
<raz>
yea, just start simple. make is like bash. it's immensely useful because it's available everywhere and a great starting point for someone new discovering your project, to easily see how to run a build or tests. but it also has the same caveat of: do not use too much of it. the syntax gets messy quick.
<FromGitter>
<Blacksmoke16> exactly :p
deavmi has quit [Ping timeout: 246 seconds]
<straight-shoota>
at that point you should just use dedicated scripts for individual tasks
<straight-shoota>
or split makefile recipies into individual components
<raz>
yup
<FromGitter>
<jrei:matrix.org> you could do a shell script, like `./run`
<straight-shoota>
if you need that, "make run" can just call that =)
<FromGitter>
<jrei:matrix.org> I don't see the point of an added dependency then
<_ht>
How is the compatibility with Windows, if that's becomes a target for Crystal? I can run make and the like there as well?
<straight-shoota>
the point is, make is a unique entry point for different tasks
<straight-shoota>
yes, cmake on windows should work
<FromGitter>
<jrei:matrix.org> yes but could be shell script this entrypoint. and on Windows, `./run.bat`
<straight-shoota>
then you need to build your own task runner
<_ht>
raz: Thanks!
<straight-shoota>
make is already available, and it's a lightweight dependency because it's typically included in many operating systems
<straight-shoota>
(except windows and BSDs)
<raz>
but on BSDs it's trivially installed anyway and every dev already has it
<raz>
and wintendo doesn't count
<FromGitter>
<jrei:matrix.org> If people like make, ok. Personally, I prefer a shell script
<straight-shoota>
even on windows it's easy to install
<raz>
make is just nicer for all dependency stuff that you tend to want when building stuff
<raz>
that's awful to build in bash
<straight-shoota>
@jrei the killer feature for make is dependencies. It automatically build dependencies if necessary and skips that if they're up to date
<FromGitter>
<jrei:matrix.org> how does it know that?
<straight-shoota>
modification time
<straight-shoota>
if shard.yml is newer than shard.lock, it runs `shards update`
<straight-shoota>
if shard.lock is newer than lib, it runs `shards install`
<straight-shoota>
that's what makes make so big
<straight-shoota>
it's not just a glorified case statement
<raz>
it's a glorified tsort :)
<straight-shoota>
=)
<raz>
one of the most powerful primitives in the universe
<straight-shoota>
(disclaimer: current shards doesn't play nice with modification times, but it's fixed in master)
deavmi has joined #crystal-lang
<raz>
reminds me, i still wish shards would do the dep fetching in parallel, would be so much faster
* raz
once looked into adding that, but the resolver code was above my head
<raz>
it's just a bit depressing when working with node and crystal in parallel. shards takes like half a minute to fetch 8 deps. while yarn downloads half of github before i've finished typing the command.
<straight-shoota>
yeah, that should be a great performance improvement
<FromGitter>
<jrei:matrix.org> this Make feature does not justify to use it, find another one :)
deavmi has quit [Read error: Connection reset by peer]
<FromGitter>
<jrei:matrix.org> Sure Make has lots of black magic. That is nice, but I find it hard to deal with it
* straight-shoota
is looking for a make to bash transpiler to show some spaghetti code
<straight-shoota>
I used to think like that
<straight-shoota>
but when I started using make I grew to really like it
<FromGitter>
<jrei:matrix.org> For simple Makefiles, I'd use sheel scripts. For more complex, Meson
<raz>
then you're missing out on the sweet spot :)
<raz>
fancier builders than make exist, but unless you're the only user of your project they tend to put up an adoption barrier (as nobody knows how to use them)
<raz>
typing "make" to build the thing you just download just has been the law since the beginning of unix time
<FromGitter>
<jrei:matrix.org> also `./configure`
<raz>
to the point where most projects that do use a fancier builder also include a makefile to invoke that builder
<straight-shoota>
fancier build systems just allow you to hide the complexity instead of avoiding it
<straight-shoota>
a makefile with high complexity immediately screams at you :D
<raz>
+3 :)
* straight-shoota
has no look finding a transpiler
<straight-shoota>
*luck
<FromGitter>
<jrei:matrix.org> for now I did use python and shell for simple tasks, working good :)
<straight-shoota>
sure, it's always what suits you best
<straight-shoota>
but when different people use the same project, it's good to have some standardized way to define tasks
<FromGitter>
<jrei:matrix.org> Indeed. That depends also on the underlying language too
<straight-shoota>
yeah, to some extend
<FromGitter>
<jrei:matrix.org> for example in Node it is usually npm/yarn
<straight-shoota>
but I really don't se the point of everyone having a build system in their language
<straight-shoota>
that just destroys interoprability between ecosystems
<FromGitter>
<jrei:matrix.org> they are usually better suited for the language ecosystem
<raz>
pkg-tool != build-tool tho
hightower2 has joined #crystal-lang
<straight-shoota>
+2
<FromGitter>
<jrei:matrix.org> yes sure
<straight-shoota>
that's why I'm not that fond of `shards build` and postinstall
<straight-shoota>
altough that's probably fine
deavmi has joined #crystal-lang
<FromGitter>
<jrei:matrix.org> nearly all modern language package managers have this kind of command
<FromGitter>
<oprypin:matrix.org> Make has exactly 1 useful feature, thats checking if a file is modified
<FromGitter>
<oprypin:matrix.org> everything else is garbage but apparently that 1 feature is enough for people
<raz>
it absolutely is
<FromGitter>
<jrei:matrix.org> and it is simple to do in bash and with find, so... moderately useful
<raz>
when you look at the alternatives you see that almost nobody else (perhaps with the sole exception of cargo) got even that one right.
<raz>
"do one things well" trumps "do a dozen things terribly" any day of the week
<FromGitter>
<oprypin:matrix.org> well it does also do a dozen things terribly
<raz>
yes, but you can use it for the one thing reliably and ignore the rest
<raz>
try doing that while writing a Gulpfile
<raz>
or a Barfrc, or whatever the latest thing in js land is ;)
deavmi has quit [Ping timeout: 246 seconds]
_ht has quit [Remote host closed the connection]
<raz>
even something as mature as cmake stops most users in their tracks with "cmake not installed" and then "eek, what is this syntax"
deavmi has joined #crystal-lang
deavmi has quit [Ping timeout: 246 seconds]
deavmi has joined #crystal-lang
<FromGitter>
<oprypin:matrix.org> cmake does a million things terribly
<raz>
i think now we're hitting a circular dependency 😬
<pyra>
if only rake was used for things outside of ruby
<FromGitter>
<kingsleyh> evening - my crystal blockchain project Axentro is going to be listed on an exchange soon and we are running an IEO (fund raising) as well in the coming weeks. If anyone is interested or knows anyone who might be interested in at first helping out with supporting us technically especially during these early steps and then for some money after we raise some please let me know. Since Crystal is a very niche
<FromGitter>
... language and then Blockchain tech within Crystal is also very niche - I'm also looking to the Ruby community - as they are also expanding their crypto efforts - and have an upcoming ruby crypto week where they showcase their crypto libs etc - so also any Ruby people - or in fact anyone with any kind of technical stills - I'll ... [https://gitter.im/crystal-lang/crystal?at=5fff6f399632f63d871601e6]
<FromGitter>
<jrei:matrix.org> Great news!! You could probably looks into the Julia community too I guess
<FromGitter>
<kingsleyh> oh yeah good suggestion thanks :)
<FromGitter>
<jrei:matrix.org> also, I think the most important is the background rather that knowing the language (which is also important).
<FromGitter>
<jrei:matrix.org> for instance, if most of people reading your post are RoR devs, not sure lots of relevant people will come on
<FromGitter>
<kingsleyh> yeah - I can work with anyone who is willing to be honest - as long as they are able to pick things up - at the moment I'm doing 99% of all the technical work - but I would like to share that burden since we have now started to get an influx of miners who are always asking questions, pointing out bugs - some of which I need to fix urgently and others which are not so important. All this extra support work
<FromGitter>
... along side my normal day job and my family (wife and 2 kids) is definitely not sustainable - I can manage for a while - but if interest picks up even more then I'm going to struggle to keep up.
<FromGitter>
<jrei:matrix.org> absolutely. And it is always good to be 2. If someone is not available, the other can keep up
<raz>
yup, community-building might be a next step (unless there already is one?). most coins have a discord where people gather
<raz>
congrats for getting on an exchange btw (even if it's a small one i know how hard that is)
<FromGitter>
<jrei:matrix.org> I have seen quickly the matrix channels related to blockchain. The most popular one is Cosmos Network. I'm seeing what is it currently
<raz>
yup, i guess the chat network varies by coin
<raz>
but it goods to have a campfire for the community to gather
<FromGitter>
<jrei:matrix.org> @kingsleyh: Bar Hofesh works now on Axentro? He left NeuraLegion?