<FromGitter>
<Sija> @jwaldrip feels like days ahead...
cerulean has left #crystal-lang [#crystal-lang]
rohitpaulk has joined #crystal-lang
txdv has quit [Ping timeout: 240 seconds]
Groogy_ has quit [Ping timeout: 240 seconds]
Yxhuvud has quit [Remote host closed the connection]
Groogy_ has joined #crystal-lang
Yxhuvud has joined #crystal-lang
txdv has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
baweaver has quit [Ping timeout: 255 seconds]
tatey has quit [Ping timeout: 240 seconds]
baweaver has joined #crystal-lang
tatey has joined #crystal-lang
baweaver is now known as Guest33209
greenbigfrog has quit [Ping timeout: 255 seconds]
brycek has quit [Ping timeout: 255 seconds]
brycek has joined #crystal-lang
greenbigfrog has joined #crystal-lang
<FromGitter>
<jwaldrip> @Sija many days, or few days?
Groogy2 has joined #crystal-lang
Groogy has quit [Ping timeout: 255 seconds]
andrewzah has quit [Ping timeout: 240 seconds]
andrewzah has joined #crystal-lang
jaitaiwan has quit [Ping timeout: 255 seconds]
<FromGitter>
<jasonrobot> Hey got a question that's kinda a "best practices" thing:
<FromGitter>
<jasonrobot> I'm making a class that can go to/from JSON and DB, and I'm using the .mapping() macros for both of those, but I'm kinda concerned that they're re-defining a bunch of stuff (initialize methods, getters/setters).
jaitaiwan has joined #crystal-lang
<FromGitter>
<jasonrobot> Is that just fine? It seems like a bad thing. The code still seems to work, but I dont know if there might be stuff happening that I'm not aware of in all that macro expansion.
<FromGitter>
<fridgerator> I use both together, I haven't had any issues
A124 has quit [Ping timeout: 246 seconds]
<FromGitter>
<jasonrobot> Nice. I was thinking of writing my own, but hey if they both work.
A124 has joined #crystal-lang
<FromGitter>
<jasonrobot> I'm also trying to figure out how to use "crystal tool expand", but can't quite seem to figure out the arguments to it...
jaitaiwan has quit [Ping timeout: 240 seconds]
jaitaiwan has joined #crystal-lang
zacts has joined #crystal-lang
gokmen has quit [Remote host closed the connection]
<FromGitter>
<faustinoaq> > who is working on crystalox? ⏎ >> There have been at least three Crystal OS'es ⏎ ⏎ @monouser7dig yeah, just search for OS https://crystalshards.xyz/?filter=os, maybe using a custom prelude or `--prelude=empty` Crystal would be capable to do more low level stuff, maybe disabling GC and doing some unsafe things 😉 [https://gitter.im/crystal-lang/crystal?at=59d722d4177fb9fe7e45778d]
<FromGitter>
<faustinoaq> Hey community, I will talk tomorrow about Crystal at my University. I hope I can introduce some classmates this awesome language. 😄
<FromGitter>
<ekremkaraca> @faustinoaq good luck!
<FromGitter>
<ekremkaraca> And good morning guys
<FromGitter>
<ekremkaraca> 🌄🌞
<FromGitter>
<faustinoaq> @ekremkaraca Thanks you 👍
<FromGitter>
<faustinoaq> And good morning too ☀️
gokmen has quit [Quit: bye.]
<FromGitter>
<Rinkana> Morning :)
Groogy_ is now known as Groogy
<Groogy>
Morning
<FromGitter>
<monouser7dig> @jasonrobot `Usage: crystal tool expand [options] [programfile] [--] [arguments]` which you may have already seen yourself so you should be able to give a filename and just by default gets the file with macro substitutions out?
<FromGitter>
<jasonrobot> If I just call "crystal tool expand foo.cr" it just prints the command's help menu though
<FromGitter>
<jasonrobot> call -> run, whichever
<FromGitter>
<jasonrobot> I've tried piping in through stdin, using all the different args (none of them are to specify an input file either). Its really got me stumped.
<FromGitter>
<monouser7dig> `crystal tool expand -c ./Desktop/fun.cr:32 ` thought that would work but it does not 😄
snsei has quit [Remote host closed the connection]
<FromGitter>
<monouser7dig> just use `crystal build test.cr —emit llvm-ir —prelude=empty` and check if the expansion worked 😄
<FromGitter>
<faustinoaq> @monouser7dig you should use `crystal tool expand -c `pwd`/foo.cr:line:column `pwd`/foo.cr`
<FromGitter>
<monouser7dig> crystal run, build, tool hierarchy, all work with relative filenames 😄 but indeed you are right
<FromGitter>
<monouser7dig> actually this does too
<FromGitter>
<faustinoaq> Yeah, you can use relative names too, but ensure to repeat filename at the end of command.
<FromGitter>
<monouser7dig> Usage: crystal tool expand [options] [programfile] [--] [arguments] ⏎ could be ⏎ Usage: crystal tool expand [options] [programfile with LNR][programmfile] [--] [arguments] ⏎ (why does It need the programmfile twice at all?) [https://gitter.im/crystal-lang/crystal?at=59d7304e177fb9fe7e45b46a]
mark_66 has joined #crystal-lang
Papierkorb_ has joined #crystal-lang
<Papierkorb_>
Morning!
<FromGitter>
<jasonrobot> agh, and its complaining about "require 'db'" earlier in the file. I was really hoping it would just show the source file after macro expansion.
<FromGitter>
<faustinoaq> @monouser7dig Because the second filename will be different, some projects can use different files, you can use a macro in one file and his definition in other.
<FromGitter>
<faustinoaq> Maybe sublimetext 3 do support this, but sublime package for crystal will need to implement these features. ⏎ ⏎ 😅 Hey Papierkorb, what pattern do you recommend to write a QT program, I mean some of these patterns 👉 https://github.com/crystal-community/crystal-patterns
<FromGitter>
<faustinoaq> I only used two pattern before, MVC for web development, and the Repo pattern for manage DB using Crecto (https://github.com/Crecto/crecto). ⏎ ⏎ I'm afraid my crystal+qt code will become in spaghetti code 😅
<Papierkorb_>
faustinoaq, I don't think that there's a one-size-fits-all pattern for anything. But if you want to see Qt code, have a look at their vast example section. Here's the section on widgets: http://doc.qt.io/qt-5/examples-widgets.html
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Papierkorb_>
faustinoaq, There are two things: 1) Think in objects 2) Think in signal/slot relations. Qt5.cr itself doesn't allow you to add Qt signals to your classes, you can use the "cute" shard for that.
<Papierkorb_>
faustinoaq, Really, signal/slot is the biggest factor when starting out with Qt. So focus on that part first. It completely reverses the code flow from "I need to have access to X" to "Someone give me X if wanted". You don't pull information, you push information.
<FromGitter>
<faustinoaq> Ok, Thanks you Papierkorb! 👍
<Papierkorb_>
faustinoaq, Which is a god send for complex applications (With or without Qt) imho. For applications, I'll use the "architecture" I've been using for a while now, simply because it didn't break yet
rohitpaulk has joined #crystal-lang
<Papierkorb_>
faustinoaq, just don't smash everything into MVC. You'll create much more issues for yourself than needed without actual gain.
<Papierkorb_>
faustinoaq, start small. Build a some small utility programs, like an image viewer or something. After that thing works, take a look again not at your code, but at the structure, and see what you like and don't like about it.
<Papierkorb_>
I wasn't able to get around to working on Qt LibEvent integration yet. So doing e.g. networking won't be fun right now
<Papierkorb_>
faustinoaq, if you have a certain question w.r.t. structuring a specific (simple-y) application, I'd use it to write a whole sample/ out of it. You won't be the only one wondering :)
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 255 seconds]
<FromGitter>
<monouser7dig> is it considered good style to omit the return keyword at the end of a method? seeing this quite a bit and personally just always type it
<FromGitter>
<faustinoaq> I'm trying to load some ui files I did on QtDesigner
<Papierkorb_>
1) You're using the Qt4 docs, you want the Qt5 docs! Don't trust Google to choose Qt5 over Qt4. 2) I didn't try adding it yet
<Papierkorb_>
monouser7dig, Yes it's good style to omit it, and most consider it bad style to have needless returns
claudiuinberlin has joined #crystal-lang
Guest33209 is now known as baweaver
baweaver has quit [Changing host]
baweaver has joined #crystal-lang
<FromGitter>
<faustinoaq> Papierkorb, yeah, you are right, I mean http://doc.qt.io/qt-5/quiloader.html, Also I just realize you put Qt Designer support in the roadmap. How ui files will be used by qt5.cr, something like PyQt ?
<FromGitter>
<faustinoaq> I just downloaded the MacOS iso, next step is trying to create a VM 😅 some hacking stuff here 😎
<Papierkorb_>
Are you planning on using Mac OS?
<Papierkorb_>
I never used a hackintosh VM not because of durr-legal, but really, because I simply don't care about using Mac OS, and thus can't maintain code for it
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 258 seconds]
claudiuinberlin has joined #crystal-lang
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<monouser7dig> making GUI wrapper and being more interested in arch than macOS is a funny combination 😄
claudiuinberlin has joined #crystal-lang
<Papierkorb_>
..?
<Papierkorb_>
Me wanting to know what my computer is doing doesn't contradict me wanting to have a fully featured graphical UI
<Papierkorb_>
I personally think Mac OS UI is awful
<Papierkorb_>
And them not being FOSS is a "No Thanks" already
<FromGitter>
<monouser7dig> arch is more the CLI + i3 beginning with how it is installed and configured but no offense, arch is also for those that tune it into a nice custom gui, sure ⏎ ⏎ I'd also use arch for some but Broadcom wifi chips are just sigh, *need* some Mac things
<Papierkorb_>
KDE all the way on all machines
rohitpaulk has quit [Ping timeout: 240 seconds]
RickHull has quit [Ping timeout: 260 seconds]
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<monouser7dig> do you have daily crystal builds for arch? thought I've seem sth. like that in the ci?
<Papierkorb_>
No idea, I just use the version from the repository
<FromGitter>
<sdogruyol> I'm waiting for the new Firefox Quantum
<FromGitter>
<sdogruyol> had enough with Chromium lol
<FromGitter>
<monouser7dig> `OS images and packages are now built automatically by a lightweight Golang program.` is this the new hip?
<Groogy>
is that the browser done entirely in rust?
<FromGitter>
<monouser7dig> only the ending `servo` seems to be pure rust
<FromGitter>
<sdogruyol> guess it'd be really hard and time consuming to a full browser in rust after all
<FromGitter>
<sdogruyol> servo is pretty good
<Groogy>
didn't some indie guy make rust based game?
<FromGitter>
<sdogruyol> haven't seen it
<FromGitter>
<sdogruyol> why not?
<Groogy>
think I heard someone mention that while prophecising how rust was going to change the entire world
<Papierkorb_>
FF is more than "just" the rendering engine
<Groogy>
there is obviously also the memory absorption engine (•_•) ( •_•)>⌐■-■ (⌐■_■)
<Groogy>
a cruical part of its framework
<Papierkorb_>
Porting the whole thing will take years of an dedicated effort that they can't make without not updating the browser in the meantime
Papierkorb_ has quit [Remote host closed the connection]
<FromGitter>
<sdogruyol> well the only thing that I hate about FF is there's no easy way of using multiple user profiles as in Chrome
<livcd>
oh but i read the idea is not to rewrite everything in FF in Rust but incrementally change what makes sense
<FromGitter>
<monouser7dig> that is the idea of rust after all 😄
Papierkorb_ has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<Rinkana> Ooh, liri looks awesome
<FromGitter>
<monouser7dig> Groogy how is Liri supposed to handle existing apps like Thunderbird? they seem rather restrictive in making everything qt and wile I am not sure TB is qt based I bet many things are not and thus it might be quite limiting?
<Groogy>
It does I know :D
<Groogy>
Eh other things will still work
<Groogy>
as long as it can work through wayland
<Groogy>
wayland has a x server plugin as well I think for apps that rely on x servers
<livcd>
well well ...for me the OS needs to go out of my way
<Papierkorb_>
Correct. Something thinks it knows better than me? Into the trash it goes.
<Groogy>
I like liri in how minimalistic and sleek the interface seems to be
<livcd>
i am happy with OSX/Windows thanks but thanks :)
claudiuinberlin has joined #crystal-lang
<Groogy>
hopefully it stays as that
<Groogy>
I've never used window managers like that
<FromGitter>
<monouser7dig> if you use tmux on Mac you get at least i3 for cli 😄
<livcd>
I use tmux on mac yes :)
<livcd>
imho the OS of 2017 and beyond is the browser
<FromGitter>
<monouser7dig> for consumers sure, for producers???
<Papierkorb_>
"Everything in the cloud!" No thanks.
<livcd>
well i wonder how long will it take for Apple to merge osx/ios into one
<FromGitter>
<ekremkaraca> Hey guys, I have set a new personal record of building Crystal: 13 min 12sec
<FromGitter>
<monouser7dig> if it is not about bigdata in a blockchain hostel by KI in the docker cloud, I'm out 😄
<FromGitter>
<ekremkaraca> It was 14 min on my previous trial
<FromGitter>
<monouser7dig> crystal compiler or personal project?
<FromGitter>
<ekremkaraca> Building Crystal
<FromGitter>
<ekremkaraca> Installing by building
<Papierkorb_>
Takes less than 5 minutes on my machine
<FromGitter>
<ekremkaraca> What do I need to reduce the time
<Papierkorb_>
Your machine specs?
<Papierkorb_>
With or without full test run?
<FromGitter>
<ekremkaraca> 6GB ram
<FromGitter>
<ekremkaraca> I suppose full run
<Papierkorb_>
That are not the full specs, but 6GiB is not much at all
<livcd>
it's interesting how far people are willing to go -> Electron
<FromGitter>
<ekremkaraca> Intel i5 core
<Papierkorb_>
There are many i5's
<FromGitter>
<monouser7dig> crystal takes 1,6gb on my side compiling, cpu quad core or dual will make a difference
<FromGitter>
<ekremkaraca> I have older one
<FromGitter>
<ekremkaraca> Cpu quad
<Papierkorb_>
Invest in RAM. Upgrade to 16GiB and you'll never have any issues with memory anymore (citation needed)
<livcd>
unfortunately people build very shitty apps..even the large tech corps are building for "best case scenario"
<FromGitter>
<ekremkaraca> I did it with brew
<FromGitter>
<monouser7dig> some think they are quad although they are just hyperthread? 😄
<FromGitter>
<ekremkaraca> Or Linuxbrew
<livcd>
everyone assumes you have the most performant phone / pc and a reasonable internet speed
<Papierkorb_>
livcd: Yes and now their crap code doesn't only run on their servers and waste CPU on the consumers devices, but their crap server AND awful UI code runs on my machine. What a time to be alive.
<FromGitter>
<ekremkaraca> I want but my family don't :(
<FromGitter>
<ekremkaraca> Maybe after army
<livcd>
Papierkorb_: sadly
<livcd>
it sucks
<livcd>
especially if you travel a lot
<Papierkorb_>
livcd: It makes me sick when I think how much real-world resources are wasted world-wide because of awful code.
<livcd>
i do not care about any of this when I am in Korea with unlimited lte plan
<FromGitter>
<sdogruyol> @ekremkaraca good luck
<livcd>
but...
<livcd>
I guess it's really expensive and requires too much effort to build a proper app that behaves nice even when you are offline / on slow connection
<FromGitter>
<monouser7dig> used linuxbrew on pi a bit and was not really bad, the only issue is getting precompiled bottles cause for whatever reason their default install path has the result that you can not use their bottles
<livcd>
it's an impossible task like building a reasonably good crossplatform UI kit (or at least reasonably good on OSX/Windows)
<livcd>
no wonder electron is that popular
<livcd>
sigh
<Papierkorb_>
Qt has been around for ages
<Papierkorb_>
And is "reasonably good crossplatform" way beyond those two
snsei has joined #crystal-lang
<FromGitter>
<ekremkaraca> At least I should make some pressure on my family to buy Mac mini
<livcd>
eh most qt applications make me to vomit
<FromGitter>
<ekremkaraca> It's harder to find here
<FromGitter>
<ekremkaraca> Here I mean, 🇹🇷
<FromGitter>
<ekremkaraca> Except Apple store 💲
<FromGitter>
<monouser7dig> 8m27s 2,5gb ram usage on a dual core i7, using brew ⏎ if speed is a concern why would you buy a Mac
<FromGitter>
<ekremkaraca> It seems that it's about processor
<Papierkorb_>
livcd: KDE applications look fine to me
<Papierkorb_>
ekremkaraca, if you like the Mac OS and everything about mac, buy a mac. If you're looking for the best bang for the buck, don't buy a mac.
snsei has quit [Ping timeout: 246 seconds]
<livcd>
Papierkorb_: they always looked out of place to me
<FromGitter>
<ekremkaraca> I should at least get an 87
<livcd>
I cant actually name a single QT app that I like or liked to use
<FromGitter>
<ekremkaraca> Not 87, i7
<FromGitter>
<ekremkaraca> Apologize guys :(
<livcd>
Papierkorb_: but i just checked built with QT and the "hiri" mail app looks nice
<Papierkorb_>
ekremkaraca, nothing much to do with i5 or i7 by itself. My computer at home has a i5, and is still faster than most mac's you can buy. With Mac, you buy into the experience, you don't "just" by a computer
rohitpaulk has joined #crystal-lang
<FromGitter>
<ekremkaraca> Thanks
<FromGitter>
<monouser7dig> sitting with a friend wo uses arch, Lenovo dual core i5 and me 13inch mb he always has < 1 load average when idling, I always 1,6 when idle 😄
<Papierkorb_>
ekremkaraca, those tiny mac mini and notebooks don't have the capabilities to cool a good processor under full load without the processor running slower. It's a physical restriction. If you want raw power, buy a tower computer.
<FromGitter>
<ekremkaraca> Thanks Papierkorb_
<FromGitter>
<ekremkaraca> Ah mentioning :(
<Groogy>
livcd I kind of like Qt Creator
<Groogy>
it's decent enough
<Groogy>
though I might switch out for VS Code at work soon
<FromGitter>
<sdogruyol> 8m27s to compile Crystal?
<livcd>
ok hiri looks nice
<FromGitter>
<monouser7dig> yes
<livcd>
i wonder if it's all just QT
<FromGitter>
<sdogruyol> here I'm complaining of a mere 20 seconds..
<FromGitter>
<monouser7dig> the crystal compiler
<Papierkorb_>
sdogruyol, with --release?
<FromGitter>
<monouser7dig> you either have threadripper or talk about a different project 😄
<FromGitter>
<sdogruyol> ah hell no
<FromGitter>
<sdogruyol> I won't do --release ever :D
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<sdogruyol> on the compiler :D
<livcd>
I hope Crystal will be one day a good alternative to Go :-)
<FromGitter>
<monouser7dig> lol
<FromGitter>
<sdogruyol> let me check though
<Groogy>
already better if you ask me <_<
<Papierkorb_>
^
<FromGitter>
<sdogruyol> ^
<FromGitter>
<sdogruyol> However it needs more adoption and a 1.0 label
<Papierkorb_>
^
<livcd>
well I need windows support
<livcd>
so for me it's not there yet
<Papierkorb_>
wasn't there this "bash on windows" (sic!) thing?
<FromGitter>
<sdogruyol> nope that won't cut it
<Papierkorb_>
Most awful name in existence. Can't expect better from MS
<FromGitter>
<sdogruyol> bash - windows
<FromGitter>
<sdogruyol> that'd better :P
<Papierkorb_>
Not for the end-user, but for dev'ing?
<FromGitter>
<sdogruyol> just kidding
<livcd>
i do not think that's the name of it
<FromGitter>
<sdogruyol> Why do you guys compile the compiler in release anyway?
<Papierkorb_>
Because it makes me compile with it faster?
<Groogy>
Yeah it works
<Groogy>
Though it is Windows 10 only which is bit of a problem
<livcd>
i think the official thing is Windows Subsystem for Linux
<FromGitter>
<sdogruyol> do you use the master branch to compile your Crystal programs all the time?
<FromGitter>
<sdogruyol> then I don't get the reason why you'd do that :P
<Papierkorb_>
Groogy: do you still need to be part of that insider program?
claudiuinberlin has joined #crystal-lang
<Groogy>
no don't think so
<livcd>
go|dfish: windows subsystem for linux :P
<crystal-gh>
[crystal] straight-shoota opened pull request #5084: Add custom time formats (master...jm-time-formats) https://git.io/vd0SR
<Groogy>
don't remember doing anything like that, though my account might already be hooked up
<livcd>
well in any way windows support and parity of features is a must for me
<livcd>
to consider Crystal an alternative to GO
<FromGitter>
<monouser7dig> I've even seen people running gui through wsl, works without insider program for sure
<Groogy>
What do you use Go for?
<livcd>
everything :D
<Groogy>
what is everything?
<Groogy>
i.e what live project do you have running Go?
<FromGitter>
<monouser7dig> generics 😄
<FromGitter>
<sdogruyol> `make clean crystal release=true 405.74s user 4.97s system 99% cpu 6:52.88 total`
<livcd>
ETL, microservices, gui apps on windows (using lxn/walk) etc
<FromGitter>
<sdogruyol> ~7 mins not bad
<Groogy>
cool
<Papierkorb_>
sdogruyol, in any case, 20s for the whole working compiler? And people complain about "those absurd compilation times"?
<livcd>
also deploying to Kiosks that mostly run Windows
<FromGitter>
<monouser7dig> Kiosks?
<Papierkorb_>
Just linking a C compiler would probably take longer
<FromGitter>
<sdogruyol> the weird thing is that a simple kemal app takes longer to compiler @Papierkorb
<livcd>
yes kiosks
<FromGitter>
<sdogruyol> in release mode though
<Papierkorb_>
sdogruyol, I noticed that requiring HTTP::Client always dramatically increased build times for me
<FromGitter>
<sdogruyol> requiring "http" of any kind
<FromGitter>
<sdogruyol> not sure why though
<livcd>
never used a kiosk in mcdonalds or on the airport ? :-)
<FromGitter>
<sdogruyol> `time crystal build --release src/kemal-benchmark.cr ⏎ crystal build --release src/kemal-benchmark.cr 34.42s user 0.52s system 100% cpu 34.762 total ⏎ `
<Papierkorb_>
livcd: Only that self checkout PoS kiosk at the market. Boy that thing is infuriating. The button "I want to use my own bag" has to be hammered about 100 times, but the other button (and all subsequent interactions) react immediately. What a coincidence.
<FromGitter>
<sdogruyol> 1) 42 to compile a barebones kemal app in release mode
<livcd>
Papierkorb_: yeah a lot of kiosks are crap
<livcd>
but some are good
<Groogy>
I know there's a specific file that Clang++ takes like 30 minutes to compile or something if we don't turn off optimizations for that file
<Groogy>
Clang likes to optimize
<FromGitter>
<sdogruyol> coming from Ruby, It feels like eternity (the compile times)
<FromGitter>
<sdogruyol> I can't even imagine using clang lol
<livcd>
Papierkorb_: but as i said building a performant and pleasant UI anywhere is apparently a hard task
<livcd>
just look at the most infotainments
<livcd>
or whatever
<Papierkorb_>
livcd: The joke is that only that button takes ages to work. The other button "yeah take my money for another bag" works immediately, just like everything else there.
<livcd>
Papierkorb_: strange
<FromGitter>
<monouser7dig> coming from ruby one can't even imagine compiling I guess 😄 ⏎ maybe just some strange people write gui because others think they are to knowledgeable to do that but better would
<FromGitter>
<monouser7dig> (mind the `some`) please
<Papierkorb_>
livcd: Do those advertisment displays at places like the doctor also count as kiosks? If so, they just seem to be 1) horribly underpowered 2) horribly badly progrmmed 3) or both. Laggy slideshow :(
<FromGitter>
<sdogruyol> enough about flaming compile times :P
<FromGitter>
<sdogruyol> I still remember Rust pre-1.0
<livcd>
Papierkorb_: not sure what do you mean but i guess so
<FromGitter>
<sdogruyol> taking ages to compile and it's way slower than Crystal at the same stage
<Groogy>
I find Crystal being fast enough, though I have noticed Ego taking like a second to compile now which worries me, since there isn't much stuff there yet
<Groogy>
though also that is in debug
<livcd>
but they are a good example of badly designed user applications
<FromGitter>
<krypton97> Does Crystal compile to a standalone binary app without linked files on both mac/linux?
<FromGitter>
<monouser7dig> Papierkorb, always think the same when using one of those, like a dead cheap pi could power tens of them
<livcd>
1) if it's slow when it just displays data in a nice way then...really ? wtf is wrong with you people
<livcd>
2) but lots of kiosks do validations when they query remote services
<Papierkorb_>
^
<livcd>
so if the network at the airport / mall is slow etc then the user has to suffer
<livcd>
but...
<Papierkorb_>
livcd: Yeah, my dentist has one of those displays where they have an ad for their services, and show stuff like the weather and "news" from some tabloids. Lags like nothing's ever lagged before. It's basically an overkill power point slideshow?
<FromGitter>
<monouser7dig> but they do not need to stream a Netflix show, just get some train arrival bits most of the time ⏎ ⏎ including all deps is still a bit to do I think you can use otool or similar to check @krypton97
<livcd>
well you underestimate how "overengineered" these systems are
<livcd>
you scan your passport at the kiosk and it goes through so many validations that you want to kill someone
<FromGitter>
<krypton97> I took a look on a linux cr app and it had no deps like rust, just a bin app, but it was a simple print.. I know there's also musl that's a replacement for glibc, but not that fast
<Papierkorb_>
The current compiler can link statically
<FromGitter>
<krypton97> Even with c bindings?
<Papierkorb_>
if you provide the necessary static libs, that has always worked
<FromGitter>
<krypton97> I'll take a deeper look when I get home. With go, everything seems to be standalone which makes it very easy to distribute the app
<livcd>
so hit me up when Crystal on Windows is ready :D
<FromGitter>
<krypton97> Can't say the same with rust, there's a bunch of files damn
<Papierkorb_>
krypton97, with Go, it's the same: If you link to shared libs, you'll need to distribute those
<FromGitter>
<krypton97> Great!
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
claudiuinberlin has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 264 seconds]
snsei has joined #crystal-lang
ShalokShalom_ has joined #crystal-lang
snsei has quit [Ping timeout: 264 seconds]
ShalokShalom has quit [Ping timeout: 240 seconds]
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<monouser7dig> oh nvm ⏎ totally missed the macro
claudiuinberlin has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter>
<monouser7dig> could you replace sth. like ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ I mean I do not intend to bother you if you do not want, but maybe one of us learns something (may as well be me) [https://gitter.im/crystal-lang/crystal?at=59d77f81bac826f054410a1c]
<FromGitter>
<monouser7dig> just cause it was like this before, and it is only small, don't you think it is faster?
<Papierkorb_>
No.
<Papierkorb_>
I repeat: Don't use StaticArray.
<FromGitter>
<zyriuse75> do you know if there is a way who i can check the OS ?
<Papierkorb_>
Its behaviour is *not* that of Array.
<FromGitter>
<monouser7dig> cause?
<FromGitter>
<zyriuse75> i mean if the script run on (centos or debian or even mac )
<Papierkorb_>
monouser7dig, Cause you didn't read the docs nor source.
<Papierkorb_>
Using StaticArray just because is equivalent to using struct's just because. Don't.
<FromGitter>
<monouser7dig> it's stack what else?
<FromGitter>
<monouser7dig> there is actually a ton of static array in there but...
<FromGitter>
<monouser7dig> passed by value instead of reference probably if you say like struct
<FromGitter>
<zyriuse75> no one have an idea about how i can check the os with crystal ?
<RX14>
@zyriuse75 well you can use flag? to get the platform in macros
<Papierkorb_>
At compile time ^
<RX14>
what do you specifically need the OS for?
<FromGitter>
<zyriuse75> i need to check if the script turn on debian or centos
<FromGitter>
<zyriuse75> or others os
<RX14>
oh ok then flags dont help at all
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<RX14>
debian isn't an OS to me, it's a distribution
claudiuinberlin has joined #crystal-lang
<RX14>
i'd have told you how to find out if it was on linux, osx or freebsd, etc
<FromGitter>
<zyriuse75> its true sorry distribution :)
<RX14>
you need something like the lsb_release command to find which distro you're on
<RX14>
so just shell out to a couple of those
<Papierkorb_>
Debian is an Operating System which is a Distribution of the Linux kernel and the GNU user space
<Papierkorb_>
zyriuse75, else read `/etc/lsb-release`. Doesn't have to exist though
<RX14>
Papierkorb_, yeah sure but when most people say "check the OS" they mean the kernel
<FromGitter>
<monouser7dig> 😄 so still curious what is wrong with the stack papierkorb?
<Groogy>
on the StaticArray, most methods of Static array also creates normal arrays
<Groogy>
and it is going to screw with your types a lot
<Groogy>
just FYI
<Papierkorb_>
If it does exist, it's the easiest way to check which exact OS you're running on. Another linux specific thing could be using uname(2) to read the kernel version and name. Not that great though
<Groogy>
There's nothing wrong with Static Array or the stack, whats wrong is most likely your reason for using it
<Papierkorb_>
^
<Papierkorb_>
And not knowing about all the implications.
<RX14>
@monouser7dig because it will perform just the same and act 10x weirder
<FromGitter>
<monouser7dig> so you mean static is not faster because it is even slower because it creates a normal array, what do you mean by `screw with the types`?
<Groogy>
no I mean
<Groogy>
if you do static_array.map { |val| do_stuff(val) }
<Groogy>
what type do you think it produces?
<FromGitter>
<monouser7dig> if I have Array(int32) I expect the same back
<Groogy>
yeah but static array is not an Array(Int32)
<Groogy>
it is a StaticArray(Int32)
<FromGitter>
<monouser7dig> yes meant to say that
<Groogy>
so yet again what type do you think the map method will produce?
<FromGitter>
<monouser7dig> so I expect a StaticArray(Int32) back
<Groogy>
because it isn't a StaticArray
<Groogy>
what if you do next in the block?
<Groogy>
and skip an element
<Groogy>
what size would the StaticArray be?
<FromGitter>
<monouser7dig> less
<Groogy>
if it would create a static array instead
<Groogy>
but how would it now it sohuld be less at compile time?
<Groogy>
that is a decision made on runtime?
<FromGitter>
<monouser7dig> > **<Groogy>** if it would create a static array instead?
<Groogy>
Yes but the reason it isn't creating a static array is most probably because of this
<Groogy>
because when invoking #map, or any similar method
<Groogy>
it can't know the size
<RX14>
simply because you can't change the array size means you can't do nice things with it
<FromGitter>
<monouser7dig> so does it give back a normal Array(int32) because it otherwise could not cope with the size changes
<Groogy>
so you'll get an array instead
<RX14>
@monouser7dig being on the stack doesn't inherently make things faster
<FromGitter>
<monouser7dig> yes
<RX14>
you're trying to use staticarray because you think it'll make your code faster
<Groogy>
it won't
<FromGitter>
<monouser7dig> so why do you use it nevertheless? 😄
<Papierkorb_>
This just in: The Stack is also in memory, just next to the heap
<RX14>
if you bastdardized staticarray into working, it STILL wouldn't make a difference to your code
<Papierkorb_>
"you"? You tell us
<Groogy>
because copy by value does have certain behaviours that might be desirable
<RX14>
you make things MUCH harder for NO gain
<Groogy>
I use static array in my Matrix and Vector classes
<Groogy>
because it gives me the behaviour I want
<FromGitter>
<monouser7dig> allright
<RX14>
@monouser7dig because we know the situations when it is faster
<RX14>
99% of staticarray use is for an IO buffer for read
<RX14>
like thats pretty much all they're practically used for
<FromGitter>
<monouser7dig> why is it faster in that case?
<Groogy>
you can get performance boost for memory locality, but you get that on Stack or Heap non the less
<RX14>
because Array.new is much slower than creating a staticarray
<Papierkorb_>
And that already touches the more dangerous things about an static array
<Groogy>
and with how Crystal is built you can't really optimize for that
<RX14>
once you have one the performance difference is minimal
<RX14>
you're unlikely to be creating and destroying arrays at a very high rate
<FromGitter>
<monouser7dig> yeah sure
<FromGitter>
<monouser7dig> thanks
<Groogy>
if your objects have a very low lifetime at a point where it is a performance bottleneck then something is definetly wrong
<FromGitter>
<monouser7dig> I made a benchmark using Int32 static_a, array, array(size) and malloc, will take a short look
<Groogy>
Also keep in mind you can very easily blow the stack
<Groogy>
which we've done a bunch of times with Alloca constructs
<FromGitter>
<monouser7dig> like how easily? alloca?
<Groogy>
As in someone did something wrong once and it would cause the AI to allocate the entire stack in a loop if it looped enough amount of times
<Groogy>
alloca is a construct that allows you to dynamically allocate memory on the stack by moving the pointer where oyu are in memory on the stack
<Groogy>
it is also told by like everyone to not use because you break everything so damned easily
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
claudiuinberlin has joined #crystal-lang
<Papierkorb_>
Please don't use malloc.
<FromGitter>
<monouser7dig> yeah
<FromGitter>
<monouser7dig> did not want to/ not intend to use it in reality, but wanted to know the speed difference
<Groogy>
also without code that says nothing
<Groogy>
I am guessing dynamic array is just adding elements one by one?
<Groogy>
while normal array is Array.new(0, count)?
<FromGitter>
<monouser7dig> always just adding 1...10000 into the respective place
<Groogy>
but let's say you have a static array on the stack, with 10k doubles
<Groogy>
a weight value for each agent in a simulated strategy game,
<Groogy>
setting the static size to 10k wouldn't be that weird
<Groogy>
that's already almost 100kb :/
<RX14>
well we do have 8MB stacks
<RX14>
by default
<RX14>
well actually fibers are always 8MiB
<FromGitter>
<monouser7dig> yes I remember and 4kb for fibers because they reduce it in the beginning somehow I guess
<Papierkorb_>
Copying 100KiB sounds like a great way to disrupt performance. Just by passing it around. Neat
<FromGitter>
<monouser7dig> 4mb*
<RX14>
no, 8mb max size for fibers
<RX14>
4kb starting size
<RX14>
default stack size is controlled by the OS
<Groogy>
Papierkorb well luckily we don't have alloca in Crystal
<Papierkorb_>
Thanks linux for allocation-on-demand
<Groogy>
same thing would have used alloca in our ai code
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Groogy>
and we've gotten so many bad to track crashes thanks to it
claudiuinberlin has joined #crystal-lang
<RX14>
well staticarray *is* alloca
<Groogy>
no alloca let's you at runtime decide what to allocate
<RX14>
oh yeah nvm,
<Groogy>
static array needs the number at compile time
<Groogy>
and that is why I've been campaigning so hard against it
<Groogy>
since people started using it at the company as the silver bullet
<Papierkorb_>
LLVM's intrinsic is called alloca, which may take a run-time size
<FromGitter>
<monouser7dig> if you do pointerof and get a decent array you can have some sort of alloca
<Papierkorb_>
1) No 2) Please don't
claudiuinberlin has quit [Client Quit]
<Groogy>
and when you pointed out "we've had so many problems with this" people forget they broke everything yesterday and you just have to scream at them "I JUST FIXED THE MESS YOU MADE"
<FromGitter>
<monouser7dig> heard people do that in java to trick garbage collection
<Groogy>
the second you put in "trick" that's where something is wrong
<Groogy>
if the GC is a problem for you, then you just have to learn how to not trigger it
<Groogy>
when it is critical
<Papierkorb_>
Writing programs isn't speedrunning. They have tricks. We don't.
claudiuinberlin has joined #crystal-lang
<Groogy>
Heap allocation -> Slow -> too many small allocations will most likely tirgger GC -> Find more optimal ways to do these things
<RX14>
Groogy, well in java they dont really have an option lol
<Groogy>
have only played around in Java so can't say about more high end problems you might end up there
<Papierkorb_>
I always heard "Tune the GC"
<Groogy>
I just know I hated every second of it because of its design. I don't know why theres just something soul sucking about it
<FromGitter>
<monouser7dig> in crystal you can really disable and enable and trigger gc right?
<Papierkorb_>
Groogy: Java is just awful.
<Groogy>
Yeah but if you need to, don't
<FromGitter>
<monouser7dig> 😄
<Groogy>
I would like a nice callback to be able to track when the GC is triggered and what it collected
<RX14>
i don't mind java
snsei has joined #crystal-lang
<Groogy>
so Ican make a tool to debug when I am missusing my objects
<RX14>
well java 8
<RX14>
its usable
<RX14>
its got good tooling
<FromGitter>
<sdogruyol> lol
<RX14>
but i wouldn't enjoy it
<FromGitter>
<sdogruyol> "usable"
<Groogy>
only thing I did in Java was metaprogramming by cracking how the JVM worked
<Groogy>
but I did that because it was fun
<FromGitter>
<sdogruyol> it's like the ten bazillion pounds of 25-year heavy optimizations
<FromGitter>
<sdogruyol> calling it just "usable" is a bit understatement :D
<Groogy>
I saw JRuby and wondered how they got things to work, talked bunch with people working on it and then expirmented to see how it worked
<RX14>
well let me qualify that
<Papierkorb_>
sdogruyol, the JVM. Java as language is horrible.
<RX14>
java is usable until you start using other people's libraries
<Groogy>
oh yeah the JVM is actually quite fun to play with
<FromGitter>
<sdogruyol> when someone says Java I always think of JVM
<RX14>
well the old ones
<FromGitter>
<sdogruyol> and for the last 5 years, Java is more innovative than Ruby
<RX14>
the commons helpers are OK since they're just simple libraries
<FromGitter>
<sdogruyol> look at Java 8 and Java 9
<RX14>
all the frameworks and stuff are horribly overengineered
<Papierkorb_>
Just after C++ lul
<FromGitter>
<sdogruyol> @RX14 yeah
<Groogy>
also does this sound super stupid or would that be fine to add or even possible? Debugging hooks to the debugger?
<FromGitter>
<sdogruyol> I strongly agree with that
<Groogy>
so you could memory profile usage etc.
<FromGitter>
<sdogruyol> They tend to have a high preference of overengineering
<RX14>
if i had a company i'd probably use a JVM lang
<FromGitter>
<sdogruyol> I never understand why though
<RX14>
probably kotlin tbh
<Papierkorb_>
Groogy: Check out if boehmgc has a hook for that. Maybe it's just not exposed
<FromGitter>
<sdogruyol> same here
<Groogy>
yeah I'll do that in the weekend, if I find it I'll make a pull request
<Papierkorb_>
Groogy: Though there's `GC.stats` if you just want to know how your program is doing on a 100km above view
<Groogy>
yeah true
rohitpaulk has quit [Ping timeout: 240 seconds]
<RX14>
you learn a lot of JVM internals from MC modding since everything is a hack
snsei has quit [Ping timeout: 264 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter>
<sdogruyol> I'd really like to have built-in toolchain for profiling crystal programs
<FromGitter>
<sdogruyol> something like go pprof
<FromGitter>
<sdogruyol> makes it dead simple..
<RX14>
i think C tools are fine
<Groogy>
gprof can profile crystal I think?
<RX14>
well
<FromGitter>
<sdogruyol> @RX14 it's not so user-friendly..
<RX14>
perf and callgrind work just fine in crystal
<RX14>
Groogy, you could also create something generic by hooking into GC_* calls and write an external profiler
<RX14>
which works on any binary
<FromGitter>
<monouser7dig> ( maybe with proper indentation )
<RX14>
using something similar to how ltrace does it
<Groogy>
hmmm
rohitpaulk has quit [Ping timeout: 260 seconds]
<RX14>
i think the hard pert is interpreting it Groogy
<Groogy>
Well what I want is the types
<RX14>
you can write multiple frontends for collecting the data
<RX14>
ok yeah thats a god point
<Groogy>
the data is useless without like type of object allocated and deallocated and at what time
<RX14>
yeah i forgot about that
<Groogy>
also need to think about it, could be a nice thing to add to the standard library but needs to be done right and not leave it open to mess with the GC for unsafe operations
<Groogy>
like fucking up the finalize methods of every single class or something
<RX14>
lol
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
sz0 has quit [Quit: Connection closed for inactivity]
<Groogy>
could be nice for users to be able to see "Huh I am doing __tons__ of tmp array allocations it looks like...."
<FromGitter>
<sdogruyol> ^
<Groogy>
hmmmm so.... seems to be bunch of things that uses malloc alone without providing a type :/ like strings it seem
<Groogy>
huh I can't find where objects allocate memory ???
<Groogy>
guessing new isn't defined anywhere? :/
Papierkorb_ has quit [Quit: Konversation terminated!]
<FromGitter>
<monouser7dig> and above kotlin, seems like a weird thing 😄
<FromGitter>
<fridgerator> isn't that based around web searches?
claudiuinberlin has joined #crystal-lang
<FromGitter>
<monouser7dig> Seems part of it
<FromGitter>
<monouser7dig> it's like every student googles java and people who do real cpp don't ask stack overflow
<FromGitter>
<fridgerator> lol
claudiuinberlin has quit [Client Quit]
claudiuinberlin has joined #crystal-lang
claudiuinberlin has quit [Client Quit]
claudiuinberlin has joined #crystal-lang
snsei has joined #crystal-lang
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
claudiuinberlin has joined #crystal-lang
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
claudiuinberlin has joined #crystal-lang
claudiuinberlin has quit [Client Quit]
claudiuinberlin has joined #crystal-lang
claudiuinberlin has quit [Client Quit]
claudiuinberlin has joined #crystal-lang
<RX14>
please ignore the tiobe stuff
<RX14>
it's pointless to look at because it's simply wrong by inspection
<RX14>
Groogy, there's a `def self.allocate` for each object
<RX14>
which calls malloc
<RX14>
basically, for each def initialize, there is defined a def self.new with the body `instance = self.allocate; add_finalizer(instance); instance.initialize(*args)`
<RX14>
Groogy, you can inspect the type ID from the object header with just a pointer
<RX14>
which is also another possibly easyer way to do iot
snsei has quit [Remote host closed the connection]
<FromGitter>
<monouser7dig> just made a request/ issue on the crystal-tools repo or how it is called where they maintain the tooling, atom has nice inspection tooling which does not seem to be available in sublime
<FromGitter>
<monouser7dig> Papierkorb, if you choose sublime over atom you choose some speed over some tooling, just depends what you miss/ if you miss any of that
<Papierkorb>
I need syntax highlighting. The `initialize` snippet is helpful. Everything else: Couldn't care less.
<FromGitter>
<monouser7dig> sublime will in this case probably be good, you can have snippets
<FromGitter>
<monouser7dig> init cause one just can't possible type it quickly? 😄
<Papierkorb>
it's just so darn convenient for some reason.
<Papierkorb>
Any other snippet is more annoying. Can't count how often it extended my `end` to `each_with_index`.
<FromGitter>
<monouser7dig> one thing in sublime that got me several times, if you move a file while having it opened, sublime will recreate the file at the old place when you save, I think this is really bad, did not find a setting, but once you know...ok
<FromGitter>
<monouser7dig> I've some autocompletion package which just looks at all words in all open documents and chooses completion based on them, it works ok, someday a context aware thing would be cool but...
<Papierkorb>
that's what I also have in atom. works well enough most of the time to be honest.
<FromGitter>
<georgeu2000> > if you move a file while having it opened, sublime will recreate the file at the old place when you save ⏎ Yep, this happens to me. I always close before moving.
<Papierkorb>
faustinoaq, What exactly do I have to do in VS Code for Peek definition to work?
<Papierkorb>
It always tells me that it can't find the def
<FromGitter>
<monouser7dig> I think this linter works like, you invoke the crystal compiler and give the linter a regex to extract line number and error message and the linter then displays that inline
ShalokShalom_ is now known as ShalokShalom
claudiuinberlin has joined #crystal-lang
DTZUZO has quit [Ping timeout: 248 seconds]
<FromGitter>
<georgeu2000> @monouser7dig - Linter works great.
<FromGitter>
<monouser7dig> if I repeat to tell that I had a very dumb issue with a crystal debugging message ⏎ ⏎ `a : Array(Int32) = []; gives the error "expect [] of ElementType"` ⏎ thus I wrote `a : Array(Int32) = [] of ElementType` ⏎ (kind of Like in java: Set<T> l = new HashSet<>(); cause I thought ElementType was some interface or kind of it) ... [https://gitter.im/crystal-lang/crystal?at=59d7c9d5f7299e8f53b7c303]
<Papierkorb>
I .. don't see the issue
<FromGitter>
<monouser7dig> see the debug message led me to write incorrect code still
<Papierkorb>
The compilers job is to compile. Yours to think.
<FromGitter>
<monouser7dig> either I was just surprisingly stupid or someone else agrees this could be made more expressive
<FromGitter>
<monouser7dig> no the compilers job is also to give sensible error messages and help me arrive at the correct conclusion
<FromGitter>
<monouser7dig> to you insiders ElementType is obvious of course
<oprypin>
monouser7dig, yeah to people who have read the documentation it's pretty obvious
<oprypin>
do not expect hints about syntax features that you dodn't bother reading about
<oprypin>
compilers usually just say invalid syntax anyway
<oprypin>
so this is already better than average
<FromGitter>
<monouser7dig> nothing about ElementType, just that = [] is wrong, see, I know now it now and it is not hard to memorize just think {{here_goes}} is more obviously showing that here_goes is a Placeholder
<oprypin>
nope it's actually worse
<Papierkorb>
{{here_goes}}? So `[] of {{String}}`
<crystal-gh>
[crystal] Fryguy opened pull request #5085: Short circuit Hash#find_entry for empty Hashes (master...faster_empty_hash_lookup) https://git.io/vdE6n
<FromGitter>
<monouser7dig> and actually a : Array(Int32) = [] giving an error is weird in itself cause why can not crystal know that it is an array of int? at least I told it
<FromGitter>
<monouser7dig> okay accept you opinion 😄
<oprypin>
you told it the type of the variable, but first it needs to create a value
<FromGitter>
<monouser7dig> the value is an empty array of int32
<oprypin>
where does it say that?
<FromGitter>
<monouser7dig> int : Array(int32) = [] , the first part tells what it is, the second tells it is empty
<oprypin>
so you're creating an
<oprypin>
so you're creating an "empty"
<FromGitter>
<monouser7dig> might be a parsing problem but coming from pure logic, there is no ambiguity
<FromGitter>
<monouser7dig> an empty array
<Papierkorb>
`getter foos = [] of Foo` should be the only way to do that. Why have two syntaxes for the same thing
<FromGitter>
<monouser7dig> the `int :` was nonsense, sorry, should have been some name
<FromGitter>
<monouser7dig> yes two syntaxes is bad as well agreed
<oprypin>
monouser7dig, you can argue that the programming language should be changed to make your example work ( see also https://github.com/crystal-lang/crystal/issues/2995 ) but you cannot argue that it makes sense under the current state of the programming language
<FromGitter>
<monouser7dig> although I do like the notation arr : Array(Int32) because this is the same Type that I'd put into a function call
<oprypin>
the state is that every literal immediately must have a type
<FromGitter>
<monouser7dig> of Int32 is different from what I'd put in a function call
<FromGitter>
<monouser7dig> oprypin yeah now I see your point, took me some time but actually makes sense currently
<oprypin>
when you write an array literal, the compiler must have a way of determining what type it stores. and only then the variable it's being assigned to is being considered
<FromGitter>
<monouser7dig> read your proposal as well and especially at the beginning of using crystal strongly agreed..now I'm not that sure but tend to still agree
<oprypin>
yeah the proposal is really easy to agree to but really difficult to implement
<FromGitter>
<monouser7dig> 😄
<oprypin>
aftettr that's done we can argue for untyped array literals, then your example would work
<FromGitter>
<monouser7dig> I'll hopefully will still be around 👍
<FromGitter>
<monouser7dig> gee it's too late 😄
<oprypin>
another example that might help with understanding:
<oprypin>
`a : Array(Int32 | String) = [1, 2, 3] of (Int32 | String)` is valid
<oprypin>
`a = [1, 2, 3] of (Int32 | String)` is valid
<FromGitter>
<monouser7dig> one thing I could argue is that the empty array should be handled as an array with a number, it should both default to Int32 and thus arr : Array(Int32) = [] should work like your first example
DTZUZO has joined #crystal-lang
<oprypin>
no comment
<FromGitter>
<monouser7dig> nevermind
<FromGitter>
<HCLarsen> @sdogruyol we're also above Elixer, and 3 higher than last month.
<FromGitter>
<HCLarsen> Hey guys, I'm trying to play around with the "play.crystal-lang.org" site, and it gives me an error when I do require "http/client". Is that a limitation in the online interface that you can't require libraries, or is something wrong with that library?
<oprypin>
HCLarsen, show proof
<FromGitter>
<bew> iirc there are errors when requiring http stuff in crystal play or the online testers
<oprypin>
pretty sure it's not about requiring
<oprypin>
but about intentionally being prevented from getting a free botnet node
<FromGitter>
<HCLarsen> Ok, so it's just the online thing. Got it.
<oprypin>
i'm not really sure if you got it
<oprypin>
because requiring generally works just fine
rohitpaulk has quit [Remote host closed the connection]
<FromGitter>
<matrixbot> `@Renich:matrix.org` ah, sorry for the bad indentation
<oprypin>
Renich, y u do dis
<FromGitter>
<matrixbot> `@Renich:matrix.org` Well, i have an app that's gonna run in a loop. So, I want to define a Start class that runs all it has to run (logging, config, etc)
<oprypin>
please remove matrixbot
<oprypin>
you can connect though matrix to irc if you really want
<FromGitter>
<matrixbot> `@Renich:matrix.org` OK
* FromGitter
* matrixbot is looking how to remove it*
Renich has joined #crystal-lang
<oprypin>
I strongly believe that objects should represent tangible objects
<oprypin>
"Start" is not one of that
<FromGitter>
<monouser7dig> def self.run! should do (just working, not saying good or bad)
<Renich>
oprypin: how would you go about initializing the app, then?
<oprypin>
assign a bunch of variables, i dunno
<oprypin>
should it be an App class then?
<oprypin>
App.new.run
<Papierkorb>
I usually call that facade class `Tool`, which then does the front-end stuff
<oprypin>
tool?
<Papierkorb>
The tool setting things up for the front-end to do something useful
greenbigfrog has quit [Remote host closed the connection]
<FromGitter>
<matrixbot> `@Renich:matrix.org` I dunno how to remove the matrix bot, btw, oprypin. I will have to remove it from favorites
<oprypin>
well to start with you probably shouldn't be connecting to gitter using matrix
<jnerula>
I'm trying to create a class-based view system
<jnerula>
The idea being you send 'GET / HTTP 1.1' or whatever, and it calls a 'get' method on a View class
<Papierkorb>
`"get" => ->self.get,` etc.
<jnerula>
I've just been messing around with Crystal this morning and it seemed kinda fun
<Papierkorb>
jnerula: But in your specific case, just use a `case` statement, not a temporary hash
<oprypin>
yeah exactly, why store and return methods when you can just call them
<Papierkorb>
and just call out to the method from there
<RickHull>
yes, my first thought was to reach for `case` -- but there is something nice about declaring your map as data rather than executable code
<Papierkorb>
building a map sounds like code to me
<RickHull>
you could reference that map from outside
<Papierkorb>
if you want to make it harder on yourself, yes
<jnerula>
A case here would work great, but I'm trying to put myself through the challenge of more functional style stuff
<Papierkorb>
What I already wrote.
<jnerula>
btw it's still trying to invoke the methods if I use eg. `"get" => ->self.get,`
<jnerula>
wait, nevermind
<oprypin>
sigh
snsei has joined #crystal-lang
<FromGitter>
<HCLarsen> Hey guys, I can't seem to figure out the to_json method for strings. It's calling for a JSON::Builder argument, but I'm not sure what to put in there.
<Papierkorb>
please post code.
<FromGitter>
<HCLarsen> I don't have code to post because I don't know what to write yet.
greenbigfrog has joined #crystal-lang
<oprypin>
HCLarsen, ok then what are you trying to do?
<oprypin>
because calling to_json on a string is not that useful
<RickHull>
yeah, typically you call it on a data structure, and it returns a string
<FromGitter>
<HCLarsen> The HTTP::Client returns a string, which contains JSON data. I want to parse that into something more meaningful. I figured to_json would be the way to go.
<RickHull>
you would want to first extract the JSON string, and then something like JSON.parse(json_str)
<FromGitter>
<fridgerator> ah, you want `JSON.parse`
<FromGitter>
<HCLarsen> I don't see JSON in the api documentation.
<FromGitter>
<HCLarsen> Interesting. The documentation definitely led me to believe that I needed to use as_h.
<FromGitter>
<HCLarsen> Thank you for your help.
<FromGitter>
<HCLarsen> What's the purpose of the as_h method then?
<FromGitter>
<elorest> `as_h` will only work if the underlying structure is a hash.
<oprypin>
HCLarsen, at every point in json, everything can be either a string or an array or a hash or etc. the compiler is telling you that. it can't make assumptions
<FromGitter>
<HCLarsen> But, it was a hash. That's why I was using it.
<jnerula>
the docs seem to imply that only JSON::Any is further traversable, while JSON::Type isn't?
<oprypin>
HCLarsen, ok, it's a Hash, but each of its values can be either a string or an array or a hash or etc. the compiler is telling you that. it can't make assumptions
<oprypin>
that's why there is a wrapper type JSON::Any that allows you to make these assumptions, up until the very last moment
<FromGitter>
<HCLarsen> I wasn't telling it to make assumptions, I was using the as_h method to tell it that it's a hash.
<jnerula>
A hash from what to what though? You're only defining the top level type for that object
<oprypin>
HCLarsen, OK so you get a `Hash(String, String | Int64 | Float64 | Hash | Array)`
<FromGitter>
<HCLarsen> Take this sentence for example: To convert them to String, Int32, etc., use the as_ methods, such as #as_s, #as_i, which perform a type check against the raw underlying value.
<oprypin>
geez cant even finish a sentence here :p
<FromGitter>
<HCLarsen> I wanted to convert the JSON::Any to Hash so that I could write code that treated it like a hash.
<FromGitter>
<HCLarsen> jnerula, you lost me on that one.
<oprypin>
`value : Hash(String, String | Int64 | Float64 | Hash | Array)`; then `value["main"] : String | Int64 | Float64 | Hash | Array`, then `value["main"]["temp"]` - what if value["main"] ended up being an Int32 you end up calling `["temp"]` on that?
<jnerula>
This ^^^
LOLBOW has joined #crystal-lang
<FromGitter>
<HCLarsen> That's why I tried calling "as_h" on it before I called ["temp"] on it, and got the same error.
<oprypin>
likely not the same. Hash does not have a method `as_h`
<FromGitter>
<HCLarsen> But it said that I was trying to call as_h on an Array.
<FromGitter>
<asterite> Just remove `as_h` and do `puts value["main"]["temp"].as_f`
<oprypin>
that's the intended use, yes, but i was building up to that
nijotz has joined #crystal-lang
<FromGitter>
<asterite> With `as_h` you are going from `JSON::Any`, which lets you traverse the data structure infinitely, to a `Hash` that lets you just access one level
<FromGitter>
<asterite> So jnerula's answer, basically
<oprypin>
welp i cant finish a sentence so whatever
<FromGitter>
<asterite> why?
<FromGitter>
<HCLarsen> Wait, you mean that as_h prevents me from going any deeper into the nested structure?
<FromGitter>
<asterite> Yes, exactly
<FromGitter>
<ezrast> @HCLarsen You're misinterpreting that error message - you were calling `[]` on a value that could have been a `String`, `Array(JSON::Type)`, `Hash(String, JSON::Type)`, etc. In order to call a method on a union type, every type in the union has to implement that method. You were getting an error because Array does not implement `[]` with a String argument (neither does String, Int, etc; the compiler just
<FromGitter>
... happened to check Array first)
<FromGitter>
<ezrast> The actual value was a Hash, but it's compile-time type is Union, not Hash
<FromGitter>
<asterite> `as_h` means: this json thing I have here, which can be any json type, I know it's a hash. From there, if you index it with a string it will be again any json type, but a `JSON::Type`, not a `JSON::Any` anymore
<FromGitter>
<asterite> In any case, this is waaaay too confusing
<FromGitter>
<asterite> I said many times that `JSON::Any` was a mistake and just having `JSON::Type` would be simpler
<FromGitter>
<HCLarsen> I'm gonna be honest, I don't think that structure is a good thing. I would expect an as_h method to convert the entire nested structure to a hash.
<FromGitter>
<asterite> That's what it does :-)
<oprypin>
but there's no conversion happening T_T
<FromGitter>
<asterite> but the elements of that hash can be any type in the JSON world
<FromGitter>
<HCLarsen> At the very least, the documentation should be clearer.
<oprypin>
oh that's for sure
<FromGitter>
<HCLarsen> I hope no one gets offended if I try to clear that up and do a pull request next week.
<FromGitter>
<asterite> Please don't, we just need to remove `JSON::Any` from the standard library
<FromGitter>
<asterite> With "please don't" I mean that you will waste time because those docs will later disappear
<FromGitter>
<HCLarsen> Then how would it work without JSON::Any? What would the JSON.parse method return?
<FromGitter>
<asterite> A union of all the JSON types
<FromGitter>
<asterite> Maybe you'd like to look at JSON.mapping?
<oprypin>
HCLarsen, I'm of the opinion that to explain something, first you need to understand it perfectly, and then also have the ability to put yourself in the shoes of a beginner
<oprypin>
which is quite a requirement
<FromGitter>
<HCLarsen> I was a technical salesperson for 12 years. Translating expert jargon into beginner jargon was my job.
<oprypin>
good, so then you need just the first part, i guess
<FromGitter>
<HCLarsen> @asterite , what's a union?
<oprypin>
asterite, I don't see how one would get far without JSON::Any. i'm pretty sure it would be annoying as hell, unless you have some ingenious idea
<FromGitter>
<HCLarsen> Thank you. That'll give me some reading tonight.
<FromGitter>
<HCLarsen> I assume with union types it's easy to query it to determine which type it is?
<oprypin>
yeah
<oprypin>
the more involved part is proving to the compiler that you've checked properly
<FromGitter>
<HCLarsen> Good then. In the case of JSON.parse, it would be very useful to query it to see which type is it, and then deal with the data appropriately.
<FromGitter>
<HCLarsen> Yeah, that's like using optionals in Swift. One hell of a learning curve on those.
<oprypin>
you can definitely do that manually at every junction, if you get the union type directly, with JSON.parse_raw
<oprypin>
JSON.parse wraps the result in an object that helps traversal
<FromGitter>
<asterite> oprypin: JSON.parse(data).as(Hash)["foo"].as(Array)[0].as(Float). A bit longer but super explicit
<oprypin>
such nice material for smirks in reddit comments
<FromGitter>
<HCLarsen> Readable code is key.
gokmen has quit [Quit: bye.]
<Papierkorb>
oprypin: /r/programming attracts mostly unspecialized people living in a funny bubble
<Papierkorb>
Who cares what they think
<FromGitter>
<HCLarsen> I'm assuming you could also do a case switch on that? Type checking could be useful.
<oprypin>
that was just one way of saying "general publicity"
snsei has joined #crystal-lang
gokmen has joined #crystal-lang
<Papierkorb>
HCLarsen, if you want to traverse the structure, yes you can use a `case` with a when for each type you care about
<Papierkorb>
oprypin: Looking at the current world of *programming*, this "general publicity" person didn't seem to care much about writing stable code in the past years.
<oprypin>
look i'm not gonna deny that programming is a special kind of adrenaline chase for me
<oprypin>
if i see unnecessary verbosity, i don't like that
<Papierkorb>
You can easily write a dig-esque method?
<oprypin>
you got me there
snsei has quit [Ping timeout: 255 seconds]
<FromGitter>
<HCLarsen> I meant that question for @asterite 's theoretical example.
<oprypin>
`case (root = JSON.parse data); when Hash; root["foo"]` etc
<oprypin>
I'm just thinking about generalizing the idea of turning compile time checks into runtime checks when you really want, like in this case
<FromGitter>
<georgeu2000> I have a web request params that comes from the body of an HTTP request: ⏎ `@params = JSON.parse(context.request.body.to_s)` ⏎ How can I add another key/value? The following fails: ⏎ `@params[:foo] = "bar"` [https://gitter.im/crystal-lang/crystal?at=59d7f56ce44c43700a01aa18]
<FromGitter>
<georgeu2000> How can I handle a Hash with arbitrary depth?
<FromGitter>
<georgeu2000> Is there any examples or documentation?
<oprypin>
a special state you can enter where instead of generating a "no such method" compile error you get a subset of types that support it or a runtime error otherwise
<oprypin>
georgeu2000, there's no direct documentation on "handling a Hash with arbitrary depth"
<FromGitter>
<monouser7dig> aaah read that but could not infer the context 👍
<FromGitter>
<opensas> @Papierkorb @HCLarsen @asterite once I had to parse a json with unknown structure, I started with json.parse and JSON:: Any, but eventually ended up just using json.parse_raw, JSON::Type and a case statement, my code was even more concise and clearer, inside the case I didn't even had to cast the value https://github.com/opensas/json-mappings-generator/blob/master/src/json-mappings-generator.cr#L70 , in my
<FromGitter>
... case JSON::Any wasn't very useful
<oprypin>
good for you, i guess
<Papierkorb>
Yup that's how you do it. You shouldn't use a NamedTuple though. At least use a struct instead, the `record` macro comes in handy for this.
<oprypin>
you're just mapping a general use case to a general use case, of course a generalistic approach will work better than something made for getting *specific* fields
<FromGitter>
<monouser7dig> > **<Papierkorb>** Yup that's how you do it. You shouldn't use a NamedTuple though. At least use a struct instead, the `record` macro comes in handy for this. ⏎ ⏎ at least named tuples are faster than an array afaik? why struct then (had this today already just other way round)
<FromGitter>
<opensas> Didn't know about the ´record´ macro, I'll give it a try, thanks! I should be more performant than a NamedTuple, right?
DTZUZO has quit [Ping timeout: 240 seconds]
<Papierkorb>
monouser7dig, that's comparing pears with apples
<Papierkorb>
opensas, same performance-wise. Just a better choice as data structure. Tuples are not storage data types, they're transfer data types.
<FromGitter>
<opensas> good to know, sometimes it's a bit difficult to know which structure is more appropriate for each use case, a cheat sheet would be useful, any docs that might be worth reading about it???
<FromGitter>
<monouser7dig> `Tuples are not storage data types` so no real reason other than aesthetic?
<Papierkorb>
> they're transfer data types.
<Papierkorb>
Logistics aren't aesthetics. Without nothing much would happen in our world.
<FromGitter>
<monouser7dig> yeah but whats the catch with that, any implications?
<Papierkorb>
"catch with that"?
<FromGitter>
<monouser7dig> the downside
<Papierkorb>
To what?
<Papierkorb>
To doing what?*
<FromGitter>
<monouser7dig> the downside of using tuples as storage (instead of struct)
<FromGitter>
<opensas> I think @monouser7dig is asking why is it preferable in this case to use a struct instead of a named tuple
<FromGitter>
<opensas> me too btw
<FromGitter>
<monouser7dig> sure
<oprypin>
opensas, in *this* case it's really arguable
<oprypin>
i like your usage of namedtuple
<FromGitter>
<opensas> when you say transfer data types you mean they are mainly intended to pass parameters between methods?
<Papierkorb>
It's totally inconvenient to use. You don't have any control over their behaviour, and can't augment the types with methods. To the programmer, a tuple is a bunch of bytes, a struct brings structure into the chaos. And, writing `foo[:bar]` just sucks compared to `foo.bar`
<oprypin>
opensas, that'
<Papierkorb>
opensas, yes
<oprypin>
opensas, that's the typical example, but could apply to passing things around in general
<oprypin>
which you actually seem to be doing, not really storing in the long term, though i get that the duration is not the point
<Papierkorb>
opensas, `def foo(*args)` <- args is a Tuple. You can pass these on (Splatted or not). They're like temporary structures in this regard.
<Papierkorb>
Whenever you're storing a tuple, you should take a moment and rethink your approach, if a real type isn't much better suited at this point. A `class` if you can, but even a struct (`record` does exist) is a improvement. It'll make your code much easier to maintain too.
<Papierkorb>
Doesn't mean there may not be a case where storing a tuple is actually a good idea. I haven't come across one yet, but others do other things ;)
<Papierkorb>
Maintainability? Yeah, totally YAGNI
<Papierkorb>
Who cares
<Papierkorb>
You're right, it's a job security thing
<Papierkorb>
If no one dares to touch the code but you, your job is safe
<FromGitter>
<monouser7dig> it's not like you have to expand every piece of a program 😄 haha
<oprypin>
when you care about getting a few pieces of data into one thing, passing it somewhere, then breaking it apart again, that's the use case for tuples
<FromGitter>
<monouser7dig> thanks for the advice again though, looking foreword to a prosperous future
<oprypin>
and if you need to create them as often as in opensas's case it seems like a nice benefit in addition to seeming like the proper use case to me
<FromGitter>
<opensas> I'm using the tuples just to temporary aggregate the json struct to process it after parsing it all, I'll give it a try with a struct to see how the code ends up, thanks for the explanations, I think the docs could benefit from a section comparing the different structures and sue cases available in Crystal, like the one explaining differences between classes and structs
<oprypin>
well even old established programming languages don't have that luxury
<oprypin>
discussions of tuples happen all the time in #python , and the advice is scattered throughout blogs. "the community" in general has pretty good knowledge about it thought
<FromGitter>
<monouser7dig> it literally has --emit as an option but does not parse it?
<FromGitter>
<oprypin> someone had a really helpful replacement of -- to —
<oprypin>
kind of a big difference between --emit and -—emit
<FromGitter>
<monouser7dig> funky, pasted that from a message where I pasted it from a website, look just the same in my term
<oprypin>
get a better terminal font then
<FromGitter>
<monouser7dig> its completely insane output anyway probably for anything more than x =1
snsei has joined #crystal-lang
<FromGitter>
<monouser7dig> so --prelude=empty is required to make it parsable by a human but then I can not use a hash? cause it can not find methods cause it propably leaves a whole lot out
<Papierkorb>
Ctrl+F is your friend.
<FromGitter>
<monouser7dig> I'll just pretend hash#empty compiles down to exactly the same as hash#size == 0
<FromGitter>
<monouser7dig> otherwise faith in llvm would be disrupted anyway
<Papierkorb>
The llvm IR isn't optimized
<Papierkorb>
Except for trivial platform agnostic things, but that doesn't include method inlining
<Papierkorb>
Hence, objdump to the rescue
<FromGitter>
<monouser7dig> could be optimized though couldn't it? I mean optimization happens with the IR code and not the binary?
<Papierkorb>
The IR is backend agnostic
<Papierkorb>
Also, no why should you optimize it? The IR is for human consumption
<FromGitter>
<monouser7dig> cause I'd want to see the optimization, otherwise I'd look at the source code for human consumption 😄
snsei has quit [Remote host closed the connection]
<FromGitter>
<monouser7dig> so you can actually optimize IR and get back to IR just maybe not with these crystal command which is unfortunate to say the least
<FromGitter>
<georgeu2000> I was able to parse, but not sure how to update the params: ⏎ ⏎ ```@params = JSON.parse_raw(context.request.body.to_s) ⏎ @params["foo"] = "bar"``` ⏎ ⏎ I get `no overload matches 'Array(JSON::Type)#[]=' with types String, String` [https://gitter.im/crystal-lang/crystal?at=59d8139801110b723186e681]
snsei has joined #crystal-lang
<FromGitter>
<georgeu2000> Not sure why @params is an Array, or how to update it.
<FromGitter>
<georgeu2000> Also looking for documentation on what is going on here...
snsei has quit [Remote host closed the connection]
<FromGitter>
<faustinoaq> > @faustinoaq, What exactly do I have to do in VS Code for Peek definition to work? ⏎ ⏎ Papierkorb, Enable implementations on `settings.json` ⏎ ⏎ ```{ ⏎ "crystal-lang.implementations": true, ⏎ }``` [https://gitter.im/crystal-lang/crystal?at=59d818c8f7299e8f53b94b62]