<Prep>
is the reason Hash#fetch does a raise "Missing hash value: #{key}" instead of returning a nil, due to the "we don't want null point exceptions" ?
<asterite>
There are many reasons
<asterite>
One reason is that fetch would always return something that also contains the Nil type
<asterite>
so you couldn't do: a = {1 => 2}; a.fetch(1) + 3
<asterite>
(undefined method '+' for Nil)
<asterite>
The other reason is that if you have nilable types as values in the Hash, you can't know if the returned value is nil or doesn't exist in the hash
<asterite>
The "we (almost) don't have null pointer exceptions" is just a consequence of having Nil as a separate type
<asterite>
and we always wonder if that's the best way to go (but so far it's been fine)
<Prep>
fair enough
<asterite>
You can always use a = {1 => 2}; a[1]? # returns the value or nil if not found
<Prep>
I guess I'm too fond of the: a = foo[:bar] || "zoink" syntax
<Prep>
but a = (foo[:bar] rescue "zoink") is not too bad
<Prep>
as for your first reason, Ruby has that same problem. I've always figured if you want to make sure, you just check if the variable is present before doing the call
<asterite>
you can do: a = foo[:bar]? || "zoink"
<asterite>
it's more efficient because there's no exception handling involved
<Prep>
hey! that's pretty nice :-)
<Prep>
I wasn't aware of that
<Prep>
def []?(key)
<Prep>
end
<Prep>
fetch(key, nil)
<asterite>
:)
<asterite>
Yes, it's an addition to Ruby's syntax
<Prep>
I like it! The rescue thingy was really bothering me
bcardiff has joined #crystal-lang
<Prep>
also, in the interest of keeping track of who's working on what, I'm working on a libarchive module for crystal
<waj>
nice! is it public already?
<Prep>
no, I just started working on it last night
<CraigBuchek>
So we should probably take a look at thetechnical issues he ran into and make sure they won't be an obstacle for Crystal.
<CraigBuchek>
That is, make sure we know how we plan to avoid those problems.
adkron has joined #crystal-lang
<adkron>
nil is bad
<asterite>
@adkron yes, it is
<asterite>
we can add it
<asterite>
nil.bad? #=> true
<asterite>
:)
<adkron>
sweet
<adkron>
I'm going to use this language all the time
<asterite>
@kostya yes, but we don't know what are the technical issues he ran into
<asterite>
@kostya we already discarded macros executed via jitting, because that doesn't work well when cross-compiling
<asterite>
@kostya another option is to use macros like rust, with quasiquoatations
<asterite>
quasiquotes, I mean
nekron has joined #crystal-lang
palla has joined #crystal-lang
asterite has joined #crystal-lang
waj has joined #crystal-lang
waj has joined #crystal-lang
asterite has joined #crystal-lang
<asterite>
@adkron why you say nil is bad?
<adkron>
nil does not tell you anything
<adkron>
when you ask a hash or an array for a value and it returns nil if the key isn't there or if someone added nil to the hash or array
<adkron>
That is one example
<CraigBuchek>
I love your distinction between a hash item that is nil, versus not finding the key.
<adkron>
When nil is passed around and around and suddenly you call a method on it and get a no method error
<adkron>
Now you have a fun time of trying to track where the magical nil originated
<adkron>
nil checks become littered all over the code
<adkron>
Reducing the readability and flow of what is important
<CraigBuchek>
adkron: Crystal doesn't allow that.
<CraigBuchek>
Crystal catches that at compile time, with static type analysis.
<asterite>
And we try to show you where the nil originated from, at compile-time (but there's still room for improvements)
<adkron>
awesome
<adkron>
I wasn't coming in to complain about the language. My nil spidey sense went off that someone was asking why Hash#fetch would return a key error and not nil
<asterite>
@adkron oh, but how did you read that? You wasn't in the channel before
<CraigBuchek>
I think that's a great thing. Although it is a slight violation of the "Only use exceptions for exceptional cases" principle.
<CraigBuchek>
I think it's worth violating that principle here.
<adkron>
asterite: spidey sense
<CraigBuchek>
Or perhaps a mole.
<adkron>
I don't find it use for exceptional cases
<adkron>
It only violates it if the case is trully not exceptional
<adkron>
If a developer creates a hash in a hard coded fashion, god forbid, and expects values to be there that would be exceptional
<asterite>
@adkron I'll have to install that program :-P
<adkron>
If the hash is created form user input, it would not be exceptional
<CraigBuchek>
In this case, the hash very well may be created by user input.
<adkron>
Now back to figuring out how to delete non-unique records from a db so that I can add a unique index.
<adkron>
then I believe Hash#fetch in crystal takes a block and you don't have to raise an exception. asterite, am I correct?
<asterite>
Yes, it can take a block or a value
<adkron>
Now the developer decides what is exceptional. Fantastic
<adkron>
I personally wish that the [] syntax acted as default fetch
<adkron>
That is what I would do if I was making my own language
<adkron>
asterite: I may have to use this language
<adkron>
asterite: I have a mole in your channel, CraigBuchek was correct
<CraigBuchek>
I'm going to give a talk on Crystal at the March STL Ruby meeting.
<adkron>
CraigBuchek: that is awesome. Did you know that I am one of the organizers of STL Ruby?
<CraigBuchek>
LOL
<adkron>
^^^ MOLE
<asterite>
If you'll give you a talk you can ask us about specific implementation details, if you need them
<asterite>
When is that STL meeting?
<CraigBuchek>
2nd Monday of March would be March 10.
mverzilli has joined #crystal-lang
<CraigBuchek>
I've been looking at Crystal, but haven't actually used it yet. I really like what I see so far. Scheduling a presentation will make sure I get to get my hands dirty and learn it.
<adkron>
asterite: although I know little about crystal. I do have the github page pulled up on my browser and haven't closed it in 4 days. Maybe I should actually dig in.
<asterite>
It's pretty simple to get it up and running
<CraigBuchek>
adkron would probably have to coordinate that. Maybe even a Google Hangout Live.
<asterite>
That would be nice. It's a bit difficult for us to join the meeting
<CraigBuchek>
Aw, c'mon. How far away from St. Louis MO could you possibly be? ;)
<asterite>
:)
<CraigBuchek>
Montevideo, Uruguay?
<asterite>
Almost!
<asterite>
We are in Buenos Aires, Argentina
<adkron>
We can work something out. I will leave it up to CraigBuchek
<adkron>
asterite: I want to come visit
<CraigBuchek>
asterite: That's what ARIN says your IP is.
<CraigBuchek>
asterite: What time zone are you in?
<CraigBuchek>
It's 10:37 AM here now.
<asterite>
GMT -3
<asterite>
Here it's 1:37 pm
<CraigBuchek>
Wow, how the heck can you be that far east of us?
<CraigBuchek>
Stupid American education system.
<asterite>
lol
caro__ has joined #crystal-lang
bcardiff has joined #crystal-lang
palla has joined #crystal-lang
asterite has joined #crystal-lang
asterite1 has joined #crystal-lang
asterite2 has joined #crystal-lang
asterite has joined #crystal-lang
irclogger___ has joined #crystal-lang
asterite1 has joined #crystal-lang
Liothen has joined #crystal-lang
broz has joined #crystal-lang
waj has joined #crystal-lang
asterite has joined #crystal-lang
asterite has joined #crystal-lang
asterite1 has joined #crystal-lang
asterite has joined #crystal-lang
asterite has joined #crystal-lang
asterite has joined #crystal-lang
broz has left #crystal-lang [#crystal-lang]
asterite has joined #crystal-lang
asterite has joined #crystal-lang
<filer>
daylight savings/summer time always makes it more confusing
<filer>
right now Chile is 2 hours ahead of the east coast of the US, but in our spring when we go ahead an hour, they go back an hour, so then they're the same time
<CraigBuchek>
Ah, I hadn't considered southern hemisphere daylight savings, only northern hemisphere.