ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.34.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<hightower2> I don't need to #join Fibers or anything, right?
<FromGitter> <Blacksmoke16> i dont think so? :shrug:
<FromGitter> <straight-shoota> hightower, you can spawn fibers as fire and forget. But it's still good practice to keep taps on spawned fibers.
<FromGitter> <straight-shoota> variable access is not thread safe. If you want to share a variable between fibers, you need to guard it. You can also take a look at Atomic(T). Or better: Use only channels to communicate between fibers.
<hightower2> great, thanks
<FromGitter> <stronny> mutex is also fine
ur5us has joined #crystal-lang
<hightower2> yes, sure
<hightower2> Hey what's the most convenient way to display Time::Span#total_seconds to 3 decimals?
<hightower2> I'm looking for something that's not as crude as using printf
<FromGitter> <stronny> sprintf?
<FromGitter> <Blacksmoke16> .round?
<FromGitter> <stronny> actually what do you mean 3 decimals?
<hightower2> 5.123 instead of 5.2973641546
<FromGitter> <Blacksmoke16> prob like `1.234`
<FromGitter> <Blacksmoke16> `val.round 3`
<FromGitter> <stronny> there's `Number#humanize`
<hightower2> Hm round 3 looks good, except that it doesn't force 3 decimals, so 5.250 gets displayed as 5.25
<FromGitter> <Blacksmoke16> does it matter?
<hightower2> yes I'd have to have it formatted in columnar output
<hightower2> well, will resort to sprintf
<FromGitter> <stronny> why do you avoid sprintf?
<hightower2> I think "%f.3" % span.total_seconds will work... or whatever the exact syntax is
<FromGitter> <stronny> type goes at the end
<FromGitter> <Blacksmoke16> `val.humanize significant: false`
<FromGitter> <Blacksmoke16> makes it a string tho
<FromGitter> <Blacksmoke16> can write directly to an io as well
<hightower2> yes, I do that
<FromGitter> <Blacksmoke16> `val.humanize io, significant: false`
<FromGitter> <Blacksmoke16> hmm, should `Exception` include file/line?
<FromGitter> <stronny> unless it's a release build
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e966586fea5216d697e537d]
<FromGitter> <Blacksmoke16> be pretty easy
<FromGitter> <stronny> isn't it already there in the trace?
<FromGitter> <Blacksmoke16> probably, not easily exposed as it could be
<FromGitter> <stronny> also, won't *FILE* expand to the definition file, not usage file?
<FromGitter> <Blacksmoke16> mm it seems that way yea
<FromGitter> <Blacksmoke16> darn
<FromGitter> <stronny> what's wrong with current state of things?
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
<FromGitter> <Blacksmoke16> nothing really, just a thought i had
<FromGitter> <Blacksmoke16> adding some logging and thought it would be handy to point out an exception happened at file:line without printing whole trace
<FromGitter> <stronny> > The backtrace is an array of strings, each containing “0xAddress: Function at File Line Column”. ⏎ ⏎ `x.backtrace.first`?
<FromGitter> <Blacksmoke16> oh, that literally contains the file and line number doesnt it
<FromGitter> <stronny> it does indeed
<FromGitter> <Blacksmoke16> hm its not actually correct
<FromGitter> <Blacksmoke16> `at src/athena.cr:201:5 in 'user'`
<FromGitter> <Blacksmoke16> actual exception is raised on 198
<FromGitter> <stronny> ` show_full_info = ENV["CRYSTAL_CALLSTACK_FULL_INFO"]? == "1"`
<FromGitter> <stronny> try with this on
<FromGitter> <Blacksmoke16> thats a bit more helpful but no, still 201
<FromGitter> <Blacksmoke16> `at src/athena.cr:201:5 in '*RoutingController#user<Int32>:User'`
<FromGitter> <stronny> looks like the backtrace starts one frame back heh
<FromGitter> <Blacksmoke16> rip
<FromGitter> <Blacksmoke16> minimal example works fine
<FromGitter> <stronny> okay, so easy <irony>fix</irony> would be to wrap raise
<FromGitter> <stronny> that way your backtrace would start at the call of the raise wrapper
<FromGitter> <Blacksmoke16> wrap raise in what?
<FromGitter> <Blacksmoke16> oh the method
<FromGitter> <Blacksmoke16> `throw` :trollface:
<FromGitter> <stronny> yeah that would be interesting lol
<FromGitter> <Blacksmoke16> how bad of an idea would it be to use `Log::Context` a bit outside of the logging context?
<FromGitter> <stronny> hm?
<FromGitter> <Blacksmoke16> its quite useful as a general container for data related to something
<FromGitter> <Blacksmoke16> i.e. `raise SomeError.new "Something went wrong", context: Log:Context.new user_id: user.id`
<FromGitter> <Blacksmoke16> which in turn would be logged via `Log.error(exception: ex) ...`
<FromGitter> <stronny> in the world of static analysis "a general container for data related to something" usually is counterproductive
<FromGitter> <Blacksmoke16> let me rephrase
<FromGitter> <Blacksmoke16> contextual data related to an exception
<FromGitter> <stronny> why don't you make a new exception type that takes its context directly?
<FromGitter> <Blacksmoke16> hm
chachasmooth has quit [Ping timeout: 265 seconds]
<FromGitter> <Blacksmoke16> i would deff do that to represent data explicitly related to the exception
<FromGitter> <stronny> instead of `SomeError` make it `UserError.new "description", user.id`
<FromGitter> <Blacksmoke16> to be clear, i would just use this for logging, i.e. use the context from the exception, and merge it into the other logger context
chachasmooth has joined #crystal-lang
<FromGitter> <stronny> example?
<FromGitter> <Blacksmoke16> way things are setup atm is i have a default error listener the gets invoked for each exception that bubbles up to the "top level"
<FromGitter> <Blacksmoke16> i.e. if you do `1 / 0` in a controller action it would log
<FromGitter> <stronny> okay
<FromGitter> <Blacksmoke16> `[2020-04-15T02:08:48.006400000Z] athena.routing.FATAL: Uncaught exception DivisionByZeroError: 'Division by 0' at /var/lib/snapd/snap/crystal/340/share/crystal/src/int.cr:138:7 in 'check_div_argument' {}`
<FromGitter> <Blacksmoke16> and in turn be returned to client as 500
<FromGitter> <Blacksmoke16> so within this listener, it would be possible to check if the exception is a like `ContextualException` and if so, add its context to the logger for that entry
<FromGitter> <Blacksmoke16> which seems useful
<FromGitter> <stronny> no, that's what you do in ruby
<FromGitter> <stronny> in crystal you define a type for every actual context and use inheritance to code it up
<FromGitter> <Blacksmoke16> right, to be clear thats what im doing as well, i have a concrete exception class for some common HTTP errors
<FromGitter> <stronny> so what's wrong?
<FromGitter> <Blacksmoke16> the question is how to best expose context related to that exception to the logger
<FromGitter> <Blacksmoke16> some `.context` method on the exception could prob do it as well, which each class would implement?
<FromGitter> <stronny> if all you need is a string then yeah, that would work
<FromGitter> <Blacksmoke16> ```def context ⏎ Log::Context.new user_id: @user_id``` [https://gitter.im/crystal-lang/crystal?at=5e967601e24b4d6c440c5112]
<FromGitter> <stronny> actually that context would be useful anyway, so maybe all you need is `inspect`
<FromGitter> <Blacksmoke16> actually yea, i think this concept i was thinking of isnt required
<FromGitter> <Blacksmoke16> the log entry would inherently have the exception obj
<FromGitter> <Blacksmoke16> which custom backends could get data off of
<FromGitter> <Blacksmoke16> and then in the formatter, could just do like ⏎ ⏎ ``` if ex = entry.exception ⏎ io << ' ' ⏎ ex.inspect io ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e9676c9fea5216d697e874d]
<FromGitter> <Blacksmoke16> yea i like that better, then its not dependent on some random `Log` type
<FromGitter> <stronny> it's nice that Crystal has arbitrary hashes, but in the long run you're better off using them sparingly
<FromGitter> <Blacksmoke16> for sure
<FromGitter> <Blacksmoke16> was thinking of the use case where you do have a custom exception type, but then want to include some arbitrary data related to it
<FromGitter> <Blacksmoke16> to be logged
<FromGitter> <stronny> don't do that =)
<FromGitter> <Blacksmoke16> but yea, i cant really think of a use case where that would be actually useful
<FromGitter> <Blacksmoke16> if anything use modules to mix into existing types
<FromGitter> <Blacksmoke16> like idk, to include a request URI related to it or whatever
<FromGitter> <stronny> usually there's not much to do with exception other than report it
<FromGitter> <Blacksmoke16> exactly, and any data you would want to log would be on the obj itself
<FromGitter> <stronny> so having this information available as a separate variable seems rather overengeneered to me
<FromGitter> <Blacksmoke16> or logged at some other point, like user/customer ids
<FromGitter> <Blacksmoke16> agreed
<FromGitter> <stronny> just dump it into the message and be done
<FromGitter> <Blacksmoke16> now how to best render this error message :P
<FromGitter> <Blacksmoke16> er include exception context in the entry to display*
<FromGitter> <stronny> in large red letters!
<FromGitter> <stronny> (by the way a bedtime story: we had td-agent crashing; turned out that some crypto soft like geth or somesuch not only dumped ANSI sequenses to syslog, it wrote invalid utf8 which caused ruby to choke and die lol)
<FromGitter> <Blacksmoke16> reminds me when i learned the hard way that mysql utf-8 isnt actually utf-8
<FromGitter> <stronny> oh, my ass queue elle
<FromGitter> <stronny> don't get me started on this dumpster fire
<FromGitter> <Blacksmoke16> someone put an emoji into the the title of their contract and it broke the app, since it got saved but then wasnt able to be retrieved or something iirc
<FromGitter> <Blacksmoke16> was for a side project for a game so nothing impt but still ha
<FromGitter> <stronny> you reach for a backup to discover you have many gigabytes of `?` because of course
<FromGitter> <stronny> E N C O D I N G S
<FromGitter> <Blacksmoke16> i ended up just deleting all the titles lol
<FromGitter> <stronny> no data no problem
<FromGitter> <Blacksmoke16> `UPDATE couriers SET title = ''` 😆
<FromGitter> <Blacksmoke16> 🙈
<FromGitter> <Blacksmoke16> about around the same time i learned about db normalization and stopped storing *EVERYTHING* with each courier
<FromGitter> <tenebrousedge> o________o
<FromGitter> <Blacksmoke16> wonder if i can find the screenshot of what it was before
<FromGitter> <stronny> well you better unlearn it now, because you see, rdbms doesn't scale!
<FromGitter> <stronny> today everyone is a big data scientist
<FromGitter> <Blacksmoke16> hey i found it
* FromGitter * tenebrousedge is scared
<FromGitter> <Blacksmoke16> :S
<FromGitter> <Blacksmoke16> such a bad data model
<FromGitter> <Blacksmoke16> lol and i made `title` BLOB
<FromGitter> <stronny> `startConstellationName` okay
<FromGitter> <stronny> a business with ambition
<FromGitter> <Blacksmoke16> was the refactored schema
DTZUZU has joined #crystal-lang
DTZUZU2 has quit [Ping timeout: 250 seconds]
* FromGitter * tenebrousedge claws at eyes
ur5us has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
_whitelogger has joined #crystal-lang
_ht has joined #crystal-lang
ur5us has quit [Ping timeout: 256 seconds]
<FromGitter> <Afront> @Blacksmoke16 Hey, how did you make that picture? 👀
<FromGitter> <Afront> Is it from an ORM in Crystal?
ur5us has joined #crystal-lang
<jhass> @straight-shoota mmh, why did you go for javascript_config_file over versions_index=foo.json?
postmodern has quit [Quit: Leaving]
<FromGitter> <neutrinog> does anyone know how to create a hex number out of 3 other numbers? e.g. I have R, G, B int values that need to be converted to `0x<RRGGBB>`
<jhass> color = r << 16 + (g << 8) + b
<FromGitter> <neutrinog> in the end I want the base 10 form of that hex value... kinda weird.
<jhass> sorry need parens around the r << 16, + binds stronger than <<
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
return0e_ has joined #crystal-lang
<FromGitter> <neutrinog> thanks
return0e has quit [Ping timeout: 264 seconds]
Stephie has quit [Ping timeout: 258 seconds]
Stephanie has joined #crystal-lang
Stephanie has quit [Client Quit]
Stephie has joined #crystal-lang
<jhass> not too weird, android for example encodes color values exactly like that :) (well with an additional alpha value in front)
ur5us has quit [Ping timeout: 252 seconds]
ur5us has joined #crystal-lang
HumanGeek has joined #crystal-lang
Human_G33k has quit [Ping timeout: 240 seconds]
Deuns has joined #crystal-lang
<Deuns> hello
<jhass> hi :)
<Deuns> hi jhass
<Deuns> I am trying to start invidious on openbsd-current. It builds fine with crystal 0.34.0 but I launch it : "Invalid memory access (signal 11) at address 0x4" (full trace at https://pastebin.com/ZkLREqw9)
<Deuns> searching the internet it seems to be related to a compiler bug.
<Deuns> Can anyone help on debugging this one ?
<jhass> mmh, that's not a very helpful trace :/
<jhass> (not your fault :D)
<Deuns> unfortunately. I am all hear to have a better trace :)
<jhass> running it under lldb might give a better one
<jhass> I see it ships precompiled static libraries in one of its dependencies (lsquic)
<jhass> might be just that
<Deuns> I rebuilded lsquic so I can compile :)
<Deuns> Program received signal SIGSEGV, Segmentation fault.
<Deuns> ) at /usr/src/lib/libcrypto/ex_data.c:425
<Deuns> int_new_ex_data (class_index=Variable "class_index" is not available.
<Deuns> I will dig in that direction
<Deuns> thanks jhass
<jhass> good it tells you something, for me it doesn't really :D
ur5us has quit [Ping timeout: 240 seconds]
<FromGitter> <j8r> I don't really understand https://crystal-lang.org/api/master/HTTP/Cookies.html#[]=(key,value:Cookie)-instance-method
<FromGitter> <j8r> `response.cookies["foo"] = HTTP::Cookie.new("foo", "bar", "/admin", Time.utc + 12.hours, secure: true)`
<FromGitter> <j8r> Wouldn't be more robust to have `response.cookies.add(cookie)`?
<jhass> https://crystal-lang.org/api/master/HTTP/Cookies.html#%3C%3C(cookie:Cookie)-instance-method
<jhass> I think it's just symmetry with #[]
<FromGitter> <j8r> ho I miss this, thanks
<FromGitter> <j8r> A bit confusing to have both
<FromGitter> <j8r> Any use case?
<FromGitter> <hanneskaeufler> Hi y'all, can one add type restrictions to splat arguments somehow?
<jhass> well #[] makes sense right?
<jhass> see my guess above then
<jhass> @hanneskaeufler yeah, just do it :) https://carc.in/#/r/8w87
<FromGitter> <hanneskaeufler> > *<jhass>* @hanneskaeufler yeah, just do it :⁠) https://carc.in/#/r/8w87 ⏎ ⏎ D'oh, I was preoccupied with the thought of it now working so I didn't even try zomg, thanks
<FromGitter> <j8r> jhass: but it does not to have a key name different to the cookie name
<Stephie> i'm glad we still have the old purple crystal styling on the docs generator
<Stephie> instead of making it black and white and boring
<jhass> hehe
<jhass> I wouldn't mind a dark theme though
<Stephie> idk
<Stephie> i tend to not like dark themes
<Stephie> it should use the new "dark theme" browser thing
<Stephie> if anything
<livcd> Stephie is RX14?
<Stephie> yeah
<livcd> what happened?
<Stephie> what do you mean?
<livcd> why the change?
<Stephie> it's my name...
<Stephie> i changed like, months ago
<Stephie> from one nick to the other
<Stephie> cause i prefer it
<Stephie> I actually think this could look really cool with some tweaks: http://owo.sh/6bKA4ka.png
<jhass> aww common Ary, don't troll
<Stephie> hmm?
<jhass> ah, check your GH notifications, you'll see :P
<Stephie> this is a busy morning
<Stephie> so so many notifications
<jhass> maybe we could preserve the purple as a highlight color. For links or idk what
<Stephie> i'm fine with it as it is
<Stephie> honestly
<Stephie> preferred
<Stephie> but i also wouldnt mind if it was changed either
<Stephie> it's just a nice throwback
<jhass> did sommebody do a docset yet btw?
<Stephie> hmm?
<jhass> for Dash etc
<jhass> nothing maintained apparently
<Stephie> oh
<Stephie> i've never used those
<FromGitter> <j8r> 👍 for dark theme
<Stephie> sigh
<jhass> :D
<FromGitter> <Blacksmoke16> @Afront naw, was with https://www.jetbrains.com/datagrip/
<FromGitter> <Blacksmoke16> or really use custom properties to allow custom branding
<FromGitter> <Blacksmoke16> to fit the theme of the project
<FromGitter> <j8r> The docs can be dark theme compatible, by not setting a background nor a foreground color
<FromGitter> <j8r> But the color will likely not be conistent
<Stephie> there's CSS support for dark and light themes now @j8r
<Stephie> like media queries
<Stephie> yup
<FromGitter> <j8r> We still need to write CSS styles
<Stephie> ...yup
<Stephie> that is indeed how the web works
<FromGitter> <j8r> Indeed, autodetection would be nice instead of a manual toggle
<FromGitter> <Blacksmoke16> custom properties would help, as CSS could be generalized and by just loading a custom `theme.css` file, would propagate to rest of stuff
<FromGitter> <Blacksmoke16> i.e. have some for links, background, sidebar, etc
<FromGitter> <Afront> Ahh I see thanks!
<FromGitter> <j8r> I am opening an issue
<FromGitter> <Blacksmoke16> https://forum.crystal-lang.org/t/log-module-suggestions/1962 made a forum thread about some ideas/suggestions for the Log Module
<FromGitter> <stronny> I think your suggestions mean that Crystal is not good enough
<FromGitter> <stronny> you seem to want to log more information, while a good implementation would require you to log less
<FromGitter> <stronny> here are my thoughts: ⏎ ⏎ 1) basically there are two main modes of logging: audit and debug ⏎ 2) both should ideally be automatic, based on some source annotations instead of explicit calls to log functions ⏎ 3) debug logs should be smart enough to provide as much context to a problem as possible ... [https://gitter.im/crystal-lang/crystal?at=5e9711dee920022432a637e5]
<FromGitter> <Blacksmoke16> none of those features would inherently result in more logged data on their own.
<FromGitter> <Blacksmoke16> they give the ability to better setup common data, or control how stuff is logged
<FromGitter> <stronny> why do you have several backends?
<FromGitter> <Blacksmoke16> does it not make sense to log something to a file in dev env, elasticserach, and new relic for example?
<FromGitter> <Blacksmoke16> ofc with each of those backends not handling *every* entry, i.e. only send unhandled exceptions and/or >error to newrelic
<FromGitter> <stronny> as a first approach I'd say the program should log to stdout and that's it
<FromGitter> <Blacksmoke16> sure
<FromGitter> <Blacksmoke16> then is it so bad to want to log to stdout, but then also send to es, or sentry etc if its a warning or higher?
<FromGitter> <Blacksmoke16> or in case of prod, change stdout to a file
<FromGitter> <stronny> it's okay if you control the whole operation
<FromGitter> <stronny> it's bad if you only distribute your program
<FromGitter> <Blacksmoke16> i was thinking of having this by default, it would be up to the end user to configure how they wish
<FromGitter> <Blacksmoke16> wasnt*
<FromGitter> <Blacksmoke16> plus the multi backend thing is already possible so :shrug:, could be improved a bit with the bubble concept but im not expecting all of that to be approved
<FromGitter> <stronny> as a rule integration should not be done by configuring a monolithic blob, it should be done by composition of small entities
<hightower2> Hey folks, using Crystal 0.34 (but possibly unrelated to version), I run a most basic app powered by Kemal (like 20 lines total), and immediately as it starts the resident memory size goes to 360MB, while an empty "crystal eval" process takes 140MB. What's the story behind this?
<hightower2> (I mean behind these numbers which I find surprisingly high)
<FromGitter> <stronny> how about a release build?
<hightower2> yes the kemal number is with --release, and it made no difference compared to running without
<FromGitter> <Blacksmoke16> prob would also help to ask what this app is doing
<FromGitter> <Blacksmoke16> like returning large JSON payloads or something?
<hightower2> no nothing, this is immediately after startup, with no requests
<hightower2> but I think I see... this must be memory usage from the compilation stage
<hightower2> if I compile to a binary I bet it'd be much smaller when the binary runs.. lemme check
<hightower2> yeah indeed... the binary itself takes around 20MB
<hightower2> ok, thanks for the discussion
<FromGitter> <Blacksmoke16> id suggest setting up a target
<FromGitter> <Blacksmoke16> then you can do `shards build --production` to build prod binaries of your application
<FromGitter> <Blacksmoke16> that you could then run directly, or do whatever with
<hightower2> yes, yes, no worries, I just stumbled upon this randomly and didn't recall the reason immediately
<FromGitter> <Blacksmoke16> 👍
HumanGeek has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter> <neutrinog> does anyone know how to create a multi-dimensional array of a fixed size? I'm not looking for a StaticArray because the array size is determined from a variable.
<FromGitter> <neutrinog> seems like there some be some handy syntax for that.
<FromGitter> <ondreian> Is there a good way to run `postinstall` hooks in isolation for testing?
<FromGitter> <ondreian> `shards run postinstall` for instance
<FromGitter> <Blacksmoke16> prob could setup another project and install your shard
<FromGitter> <Blacksmoke16> then like delete lib/bin/lock file etc
<FromGitter> <Blacksmoke16> to test it again
<FromGitter> <ondreian> hmm, ok. thanks, guess that works for now.
<FromGitter> <Blacksmoke16> can also setup the shard dep to point to a local file
<FromGitter> <Blacksmoke16> not sure how that would play with postinstall but worth a shot?
<FromGitter> <lodenos> Hello everyone, I search a way for writing of multi included module an example for be more explicite, It normal way is `module A module B end end` and in used is `A::B` but I would like some `module A ... end module B ... end` and find for writing like thar `A::B`
<FromGitter> <Blacksmoke16> could just do
<FromGitter> <Blacksmoke16> ```module A::B; end``` ⏎ ⏎ ? [https://gitter.im/crystal-lang/crystal?at=5e974487c7dcfc14e2bd84b1]
<FromGitter> <lodenos> @Blacksmoke16 Thx it's work with that but I need rename every declaration of module B every file
<FromGitter> <lodenos> Like the keyword include without the fusion with the current namespace like same layer u know what I neam. ?
<FromGitter> <Blacksmoke16> what you want isnt really possible without either using that syntax, or nesting the modules
<FromGitter> <Blacksmoke16> having them separate would create two separate namespaces, not one within the other
<FromGitter> <lodenos> I know it's for that I coming here because I beginer in Crystal <3 <3 <3
<FromGitter> <Blacksmoke16> all good, welcome
<FromGitter> <randiaz95> Welcome to Crystal!
<FromGitter> <randiaz95> Its the best option today.
<FromGitter> <lodenos> Ok thx for your help, I try to writing something not possible haha
<FromGitter> <randiaz95> With software nothing is impossible.
<oprypin> wellllll
<FromGitter> <Blacksmoke16> `1 / 0`
<FromGitter> <Afront> ~~If you have the right hardware~~
<FromGitter> <randiaz95> Exactly lol
<FromGitter> <randiaz95> robot armo etc.
DTZUZU has quit [Read error: Connection reset by peer]
DTZUZU has joined #crystal-lang
<FromGitter> <kinxer> @neutrinog You could use normal arrays with the constructors that pre-allocate (e.g. https://crystal-lang.org/api/0.34.0/Array.html#new(initial_capacity:Int)-class-method ).
<FromGitter> <kinxer> If you want to create your own implementation, you'd probably want to back it with slices (docs (https://crystal-lang.org/api/0.34.0/Slice.html)).
<FromGitter> <randiaz95> I wonder how I would get the default value for this
<FromGitter> <randiaz95> parameter, or for other built in classes
<FromGitter> <Blacksmoke16> granted they would still grow but yea
<FromGitter> <Blacksmoke16> @randiaz95 can get default value in a macor
<FromGitter> <Blacksmoke16> macro
<FromGitter> <randiaz95> initial_capacity is not a public attribute?
<FromGitter> <Blacksmoke16> no as its used when the array is created
<FromGitter> <randiaz95> right..
<FromGitter> <randiaz95> I think default is 0 as per the source code.
<FromGitter> <Blacksmoke16> possibly
<FromGitter> <randiaz95> yep ``` ⏎ def initialize ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5e9753a5a412254f2187de98]
<FromGitter> <Blacksmoke16> makes sense
<FromGitter> <kinxer> Yeah, but once something is put in it, it goes up to 3, and then it doubles every time it needs to resize.
<FromGitter> <randiaz95> :o
<FromGitter> <randiaz95> how u learned that?
<FromGitter> <randiaz95> Is that intelligent?
<FromGitter> <randiaz95> Would be cool if we had an ai that would predict the marginal needed increase in capacity lol
<FromGitter> <randiaz95> but that would defeat the purpose, since training machine learning algos take longer.
<FromGitter> <kinxer> I'd bet that there's a lot of research out there about heuristics for array size increases.
<FromGitter> <randiaz95> Hmm
<FromGitter> <kinxer> I'd also bet that whoever wrote `Array` knew what they were doing.
<FromGitter> <randiaz95> Sure..
<FromGitter> <randiaz95> Simple is better than complex
<FromGitter> <kinxer> Yeah, usually.
<FromGitter> <randiaz95> I would've done 1.5* increase but w.e
<FromGitter> <randiaz95> Oh.. wut about queue?
<FromGitter> <randiaz95> maybe that one increases capacity slower right?
<FromGitter> <randiaz95> as to not bloat RAM
<FromGitter> <kinxer> That would require conversion to float and then back to int.
<FromGitter> <randiaz95> ^^
<FromGitter> <randiaz95> haha
<FromGitter> <kinxer> I thought it was Array-backed? I'll take a look...
<FromGitter> <randiaz95> wouldn't that defeat the purpose of queue?
<FromGitter> <randiaz95> just use array then if there are no benefits.
<FromGitter> <kinxer> IMO, the purpose of a queue is to disallow random access (and restrict it to just one end).
<FromGitter> <kinxer> Or, in the case of `Deque`, to either end.
<FromGitter> <randiaz95> Sure but why would you like to lose that without having some benefit?
<FromGitter> <randiaz95> you know?
<FromGitter> <kinxer> Defining an API in a way that makes it easier to know how a structure is supposed to be used is its own benefit.
<FromGitter> <kinxer> But you're right: it's not Array-backed.
<FromGitter> <randiaz95> `def push(value : T) ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ end` [https://gitter.im/crystal-lang/crystal?at=5e97560ee920022432a75e92]
<FromGitter> <randiaz95> Increases capacity on push
<FromGitter> <kinxer> If it needs to.
<FromGitter> <randiaz95> Right..
<FromGitter> <kinxer> Array does that, too.
<FromGitter> <kinxer> Goes straight from 0 to 4, and then doubles.
<FromGitter> <randiaz95> it seems to do @capacity *= 2 in increase_capacity
<FromGitter> <randiaz95> yep
<FromGitter> <kinxer> Actually, it may goes straight from 0 to 8.
<FromGitter> <randiaz95> unless buffer @capacity = 8
<FromGitter> <randiaz95> sorry 4
<FromGitter> <kinxer> Sure. If you use the `initial_capacity` constructor, you can give it any capacity you want.
<FromGitter> <randiaz95> I think crystal can be used to make some sweet future internet tech
<FromGitter> <randiaz95> its good syntax/readability with great speed
<FromGitter> <randiaz95> What are you into making ben?
<FromGitter> <kinxer> I don't actually get a lot of time/energy to work on Crystal software... I mostly use C++ and bash at work. I'd like to write some geographic software in Crystal at some point, and maybe some natural language/linguistics software.
<FromGitter> <randiaz95> Very cool :D
<FromGitter> <randiaz95> There are hundreds of applications when it comes to those two
<FromGitter> <randiaz95> I wish I had more energy.
<FromGitter> <kinxer> Yeah. I also have a few ideas for things that I've never heard of being done before, but those are (of course) huge projects, and I've barely started on any of them.
<FromGitter> <randiaz95> Having a big family of non-coders is draining..
<FromGitter> <kinxer> Lol. I feel like it'd be more draining to have a family of coders, honestly.
<FromGitter> <randiaz95> Lol!
<FromGitter> <randiaz95> Habits make things less draining
<FromGitter> <randiaz95> Changing your routine for me is draining
<FromGitter> <kinxer> Yeah... The state of the world right now doesn't help with that.
<FromGitter> <randiaz95> Imagine your dad had already written the libraries for authentication in node and all you need to do is hit an api endpoint.. ⏎ ⏎ Essentially a firebase crud api. ⏎ ⏎ Your pervy sister trained boosting algo to find inappropriate things in images. [https://gitter.im/crystal-lang/crystal?at=5e9758508e987f3a5e19c417]
<FromGitter> <randiaz95> you can make an instagram within a day lol.
<FromGitter> <randiaz95> Im trying to see the positive of this.
<FromGitter> <kinxer> I mean, the self-hosted smart-home situation could be fantastic.
Deuns has left #crystal-lang [#crystal-lang]
<FromGitter> <randiaz95> True.. are you saying the return of desktop apps is coming?!
<FromGitter> <randiaz95> If the internet dies.
<FromGitter> <kinxer> Family Matrix chat, self-hosted location sharing, etc...
<FromGitter> <kinxer> I mean, I only work on native works professionally (putting me in the minority in the Crystal community, I think :P ).
<FromGitter> <kinxer> *native apps
<FromGitter> <randiaz95> The privacy thing is kinda not a feature, due to the fact that no one reads terms of agreement and 2ndly how would u upgrade the software without them thinking that you are possibly taking data.
<FromGitter> <kinxer> I'm sorry, I'm not following. Is this re Matrix?
<FromGitter> <randiaz95> What is re-matrix?
<FromGitter> <randiaz95> Im talking about the self-hosting part; that would be stored on a desktop/laptop computer
<FromGitter> <kinxer> Oh, I was thinking about self-hosting just for one's one family.
<FromGitter> <randiaz95> on a hosting service?
<FromGitter> <kinxer> And I said "re Matrix", meaning "regarding/relating to Matrix".
<FromGitter> <kinxer> No, on an in-home server.
<FromGitter> <kinxer> If you're not doing anything really enterprise-scale, I'd expect that using your own machine wouldn't cause problems.
<FromGitter> <randiaz95> my desktop has 32 gigs of ram and 2 terabytes
<FromGitter> <randiaz95> of hardisk
<FromGitter> <randiaz95> so im sure im good.
<FromGitter> <kinxer> Yeah, that's hefty. I don't have anything nearly that big.
<FromGitter> <randiaz95> i wonder if i can change my wifi's ip to have a domain
<FromGitter> <randiaz95> RandyNet
<FromGitter> <randiaz95> I can chat with my drone and it would fly to the kitchen and bring a bag of chips.
<FromGitter> <kinxer> Lol.
<FromGitter> <kinxer> http://randy.net/ isn't taken. XD
<FromGitter> <randiaz95> not on namecheap
<FromGitter> <randiaz95> randy.org is 9k
<FromGitter> <kinxer> Big oof.
<FromGitter> <kinxer> Is that per year?
<FromGitter> <randiaz95> lol
<FromGitter> <randiaz95> yes
<FromGitter> <kinxer> Nah, I have a domain name in mind when I actually have something to put on it.
<FromGitter> <randiaz95> woops
<FromGitter> <randiaz95> i meant this one lol
<FromGitter> <kinxer> But I'm keeping it in my head until then, so the internet usage tracking doesn't make the prices higher for me.
<FromGitter> <randiaz95> lol
<FromGitter> <randiaz95> I just clicked randy.net
<FromGitter> <randiaz95> DANG IT!
<FromGitter> <randiaz95> price api just did url.price ++
<FromGitter> <kinxer> Ah... My bad there.
<FromGitter> <randiaz95> im in a long boring skype meeting right now
<FromGitter> <randiaz95> you working from home?
<FromGitter> <randiaz95> https://www.upfluence.com/ is something someone is using.
<FromGitter> <randiaz95> marketplace for influencer ads
<FromGitter> <kinxer> Yeah, I'm working from home. Currently refactoring some C++ code that has 3-space indentation...
<FromGitter> <randiaz95> 1) o
<FromGitter> <randiaz95> Ctrl f and replace
<FromGitter> <randiaz95> haha you need to code a script to fix the software
<FromGitter> <kinxer> I started using an autoformatter (clang-format) and set format-on-save, so at least the indentation isn't the hard part to fix.
<FromGitter> <randiaz95> Im very glad you aren't in python lol..
* FromGitter * tenebrousedge twitches
masterdonx2 has quit [Quit: ZNC 1.7.5 - https://znc.in]
<FromGitter> <kinxer> Yeah... I will have to refactor some manually-written text-parsing C++ code soon, though, to use C++ streams, 'cause if I don't then someone else in 3-10 years will have to decipher it.
<FromGitter> <tenebrousedge> I've been doing those Google Foobar challenges lately, and the only options for languages are Python and Java, so I learned Python
<FromGitter> <kinxer> That part wouldn't be necessary in Python.
<FromGitter> <randiaz95> I wonder if he is reckless with that if he would be reckless with your rvalue pointers
<FromGitter> <tenebrousedge> whitespace issues are so so obnoxious
MasterdonX has joined #crystal-lang
<FromGitter> <kinxer> Yeah... Mixed tabs and spaces are annoying in most languages; in Python they're syntax. :|
<FromGitter> <kinxer> I say this as a young developer who learned Python first in school.
<FromGitter> <randiaz95> 2 space tabs are optimal for me
<FromGitter> <randiaz95> unless you have bad astygmatism like me and u need more space
<FromGitter> <randiaz95> 4
<FromGitter> <tenebrousedge> I really have no idea why Python is as popular as it is
<FromGitter> <kinxer> Python is a whole lot more fun to mess with than C-like languages, but recently I've had trouble going back to Python because of the weak typing.
<FromGitter> <randiaz95> Also, if you want to be accepting of bad eyesight please use underscore and notThis
<FromGitter> <randiaz95> Python is the easiest language to learn
<FromGitter> <randiaz95> easier than ruby
<FromGitter> <tenebrousedge> @kinxer that seems like a low bar
<FromGitter> <kinxer> Lol. Fair.
<FromGitter> <randiaz95> c# is fun too
<FromGitter> <randiaz95> specially with high autocomplete
<FromGitter> <kinxer> In school, the languages I learned some of were Python, C, C++, Java, Haskell, and Perl. And my first programming language was technically TI-BASIC.
<FromGitter> <randiaz95> When crystal has good autocomplete it will explode.
<FromGitter> <kinxer> So Python was my favorite of those.
<FromGitter> <randiaz95> I know python off the top of my head
<FromGitter> <randiaz95> everything essentially lol
<FromGitter> <randiaz95> i can make an antivirus off the top of my head.
<FromGitter> <kinxer> I just wasn't exposed to anything more pleasant to work in than Python.
<FromGitter> <randiaz95> I wish python had a File.new or File.read obj
<FromGitter> <randiaz95> Much better syntax
<FromGitter> <randiaz95> with open("file.txt") as file:
<FromGitter> <randiaz95> too many words
<FromGitter> <randiaz95> I use pd.read_X anyways
<FromGitter> <j8r> Python is good for coding, not running :/
<FromGitter> <randiaz95> Not true.. Its fine for running 90% of projects and systems
<FromGitter> <j8r> I prefer more safe languages to run in production
<FromGitter> <randiaz95> When you get more than 100 requests per second ( Which you should be making tons of money already) do a rewrite of major endpoints in crystal.
<FromGitter> <randiaz95> you can use static typing on all functions now in Python.
<FromGitter> <j8r> I don't only talk about performance
<FromGitter> <kinxer> Yeah. My concern with Python is much more the type safety than performance.
<FromGitter> <j8r> No, @randiaz95 - this are just docs
<FromGitter> <j8r> we can put everything and it will happily compile
<FromGitter> <randiaz95> It wont run
<FromGitter> <randiaz95> Also there are tools like kite and pycharm that make coding in python even more productive
<FromGitter> <randiaz95> so productivity can hit 1000% lol
<FromGitter> <randiaz95> reminds me of scala
<FromGitter> <j8r> @randiaz95 again, nope
<FromGitter> <j8r> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e976448d240da24337357b1]
<FromGitter> <j8r> I put a space by mistake, but it changes nothing to the result
<FromGitter> <randiaz95> OH i forgot I thought u meant compile
<FromGitter> <randiaz95> I thought the compilers for python would do type checking.
<FromGitter> <randiaz95> Sure that is a flaw. but I mean, if you throw garbage in any language ( Except GO ) it will return garbage lol
<FromGitter> <randiaz95> Go is perfect for that then
<FromGitter> <j8r> It is possible there are linters, like pylint, and others that check types
<FromGitter> <j8r> but won't be as perfect as built-in
<FromGitter> <randiaz95> Just handle everything as a string lol
<FromGitter> <randiaz95> if you need operators of other data types do quick transformations.
<FromGitter> <j8r> Rust is probably one of the best language to run in production... except I won't be surprised to have rarely very weird incomprehensible errors
<FromGitter> <j8r> predictive performance is a good to have
<FromGitter> <randiaz95> Can't we just test our code?
<FromGitter> <randiaz95> lol
<FromGitter> <j8r> Sure, but testing all possible cases is impossible
<FromGitter> <j8r> and even though there are some errors unrelated to the code itself
<FromGitter> <j8r> like some piece of code that put pressure on the GC, degrading the service
<FromGitter> <j8r> *I meant, unrelated if the code works by passing the test
lanodan has quit [Ping timeout: 260 seconds]
yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
yxhuvud has joined #crystal-lang
lanodan has joined #crystal-lang
ur5us has joined #crystal-lang
_ht has quit [Quit: _ht]
<hightower2> Hey what function is called on object destruction?
<oprypin> hightower2, finalize
<hightower2> thank you kindly
<oprypin> hightower2, it is frowned upon because u never know when it will be called
<FromGitter> <Blacksmoke16> only for classes ^
<hightower2> yes, yes, I have a class. But good note, thanks
<FromGitter> <ondreian> What's best practices for expressing non-Integer type enums, specifically `String` enums in my current case.
<FromGitter> <tenebrousedge> since when do we have string enums?
<FromGitter> <tenebrousedge> I would probably use a hash
<FromGitter> <ondreian> Well, the documentation says there aren't any, but if I want to provide the niceness of compile-type checks/autocomplete for an example coming from Typescript for instance...
<FromGitter> <tenebrousedge> what's the example?
<FromGitter> <tenebrousedge> @Blacksmoke16 what's the benefit of that over a hash?
<FromGitter> <Blacksmoke16> you get the type safety of the enum
<FromGitter> <Blacksmoke16> another option would be to overload `to_s(io)` as those values are just the string representations of the enum
<FromGitter> <tenebrousedge> can't enums be used as hash keys though?
<FromGitter> <Blacksmoke16> sure, case wouldnt allocate memory tho
<FromGitter> <kinxer> Also, isn't everything in the method example stack-allocated?
<FromGitter> <Blacksmoke16> so thats one benefit
<FromGitter> <tenebrousedge> `case` is less flexible. I prefer to use enumerable data structures, by default. I'm definitely not going to worry about the memory use of a three-element hash
<FromGitter> <Blacksmoke16> flexibility doesnt matter in this since its an enum tho?
<FromGitter> <Blacksmoke16> enum members wont change dynamically
<FromGitter> <tenebrousedge> today it's an enum. Tomorrow you might want more than one value?
<FromGitter> <tenebrousedge> I dunno, I just have a knee-jerk anti-`case` habit
<FromGitter> <Blacksmoke16> if this is a flag enum then yea dont use case
<FromGitter> <Blacksmoke16> well you could, just use a custom to_s method
<FromGitter> <ondreian> I just want autocomplete to work properly. If I use a hash that won't work
<FromGitter> <ondreian> I think the `case` encode/decode method is probably best
<FromGitter> <Blacksmoke16> enum with custom `to_s(io)`, or some other method
<FromGitter> <Blacksmoke16> depends on how it will be used
<FromGitter> <tenebrousedge> I mean, that example is just using constants
<FromGitter> <tenebrousedge> so you could do: ⏎ ⏎ ```ADD = "ADD" ⏎ DELETE = "DELETE" ⏎ PUT = "PUT"``` [https://gitter.im/crystal-lang/crystal?at=5e9785100480c128efbd35b8]
<FromGitter> <Blacksmoke16> depends on how it'll be used
<FromGitter> <Blacksmoke16> if the user is going to provide the value, enum. if its a static thing used within a method or something, then constant
<FromGitter> <ondreian> Thanks, the `entry.cr` gives me a good starting place I think. if not i'll be back. :slight_smile:
<oprypin> we need the ability to make pull requests to wiki 😬
<FromGitter> <watzon> Hey @gdotdesign you around?
<FromGitter> <Blacksmoke16> oprypin: pretty sure you can just edit it
<oprypin> Blacksmoke16, well duh
<oprypin> enjoy the read. best clickbait title ever, too. https://github.com/crystal-lang/crystal/issues/9089 cc Stephie,
<FromGitter> <straight-shoota> > we need the ability to make pull requests to wiki 😬 ⏎ ⏎ The wiki is just a git repo, so should actually be doable... =)
<FromGitter> <straight-shoota> But I'd prefer to use the wiki as little as possible
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#9c13f01 (master - Correct duplicated articles/prepositions (#9087)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/675512818
travis-ci has left #crystal-lang [#crystal-lang]
<hightower2> mm, if I'd like to end up with say, 10 objects in an array, like lst = [10 x Someobj.new] , what's the exact syntax that'd be recommended
<FromGitter> <Blacksmoke16> no arguments?
<hightower2> one arg, Someobj.new(onearg)
<FromGitter> <Blacksmoke16> ```objs = [] of Someobj ⏎ 10.times { objs << Someobj.new arg } ⏎ objs``` [https://gitter.im/crystal-lang/crystal?at=5e979757c7dcfc14e2bed5c6]
<FromGitter> <Blacksmoke16> no
<FromGitter> <Blacksmoke16> `Array.new 10, Someobj.new(arg)`
<FromGitter> <Blacksmoke16> there
<hightower2> you da man
return0e_ has quit [Read error: Connection reset by peer]
<hightower2> hm though, this gives me 10 times the same obj... I'd need a new instance 10 times
<hightower2> maybe a constructor with a block would do it, let me search
<FromGitter> <Blacksmoke16> try `Array.new 10 { Someobj.new arg }
<hightower2> yeah
<FromGitter> <Blacksmoke16> yea
return0e has joined #crystal-lang
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#07e8a48 (master - Refactor is_crystal_repo based on project name (#9070)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/675523649