<johnjaye>
i don't understand what the answer is saying or why it works. it is ( fib(n-1) + fib(n-2) 0
<johnjaye>
er ). and the person asking was using arrays and combining them with +
<ox1eef_>
Nope does not bother me but not much free time, and almost bed time.
<johnjaye>
ok. i already solved the project euler thingie myself using a while loop
<johnjaye>
but i don't understand the () syntax there
<johnjaye>
is it making a hash or something. and why would that not cause a stackoverflow but the array combining does
<ox1eef_>
The surrounding parenthesis are unneccessary but basically, even (((puts("hi")))) is valid.
<johnjaye>
hrm. so if it's all using arrays why doesn't it stack overflow
<johnjaye>
unless it does
<ox1eef_>
Are we looking at the same code ? I don't see arrays but recursion.
<johnjaye>
i thought it was recursively making an array
<johnjaye>
as in it returns [0] or [1]
<johnjaye>
then starts building it up with +
<johnjaye>
hrm
<ox1eef_>
The third or so answer ? I don't believe that's more straight forward. The recursing examples are typical and easier to understand.
<ox1eef_>
Stick with the top answers. The rest is a bunch of bullshit.
<johnjaye>
is it just the return statement that makes it work?
<ox1eef_>
You gotta tell me what code you're working with. There's at least 5 variations in that post. The top answer is the typical solution for that problem.
<johnjaye>
i'm looking at the top post
<johnjaye>
but i don't see why it gives a SystemStackError
Vonter has quit [Ping timeout: 246 seconds]
<ox1eef_>
Because it will eventually reach 0 or 1.
<ox1eef_>
And then fall into the return.
<johnjaye>
hmm. so the first version will start computing fibonacci of -1, -2, etc forever?
<ox1eef_>
Right, does not handle negative numbers.
<johnjaye>
hmm. so it would work if it was [n] if n < 2 or something like this
<johnjaye>
let me see
<johnjaye>
hmm that still gives a stack error. so i guess ruby simply ignores the value since there is no return keyword
<ox1eef_>
The return statement stops the execution of the method, so it won't enter into another recursion.
<ox1eef_>
Without the return, you'd go back into recursion, and into negative digits, then overflow the stack.
<johnjaye>
ah and the return is not needed since implicitly ruby will return the last line of the statement
<johnjaye>
makes sense
<ox1eef_>
Right only explicit when you want a hard exit from a method, or for guards.
brw has quit [Read error: Connection reset by peer]
brw9 has joined #ruby
ruby[bot] has quit [Remote host closed the connection]
ruby[bot] has joined #ruby
Linux_Kerio has quit [Ping timeout: 252 seconds]
<adam12>
johnjaye: Yep. And I think they've diverged a bit, too.
<willfish>
has any rubyist here tried go?
<adam12>
willfish: Sure. It's "ok" from my POV.
<willfish>
have you used it in earnest or is this side projects and the like? I'm debating investing in learning it to improve my market options
<adam12>
I've shipped a bunch of servers and some CLI tools.
<willfish>
oh okay, that's in earnest
<adam12>
I don't reach for it first anymore, normally doing it in Ruby first.
<willfish>
I must admit I do love ruby
<adam12>
Last year I rewrote a daemon I wrote in Go into Ruby, because I spent ~ 3 days trying to work around a gomodules issue with no resolve. In another 3 days I had a better tested and more functional version in Ruby.
<adam12>
It will probably include your job opportunities. Or Rust, but Rust is a bigger beast to slay.
<willfish>
yeah, that's pretty awesome
<adam12>
Almost every project I am on involves a small Go portion to some degree. Usually remote agents performing some sort of action.
<adam12>
s/include/improve. I can't type tonight, apparently.
<willfish>
interesting
<willfish>
I'm going to commit to learning it properly and start building some experience in it
<adam12>
Two cloud platforms that involve a small Go binary for RPC actions (check load, etc). One of those I reverted back to Ruby (as mentioned above). And I wrote a restaurant order-ahead platform that used a Go microservice to spool to the kitchen printer when new orders came in.
<willfish>
It feels like a decent tool to have in my repertoire
<adam12>
It's a shame that Crystal didn't become more popular in this space. I can write Crystal without blinking because of it's proximity to Ruby.
<willfish>
nice :)
<adam12>
bbl. putting kids to bed.
<willfish>
Yeah, I loved the idea of crystal
<willfish>
I should go to bed. It was my daughters first birthday today and I am totally pooped
<willfish>
Its 11.44 at night here
reset has quit [Quit: reset]
graywolf has joined #ruby
willfish has quit [Ping timeout: 248 seconds]
graywolf has quit [Ping timeout: 250 seconds]
xuochi has joined #ruby
nmollerup has quit [Remote host closed the connection]