Papierkorb has left #crystal-lang ["Konversation terminated!"]
<FromGitter>
<sdogruyol> just curious, how do you guys usually mock / stub?
<FromGitter>
<ryankshah> When using `@var : Type` in an abstract class, I get thrown this error: `instance variable ... was not initialized directly in all of the 'initialize' methods, rendering it nilable. Indirect initialization is not supported.`
<FromGitter>
<ryankshah> How can I fix this?
<FromGitter>
<ryankshah> Do I have to give it a default value first in the abstract class?
<FromGitter>
<ryankshah> Something like this would make life so much easier when writing documentation
shalmezad has joined #crystal-lang
return0e has joined #crystal-lang
<FromGitter>
<girng> hello friends im having problem with int64
<FromGitter>
<girng> `property selected_characterid = Int64` gives me `instance variable '@selected_characterid' of Client must be Int64:Class, not Int64` what am i doing wrong???
<FromGitter>
<girng> If i do `Int32` it works
<jokke>
`property selected_characterid : Int64`
<FromGitter>
<girng> what's difference between : Int64 and : Int32, when = Int32 works?
That_Guy_Anon has joined #crystal-lang
<FromGitter>
<plainas> so when I output an object in a string context, which method gets called to render that string?
<FromGitter>
<plainas> as in puts "#{moyobject}"
<FromGitter>
<plainas> it differs from the output of to_s
That_Guy_Anon has quit [Ping timeout: 240 seconds]
<FromGitter>
<ryankshah> I think it depends on the Object
Jenz has joined #crystal-lang
<Jenz>
Although pointers are unsafe, and I don't get them (as I've never properly used them), I like them
<Jenz>
They look cool
<FromGitter>
<ryankshah> @plainas I think that some objects override `Object.to_s` to print out a specific format such as the example here https://carc.in/#/r/3thx
<FromGitter>
<ryankshah> But if you look here with no override of `to_s` in a new class i create called `MyClass`, it prints as follows https://carc.in/#/r/3thy
<FromGitter>
<ryankshah> I'm probably wrong, but this is how it works in my head - Correct me if I'm entirely wrong
duane has quit [Ping timeout: 255 seconds]
<Jenz>
You override Object#to_s(io); docs say you shouldn't override #to_s
<Jenz>
But you are right, you override Object#to_s(io) to get a specific format or to print whatever you wish really
<Jenz>
(`puts` calls #to_s on object if its not a string)
<FromGitter>
<ryankshah> Ahhh okay that makes sense thanks for clarifying Jenz
<FromGitter>
<ryankshah> Also, how can I check if a `Set` contains an element?
<FromGitter>
<ryankshah> or if not possible, check if an `Array` contains an element (or to be able to check index) using `Set.to_a`
<FromGitter>
<plainas> I am using kemal... if I print a websocket object in a string context I get a short sthing like this:
<FromGitter>
<ryankshah> Since `Set` implements `Enumerable` would the best way to do this be using `Set.count(item)` and checking if `count(item) == 0`?
<FromGitter>
<ryankshah> Probably your best shot buddy :)
<FromGitter>
<plainas> I usually hang out there as well
<FromGitter>
<plainas> in fact more than here :D
<FromGitter>
<ryankshah> Probably the better option then :D
<FromGitter>
<plainas> But this is not kemal specific. HTTP::websocket is from the standard api
<FromGitter>
<ryankshah> Oh right I thought you were implementing the web socket from kemal my bad
<FromGitter>
<plainas> So the question that remains is how could ```puts #{myObject}``` possibly differ from puts myObject.to_s ?
<FromGitter>
<ryankshah> That question was already answered
<FromGitter>
<ryankshah> Right?
<FromGitter>
<plainas> Jens touched it, but I don't know what "a specific" format refers to nor how to trigger it or control it
<FromGitter>
<ryankshah> Well how about this
duane has joined #crystal-lang
<FromGitter>
<ryankshah> Using this syntax everything between the opening #{ and closing } bits is evaluated as Crystal code, and the result of this evaluation will be embedded into the string surrounding it.
<FromGitter>
<ryankshah> So `#{myObject}` will evaluate `myObject` and returns the value of `myObject` into the string
<FromGitter>
<plainas> suposedly by calling .to_s on it... no?
<FromGitter>
<ryankshah> Not necessarily
<FromGitter>
<ryankshah> It is whatever the variable evaluates to
<FromGitter>
<ryankshah> This outputs `"I said, Hello World!"`
<FromGitter>
<plainas> well, but .to_s of a string is the string itself. Could you show an example class where the above to snippets result in distinct output?
<FromGitter>
<ryankshah> Although its ruby its kind of a similar concept
<FromGitter>
<plainas> does that hold in crystal?
<FromGitter>
<ryankshah> @straight-shoota mind helping?
<FromGitter>
<straight-shoota> I didn't catch the original question...
<FromGitter>
<straight-shoota> `to_s` in Crystal is similar to Ruby
hightower3 has quit [Ping timeout: 240 seconds]
<FromGitter>
<straight-shoota> `to_str` is not implemented in Crystal stdlib
<FromGitter>
<r00ster91> uh when I generate my docs with `crystal docs` and I for example have something like this in my shard: ⏎ ⏎ ```module MyShardName ⏎ module SomeModule ⏎ end ⏎ end``` ⏎ ⏎ then `crystal docs` will also generate a new folder "MyShardName" inside the docs folder. ... [https://gitter.im/crystal-lang/crystal?at=5ac4d980e3d0b1ff2c9ec212]
<FromGitter>
<r00ster91> so it looks like theres an index.html missing. Why is crystal docs not generating this?
<FromGitter>
<plainas> @straight-shoota so I am using kemal, and I am trying to print debug info of my websockets...
<FromGitter>
<ryankshah> @straight-shoota he's trying to differentiate between `#{}` and `to_s`
<FromGitter>
<plainas> in some places I get a short string reprensentation... in others I get a huge dump with all the attributes, includding low level stuff
<FromGitter>
<ryankshah> @r00ster91 try adding a commend above each module to generate some sort of text and try again
<FromGitter>
<straight-shoota> @r00ster91 do you have a link?
<FromGitter>
<r00ster91> wait I will try
<FromGitter>
<straight-shoota> comment is not needed, every type will have a docs page unless it is explicitly flagged as `# :nodoc:`
<FromGitter>
<plainas> in short.... how do I get a representation like this: ```#<HTTP::WebSocket:0x55f89b21e700>``` instead of the one that its like a whole page of text
<crystal-gh>
[crystal] ysbaddaden pushed 1 new commit to master: https://git.io/vxMGO
<crystal-gh>
crystal/master b5a3a65 Johannes Müller: Fix File.join with empty path component (#5915)
<FromGitter>
<straight-shoota> @plainas There is a difference between `#to_s` which returns a string representation of an object and `#inspect` which is usually more detailed
<FromGitter>
<ryankshah> @straight-shoota so does string interpolation invoke `#inspect`?
<FromGitter>
<straight-shoota> `HTTP::WebSocket` uses the default implementations of `Reference` where `#to_s` returns the class name and object id and `#inspect` prints all instance variables
<FromGitter>
<straight-shoota> no, interpolation uses `#to_s(io : IO)`
<FromGitter>
<ryankshah> ^^
<FromGitter>
<ryankshah> Makes sense now
<crystal-gh>
[crystal] MakeNowJust opened pull request #5917: MatchData: correct sample code for duplicated named capture (master...fix/regex-match-data/named-cap-doc) https://git.io/vxMZq
<FromGitter>
<plainas> mmm I think the reason why sometimes I am getting a short description is because those are in the onClose cases
<FromGitter>
<plainas> probably the websocket object is emptied before?
poopBot has joined #crystal-lang
<FromGitter>
<plainas> mmmmm apparently not
<poopBot>
hi i am exploring stuff, want to learn some other languge , wanted something whit better productivity and better crossplatformnes then c# , so i started little Nim , googling found Crystal too so would like to know what are Pros/Cons
<FromGitter>
<plainas> If we take this example: http://kemalcr.com/cookbook/websocket_chat/ those print tatements are short.... but try and print one from the sockets array, bam... a huge amount of output floods my terminal
<FromGitter>
<bararchy> @straight-shoota and RX14 are you guys planning on addressing my proposal for single msqueue ?
<FromGitter>
<plainas> poppBot (lol@name) I am a crystal begginer too, I found it offer more direct benifit through better practicality. You can read the manual in a couple of hours, then there are good libraries out there for most stuff, shards and the compiler are easy to use and there is kemalcr which I love. Another differenciating factor was Fibers.... Nim didn't have any easy way to do things concurrently without using many
<FromGitter>
<girng> plz help, i can't define int 64 in property
<FromGitter>
<girng> but i can do int32
<FromGitter>
<plainas> I dislike async await idiom. very much. Why can't languages just implement P() and V() normaly on green threads?
<dom96>
Why do you dislike it?
<FromGitter>
<plainas> two things: 1. puts functions into to distinct categories 2. doesn't provide an easy way to control (limit) how many things you want to do at once.
<FromGitter>
<plainas> assigning concurrency details to a function, rather than programming your concurrency separately from your functions is not intuitive, just my opinion i guess.
<dom96>
I would think that async await provides more control
<dom96>
With green threads everything is done behind the scenes
<FromGitter>
<girng> async await makes code look more synchronous with asynchronous ability right??
<FromGitter>
<straight-shoota> @bararchy I'm not really into threading support
<dom96>
you have no control over when your thread yields to the event loop
<FromGitter>
<plainas> it's not about threads being green... or threading. Crystal channels can be used like a semaphore. I don' even know how I would to that with async await... I asked a few js people I work with and the answer is always: "why would you need to do that"
<dom96>
Also, for something that adds extra complexity (concurrency) you do want two distinct categories of functions.
<FromGitter>
<plainas> spawn() + aquire() and relead() it's all i need really. And its trivial to use.
<dom96>
JS people heh
<dom96>
Please don't mistake JS' async with Nim's
<FromGitter>
<plainas> dom96. I disagree... *what* I want to do, does not depend on how I want to pararelize it
<FromGitter>
<girng> please @straight-shoota can u help me
<poopBot>
i really like sytax i just looked you page first time and reading code was almost like reading Engish , that ruby stuff is nice , duno how i newer saw it
<FromGitter>
<straight-shoota> with what?
That_Guy_Anon has joined #crystal-lang
<dom96>
plainas: Out of curiosity, what types of apps are you writing?
<FromGitter>
<girng> @straight-shoota im using this code ` property selected_characterid = Int64 ` but it won't work, but if i do ` property selected_characterid = Int32` it does. if I use the `Int64` I get `of Client must be Int64:Class, not Int64`
<RX14>
dom96, having control over when you threads yield is moot as soon as you gain parallelism
<FromGitter>
<straight-shoota> @girng are you sure you want to assign a type to that property?
<FromGitter>
<straight-shoota> you probably mean `property selected_characterid : Int64`?
<RX14>
in JS, async/await has some benefit because you have 1 thread executing 1 event loop
<RX14>
in crystal we'll have multiple threads - you inherently have no control over your execution timing
<dom96>
RX14: Perhaps, I don't really get the argument of controlling how many things are happening at once with concurrency
<dom96>
You only ever have one thing happening at a time
<RX14>
in crystal you can spawn n times and you know only n things are happening at once
<FromGitter>
<girng> @straight-shoota but, what is the difference between ` = Int32 ` and ` : Int64`? why does Int32 work but Int64 doens't (when using the `=` operator)??
<dom96>
It's the same in Nim. 1 thread = 1 event loop. You can create more threads with more event loops.
<RX14>
but thats not how crystal will work
<RX14>
it'll be like go
<dom96>
It's not like async await is performing parallelism
<FromGitter>
<straight-shoota> I don't know why Int32 didn't raise any issue
<FromGitter>
<straight-shoota> would need to seem some context for that
<RX14>
dom96, fibers will move transparently between threads
<FromGitter>
<straight-shoota> `=` assigns the right hand side value to the variable,
<RX14>
the only point to async/await is being able to see which parts of code you can ignore locking in
<FromGitter>
<plainas> I am not talking about lower level details... I am talking about for example, read from many huge files at once. In crystal is trivial to do that for 1000 files but make sure that only 10 are open at a given time
<RX14>
if you can NEVER ignore locking
<RX14>
then there's no point
<FromGitter>
<straight-shoota> `:` restricts the type of value that can be assigned
<dom96>
plainas: it's the same in Nim
<RX14>
besides, you almost always want synchronous procedural code to be the default
<RX14>
because it's what you're used to
<FromGitter>
<plainas> Can you show me a snippet? I wanted to do this, turned to nim, couldn't find an easy way to dot, red crystal manual, had a working solution in the same day
<RX14>
in async/await you force people to write code differently depending on if it supports asyncio or not
<RX14>
in crystal it's automatic and it makes a huge difference
<RX14>
no more having to choose between making your interface simple and making it high performance
<RX14>
you can't "forget" to make anything async
<dom96>
plainas: do you have an example in Crystal that I could translate? Might be easier than me coming up with some guessed example :)
<dom96>
Plus I solve the code duplication issue rather nicely with a multisync macro
<FromGitter>
<plainas> worker1(), you can throw anything you want where that sleep(0) is
<RX14>
dom96, or just solve it at the root with evented CSP :P
<RX14>
nothing else makes sense to me
<FromGitter>
<girng> @straight-shoota big misunderstanding, i got my = and : mixed up. thank you
<RX14>
as nodejs has shown - evented IO has a far more significant effect on performance than runtime speed itself
<FromGitter>
<plainas> Frankly I never understood why would anyone want anything else than P() and V() idiom as defined by Dijskstra.
<RX14>
making it easy to use that evented IO is what will make your language fast in the real world
<RX14>
with real people who don't want to think about event loops
<FromGitter>
<plainas> I totally agree.
<dom96>
To be honest I also wonder this :P
<RX14>
as soon as you make evented IO harder than normal IO - and provide the option to use sync IO - someone will get lazy and use it and your performance is down the drain
<RX14>
and you'll waste time debugging it
<dom96>
I still love my async await implementation though
<FromGitter>
<plainas> you want to be able to throw your IO to the background. But the webserver case was trivial, because you paralelize everything, what If I want to process 10.000 files, I want control over how many I want open at a given time. Not just open as many as possible. It will crash
<dom96>
And it's encouraging to see Rust going the same way
<RX14>
rust has to do it that way because of not having a runtime
<RX14>
as soon as you allow yourself a runtime then CSP is far better
<RX14>
i'm actually pretty sad rust is adding async/await
<dom96>
FWIW it's trivial to create sync and async code in Nim without any code duplication
<dom96>
You just mark your proc with {.multisync.}
<RX14>
that's nice but I still think async/await and multisync are a hack around getting the core of the colution wrong
<RX14>
and as we've discussed there's still some problems
heaven31415 has joined #crystal-lang
qard has joined #crystal-lang
<FromGitter>
<girng> can i ask a question about multiple processes
<poopBot>
i allow you
<poopBot>
ask
<heaven31415>
hi
<FromGitter>
<girng> for example,in nodejs people sometimes run multiple nodejs "instances" that interact with redis or something to horizontally scale. the same thing can be done with crystal, right?
<RX14>
yes
<FromGitter>
<girng> cool =], tyhx
duane has quit [Ping timeout: 260 seconds]
duane has joined #crystal-lang
<FromGitter>
<girng> where can i find benchmarks comparing crystal to nodejs?
<FromGitter>
<girng> @ryankshah cool, which one would be the most fairest / real?
<FromGitter>
<ryankshah> Depends what you need to be fair
<FromGitter>
<girng> somemthing useful in game dev world maybe
<FromGitter>
<girng> networking test?
<FromGitter>
<ryankshah> hmm
<FromGitter>
<ryankshah> do a quick google
<FromGitter>
<ryankshah> or do your own benchmark
alex`` has quit [Ping timeout: 276 seconds]
<FromGitter>
<girng> i'm too newb and will prob create a bad benchmark :(
<FromGitter>
<ezrast> Spoiler alert, most benchmarks are bad
<FromGitter>
<ezrast> At least if "good" means "relevant to the work you are actually doing"
<FromGitter>
<ezrast> what are you actually trying to prove?
<FromGitter>
<ryankshah> I agree with @ezrast
<FromGitter>
<ryankshah> I would only take them with a pinch of salt to get approximations towards what you want to achieve
<FromGitter>
<girng> what do you mean what am i trying to prove
<FromGitter>
<ezrast> what decision are you trying to use a benchmark to inform?
<FromGitter>
<ezrast> why do you care how Crystal compares to Node at X task?
<FromGitter>
<girng> @ezrast got it, well, i was just trying how big the performance difference is compared to nodejs and crystal for game dev stuff
<FromGitter>
<girng> in, like networking maybe
tilpner has quit [Remote host closed the connection]
tilpner has joined #crystal-lang
shalmezad has quit [Quit: This computer has gone to sleep]
tilpner_ has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
tilpner has quit [Ping timeout: 240 seconds]
tilpner_ is now known as tilpner
shalmezad has joined #crystal-lang
Jenz has quit [Ping timeout: 268 seconds]
<heaven31415>
Where can I find the definition of epsilon for float32 in Crystal? By epsilon I mean: the difference between 1 and the least value greater than 1 that is representable in the given floating point type
duane has quit [Ping timeout: 260 seconds]
qard has joined #crystal-lang
duane has joined #crystal-lang
alex`` has joined #crystal-lang
Jenz has joined #crystal-lang
greengriminal has joined #crystal-lang
Jenz has quit [Quit: leaving]
<RX14>
probably isn't one
<RX14>
yeah nah
<RX14>
you'll have to define it yourself
<RX14>
you should open an issue
heaven31415 has quit [Ping timeout: 276 seconds]
heaven31415 has joined #crystal-lang
<FromGitter>
<straight-shoota> I can't think straight... can this expression be simplified? `((i - (i > 0 ? 1 : 0)) / 3) * 3` ⏎ https://carc.in/#/r/3tjq
<FromGitter>
<straight-shoota> I don't care about the value for 0, it can be undefined
That_Guy_Anon has quit [Remote host closed the connection]
<crystal-gh>
[crystal] paulcsmith opened pull request #5918: Small typo fix in bash completion (master...patch-1) https://git.io/vxMy9
Jenz has joined #crystal-lang
Jenz has quit [Client Quit]
Jenz has joined #crystal-lang
<heaven31415>
can I use uninitialized keyword for instance variables in constructor?
<Jenz>
Yes
<Jenz>
I think so at least...
<Jenz>
Lemme double check
<heaven31415>
Well I already tested code with it
<heaven31415>
however was surprised to see that those variables were initialized to zero
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
<Jenz>
What type were they?
<heaven31415>
Float32
<Jenz>
If they were ints, an uninitialized int has the value of zero
<Jenz>
Not so sure about floats though
greengriminal has quit [Client Quit]
<Jenz>
Could be same thing
<Jenz>
Must be
<heaven31415>
I think you are right
<heaven31415>
maybe is it handled differenly for types not inheriting from value
<Jenz>
But I don't see any point in uninitializing floats, initially just declaring them as zero is much easier than typing 'uninitialized'
<Jenz>
unitialized floats*
<Jenz>
I think the point about uninitialized is that they are not handled at all
<heaven31415>
Well I'm porting some C++ code and it had uninitialized floats for performance reasons
<FromGitter>
<straight-shoota> an uninitialized variable has whatever value is at that memory position
<Jenz>
But im just a noob, RX14 isthe expert
<Jenz>
Yes and memory positions are 0 by default
<RX14>
don't use uninitialized
<RX14>
just don't
<RX14>
ever
<RX14>
you won't notice the performance, ever
<Jenz>
You're quite some low-level opposer :D
<Jenz>
You're pretty much required to use it in some c binding situations though
<RX14>
yes because most of the time it's a premature optimization that'll cause you security bugs
<RX14>
yeah
<RX14>
uninitialized is there for C bindings and for people who have actually benchmarked the code and can tell me exactly HOW MUCH faster uninitialized is than without
<RX14>
most of the time people use it to shoot themselves in the foot
<RX14>
so please, don't do it
<Jenz>
You're not able to bind to things declared in c with `define` are you? I say 'things' because I've no idea what its called
<RX14>
you mean macros?
<heaven31415>
I promise I won't shoot myself in the foot
<RX14>
#define?
<Jenz>
Yes
<RX14>
heaven31415, you will, don't use it
<heaven31415>
I meant that I won't use uninit
<RX14>
nice
<RX14>
90% of the time LLVM will just optimise it to the same code with or without uninitialized either way
<heaven31415>
and what about those 10% XD?
<RX14>
either using it as an ivar
<RX14>
or complex situations where llvm can't prove you didn't use the memory before it was initialized
<RX14>
and half of the latter is because of bugs
<Jenz>
Sounds problematic
<RX14>
not really
<RX14>
all you're doing is eliding a memset if you're using uninitialized on scalars
<RX14>
s/eliding/removing
<RX14>
and most of the time llvm will elide that memset and remove it in release mode
<Jenz>
elide?
<RX14>
Jenz, elide means the compiler will remove it because it can prove it's unneccesary
<Jenz>
Ok, i see
<heaven31415>
RX14
<Jenz>
And the answer to binding to macros was no?
<heaven31415>
I would like to ask about inlining, if I'm porting some code to Crystal from C++ and I see inlining suggestion in C++ code, should I also use always inline attribute in Crystal code?
<Jenz>
(c macros)
<RX14>
heaven31415, @[AlwaysInline]
greengriminal has joined #crystal-lang
<heaven31415>
so, it will be different from cpp inline
<FromGitter>
<ryankshah> @RX14 technically you used elide in the wrong context, it only refers to omission when speaking otherwise it refers to joining/merging something
<FromGitter>
<ryankshah> But we're programmers, who gives a crap
<Jenz>
Google says otherwise 'omit (a sound or syllable) when speaking,' I mean, speaking, compiling, same shit
<FromGitter>
<ryankshah> Jenz, that refers to a sound or syllable from a word or phrase, i.e. the consonant 'k' is elided from 'knight'
<Jenz>
Oh, really? /s
<FromGitter>
<ryankshah> Yeah 😆
heaven31415 has quit [Ping timeout: 260 seconds]
<RX14>
@ryankshah but everyone uses elide to mean the removal of something in a compiler
<FromGitter>
<ryankshah> Ahhh okay that's fair then :)
<FromGitter>
<ryankshah> It's not a very common word hence my misconception of its use in compiler vocabulary
<Jenz>
Would it be irrational to make it possible to bind to c macros?
heaven31415 has joined #crystal-lang
heaven31415 has quit [Client Quit]
<FromGitter>
<straight-shoota> C macros only exist in the C source but not in the compiled library
<FromGitter>
<straight-shoota> you need to translate to Crystal
<Jenz>
Oh ok, thanks, im a noob in c as well
havenwood has joined #crystal-lang
<havenwood>
Someone should change the title links to https since they all support it. :-)
<FromGitter>
<bew> Yes, but his short form has 7 digits, which might not always be enough
poopBot has quit [Remote host closed the connection]
<oprypin>
git rev-parse --short HEAD is better, and i have it set to more digits :)
<oprypin>
core.abbrev=9
<havenwood>
oprypin: ah, nice
<oprypin>
what @bew is trying to say is that it automatically adds more digits if it's necessary
<havenwood>
aha, interesting
Jenz has quit [Ping timeout: 265 seconds]
<FromGitter>
<bew> Yes, ty for clarifying :)
heaven31415 has joined #crystal-lang
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<heaven31415>
hello
shalmezad has quit [Quit: Timezones are the bane of my existence.]
duane has quit [Ping timeout: 276 seconds]
qard has joined #crystal-lang
alex`` has quit [Quit: WeeChat 2.1]
<FromGitter>
<ryankshah> I have a class that I created, which I thought would inherit from Object. I tried calling `#clone` from my class object i created and it says it is undefined
<FromGitter>
<ryankshah> Do I have to do `MyClass < Object`?
<FromGitter>
<straight-shoota> no
<FromGitter>
<straight-shoota> `Object#clone` is not defined
<FromGitter>
<bew> Checkout `def_clone`
<FromGitter>
<straight-shoota> you're probably looking for `Object#dup`
<FromGitter>
<ryankshah> I thought `#dup` points to the same memory reference and doesnt actually create a new object?
<FromGitter>
<bew> FWIW, def_clone a macro to easily create the clone method