<FromGitter>
<jmoriau> they don't show up in the search though
<FromGitter>
<jmoriau> but they're there that's all that matters :D!
<jhass>
yes, nothing non-type does yet
<jhass>
(so methods or constants do not either)
<FromGitter>
<jmoriau> ok thanks!
buggs1 is now known as buggs
ponga has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 276 seconds]
alsm has joined #crystal-lang
Raimondii has joined #crystal-lang
trapped has quit [Read error: Connection reset by peer]
trapped has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Oliphaunte has joined #crystal-lang
Raimondii is now known as Raimondi
<alsm>
Hey, if I have an instance variable (of a struct) in an abstract class, how do I address it to access/modify from a class that inherits from the abstract?
<alsm>
or am I doing it all wrong
<RX14>
alsm, you should just eb able to use @var like suual
<alsm>
compiler complains Error: instance variable '@fixed_header' was used before it was initialized in one of the 'initialize' methods, rendering it nilable
<RX14>
you might need to call super in the inheriting class?
<alsm>
I'd thought by declaring it and it's initial value inline in the abstract class it would be instantiated for every inheriting class
<alsm>
your suggestion worked, thanks
<RX14>
did it?
<RX14>
it's not for me
<RX14>
oh no
<RX14>
ignore me
<RX14>
yep
<RX14>
alsm, basically using @instance_var = x in the root of a class is sugar for doing the same in each constructor
<alsm>
ahh ok, makes sense
<RX14>
so you need super
<RX14>
it might be a little more complex than that but then i havent read the compiler source
pawnbox has quit [Remote host closed the connection]
<alsm>
moves me forward :)
ponga has quit []
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
Oliphaunte has quit [Remote host closed the connection]
<RX14>
at the very least random should have some sensible way to generate a load of random bytes
<FromGitter>
<sdogruyol> nice article
<RX14>
instead of just an integer
<RX14>
because i just want a damn random base64 string for multipart boudnaries
<jhass>
asterite: the question really is, is /dev/urandom fast enough. Let's face it, most people can't judge whether they need a CSPRNG or a regular PRNG is enough. So using a CSPRNG by default is the saner choice. If you actually know it's too slow for you, you're deep enough into the topic anyway
<RX14>
and writing my own 10 line method to get bytes from Random so I don't have to require secure_random just to use multipart is just shit
<jhass>
and know how to use a faster PRNG that might not be a CSPRNG
<jhass>
however having a CSPRNG by default can't do any harm
<RX14>
^
Oliphaunte has joined #crystal-lang
<RX14>
and 7MB/s on a celeron M singlecore laptop which was mid-range in 2005 is more than enough random for 99.99% of people
<FromGitter>
<sdogruyol> i get around 13.5 MB/s on OS X
<FromGitter>
<sdogruyol> i7 though
<jhass>
I mean it's still enough
<RX14>
how on earth
<jhass>
yeah, 2010 or 11 i7 here too
<RX14>
how on earth is your computer slower lol
<FromGitter>
<sdogruyol> lol yeah slower than a celeron
<jhass>
maybe I have more parallel consumers
<asterite>
I can't find the conversation, but in https://github.com/l3kn/raytracer-crystal the guy told me "Rust is slower... I don't know why, maybe the default random algorithm is slow"
<asterite>
So slow by default is not good. And you don't need a secure random for a raytracer, and I guess in games you don't either
<asterite>
like generating terrain
<RX14>
then they should use FastRandom
<RX14>
but the default should be secure
<RX14>
not insecure
<FromGitter>
<sdogruyol> i also think that default should be secure than being fast
<RX14>
there should be both
<FromGitter>
<sdogruyol> balanced*
<RX14>
but if fast is the default, the worst case is vunerabilities
<RX14>
if secure is the default, the worst case is slowness
<RX14>
which one is preferable?
<asterite>
So for example if you do [1, 2, 3, 4].sample, that should be secure or fast?
<RX14>
fast, but thats the stdlib so it can be modified to use FastRandom
<RX14>
in some cases you want that to be secure
<RX14>
but I believe that SecureRandom and Random should have the same interface at least
pawnbox has quit [Remote host closed the connection]
<RX14>
and I would strongly advocate that the default Random be secure
<RX14>
that's what ruby does, is it not?
<jhass>
sadly, it's not
<RX14>
ah
pawnbox has joined #crystal-lang
<jhass>
Ruby's SecureRandom/Random is a pretty sad story altogether
<RX14>
jhass, should HTTP::Multipart::Parser/Generator be structs?
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has joined #crystal-lang
<jhass>
I think as a general rule use structs unless you need the properties of a class
<jhass>
so the question, do they have mutable state?
<RX14>
no
<RX14>
well
<RX14>
yes
<RX14>
internally
<RX14>
they both use a finite state machine of sorts
<jhass>
then they have to classes, very likely
<jhass>
*to be
<RX14>
ah yes they do
<RX14>
had a brain fart
<FromGitter>
<GuneshRaj> Hi, Could anyone point me a way to declare an Array of a Hash?
qard has joined #crystal-lang
<FromGitter>
<GuneshRaj> eg. temp = [] of String => String
<jhass>
looks good
<FromGitter>
<GuneshRaj> ops, temp = {} of String => String
<FromGitter>
<GuneshRaj> temps = [] of Array( {} of String => String ) # this is an error.
<RX14>
yes you want Hash(String, String)
soveran has quit [Ping timeout: 264 seconds]
<jhass>
tmp = [] of Hash(String, String)
<RX14>
{} of String => String instantiates the hash
<jhass>
I wonder whether we should allow the first
<RX14>
Hash(String, String) is the type signature
<jhass>
could be confusing I guess
<RX14>
well {} of x to y is a special weird case anyway
<RX14>
I would have just told people to use Hash(x, y).new and skip that syntax
<jhass>
yeah we could even argue to drop the of stuff I guess
<RX14>
it's more confusing and just wacky really
<FromGitter>
<GuneshRaj> ok, Il try that.
<FromGitter>
<GuneshRaj> great, that works: thanks jhass
<FromGitter>
<GuneshRaj> Would it be better; performance wise to have an Array of a Struct or an Array of a Hash?
<FromGitter>
<GuneshRaj> Would Struct be created at heap and therefore faster ?
<jhass>
it depends.
<jhass>
an array of hashes is an array of references
<jhass>
an array of structs is an array of elements as big as the biggest struct
<jhass>
it depends on how often you create or destroy things, how big they are, how often you "get" an element out of the array onto the stack etc
<jhass>
in doubt, benchmark ;)
<jhass>
for your real usage that is, not some minimal thing you think reflects anything
<jhass>
benchmarking some pseudo array of hashes vs array of struct stuff here is quite useless
<FromGitter>
<GuneshRaj> Yes, I thought so, just wanted to know whats the best practice if both Hash (String, String) and A Struct with the same data / params are interchangeable, which would be better.
<jhass>
and there's no general answer to that
<RX14>
@GuneshRaj is this for a set, specific set of keys?
<FromGitter>
<GuneshRaj> yes. much like a struct.
<RX14>
if so, use a struct/record. Hashes should only really be used for actual "dictionary" uses in crystal, because their values can only have one type. The alternative is a record or named tuple, which can have different types for different keys.
<RX14>
only use a hash when you don't know the set of keys beforehand, although this is a rule meant tio be broken
<RX14>
but in general don't use hashes in exactly the same way they are used in ruby
<FromGitter>
<GuneshRaj> aha
<RX14>
aside from the performance issues, it breaks type checking
<FromGitter>
<GuneshRaj> I would rather declare a Hash of String => Types::Something
<FromGitter>
<GuneshRaj> Anyway, thanks, I am going to investigate :)
<RX14>
what exactly is the usecase? are the keys different types? if so, why would you prefer doing that?
paulcsmith_ has joined #crystal-lang
<FromGitter>
<GuneshRaj> I am experimenting with data structures and models, getting data from a table as a array of hashes where the values must conform to a specific sql type.
<FromGitter>
<GuneshRaj> I am finding alternatives in terms of performance (as well as best practices to follow)
<RX14>
the best way to do that is with an array of structs, see the crystal postgres gem
paulcsmith_ has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
paulcsmith_ has joined #crystal-lang
<crystal-gh>
[crystal] asterite pushed 3 new commits to master: https://git.io/vKkBu
<crystal-gh>
crystal/master a52faf2 Ary Borenszweig: Don't expand `require` before everything else. Related to #2710
<crystal-gh>
crystal/master bd01fb2 Ary Borenszweig: Replace all `ifdef x` in code with `{% if flag?(:x) %}`. Related to #2710
<crystal-gh>
crystal/master 104c9b9 Ary Borenszweig: Formatter: automatically convert `ifdef x` to `{% if flag?(:x) %}`. Related to #2710
trapped has quit [Read error: Connection reset by peer]
kulelu88 has quit [Ping timeout: 272 seconds]
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 260 seconds]
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: https://git.io/vKkEB
<crystal-gh>
crystal/master 993bda1 Ary Borenszweig: Fiber#run: use STDERR again, and give better error message
paulcsmith_ has quit [Quit: My Mac has gone to sleep. ZZZzzz…]