#ruby - 10 June 2017
« Back 1 day Forward 1 day »
[00:11:46] RubyLearner: Is "raising an exception" the same as "creating an object of one of Exception descendants" ? If not, how exactly is it different?
[00:14:53] centrx: rubyLearner: raising an exception is actually activating it, causing the program to terminate unless the exception is caught by a rescue
[00:18:30] RubyLearner: centrx when you say “exception is caught by a rescue” do you mean “the exception object is caught by a rescue”? I would like to understand the underlying mechanics of it, in a more concrete, less abstract way. The idea of “exception” is always so abstract, I'd like to know what actually happens.
[00:24:53] centrx: rubyLearner: It's not particularly unique to Ruby, so you could look up how it's done in a more basic learning programming language
[01:07:23] RubyLearner: centrx is this correct to say? → “If the program commits a transgression, ruby saves an Exception object at $!”
[01:09:19] RubyLearner: centrx mm ok... is this process that I described a description of “raising an exception”? is it the “raising of the exception” the creation of that object and its saving in $! ?
[01:09:57] elomatreb: raise first instantiates the class you give it, and saves where it occurs. It then goes up the method call stack to find a matching rescue block, if it reaches the top without finding one your program exist and prints a stack trace
[01:14:00] elomatreb: I.e. there is little special about the Error/Exception object itself, it's only used to indicate what error occured and where
[01:14:44] RubyLearner: elomatreb: but what if I call raise and there's already an exception in $! ?
[01:15:28] elomatreb: I think if you call `raise` without an argument it defaults to re-raise what's in $!, otherwise it will override it
[01:32:56] ruby[bot]: al2o3-cr: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `' for nil:NilClass
[01:34:55] ruby[bot]: al2o3-cr: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `' for nil:NilClass
[03:27:29] jellycode: Hi there. Does anybody know ruby and another language (C#, Java, or JS) well enough to port this encryption class from Travis CI to any other language? https://github.com/travis-ci/travis.rb/blob/dc6d47614d630fecf8220d4df78f5c747a6d9680/lib/travis/client/repository.rb
[03:28:52] jellycode: The issue is that in order to encrypt a string for travis, one has to install ruby language, then install the travis client gem, and then they can encrypt the string. It feels like an excessive dependency chain for something so simple.
[03:30:05] jellycode: There's no magic with encryption like this, it's just hard for someone who doesn't do ruby.
[03:30:16] jellycode: The encryption is actually done in this class: https://github.com/travis-ci/travis.rb/blob/dc6d47614d630fecf8220d4df78f5c747a6d9680/lib/travis/tools/ssl_key.rb
[04:48:22] htb: Hi all, I am trying to install some ruby app (http://orgmode.org/worg/blorgit.html); I used rvm to setup an isolated environment and I am getting errors running rake: I get a "LoadError: cannot load such file -- blorgit" when running rake new (as per the instructions) and I get another error when adding -I (Mustermann::CompileError: regular expression should not contain ^: "^\\/.search"). Could anyone give me pointers to debug this?
[04:53:52] zenspider: htb: so... that project hasn't had a commit in 5 years. some stuff has changed in that time.
[04:54:13] zenspider: it is expecting the load path to have "." in it, which it doesn't by default anymore
[04:54:32] zenspider: that's why it isn't finding the file... also, it doesn't have proper project directory structure set up, which is odd
[04:55:04] zenspider: also, it seems to be flat out MISSING files: LoadError: cannot load such file -- /Users/ryan/xxx/blorgit/backend/active_file/init.rb
[04:57:35] htb: when I do 'rake -I . new' from the root blorgit folder, I get the Mustermann regexp error. Did you get past that already?
[05:01:14] zenspider: I think what you're seeing is shitty dependency management. this hasn't changed in 5 years, but the other projects have.
[05:01:29] zenspider: and since the instructions just say "install this shit willy nilly" you wind up with the latest versions
[05:03:50] htb: if the software doesn't look good (or too obsolete), I'll look for something else, thanks for the help anyway
[05:06:36] htb: thanks a lot that gets me through the first step. I am not sure what I disabled there, I am illeterate in ruby
[05:07:39] zenspider: they don't want you to have "^" in the regexp anymore. the blog software is ancient so it hasn't been updated
[05:07:59] zenspider: you could for the project and send a PR back to the author, but I doubt they'd bother. maybe file an issue asking about it
[05:10:23] htb: the get/post anchors is what i don't understand I think (I guess it responses to http requests). I'll play with it for a while, see if I can get it to a working state.
[07:33:18] symm-: irb causes a strange increase in power usage... all the more strange since cpu usage stays negligible
[08:35:09] prubini87: Can anyobody enlighten me, please? I need to manage 2 processes running at the same time in a console window, one is a socket connection (read/write) and the other is the user input/output. Does anyone have a tip or, very so much better an example of how to go about hangling this??
[11:07:57] James123: Any ideas on how to replace a character in an string only if it doesn't occur at the beginning of it?
[11:44:35] zenspider: James123: do the simplest thing that could possibly work. exactly what you described. nothing more.
[20:04:55] apeiros: some corrections: there are no assumptions. exceptions are raised when something is wrong
[20:05:28] apeiros: (of course, as all other code too, the code which detects a case where an exception is raised can have a bug)
[20:06:22] apeiros: calling a method creates a stack. i.e. foo calls bar calls baz -> your stack is foo > bar > baz. exceptions unwind this stack until it finds a wrapping begin/rescue
[20:06:56] apeiros: the ultimate begin/rescue is rubys interpreter itself, which will cause the application to exit with the error message you usually see in case of "unhandled" exceptions
[20:07:42] apeiros: also, raise can create an exception object, but it doesn't have to. you can pass an exception object directly: raise MyExceptionClass.new("message")
[20:08:55] RubyLearner: apeiros: is the “method stack” that you say the same thing as the backtrace that is saved in the Exception object?
[20:14:39] RubyLearner: mmm ok, so the interpreter will search the backtrace saved in the Exception object for a rescue clause
[20:15:50] RubyLearner: The backtrace tells the interpreter where to go? Or do they just happen to hold the same stack trace?
[20:17:12] apeiros: I'm actually not entirely sure about the details. but I think the thing in the exception is a copy of the actual thing used.
[20:17:15] matthewd: Somewhere in between. Do you have any other-language experience we might help you compare/contrast?
[20:17:58] apeiros: since the actual thing is "live", when the stack is being unwinded, it changes. so the exception would no longer accurately depict the origin if didn't copy before unwind.
[20:18:14] matthewd: Yeah, the exception's backtrace is a representation of the VM's actual call stack state at the time the exception occurred
[20:18:39] bawsky: Got a problem involving the need for non-blocking requests... Can someone help? Details in a sec
[20:18:42] apeiros: also the actual thing might contain more/different information related to implementation details of the VM
[20:18:58] matthewd: Most notably, the exception's backtrace is mutable.. your power to mutate the real stack is somewhat more limited :)
[20:20:07] matthewd: rubyLearner: Consider that the VM is always tracking where you called from, because even absent an exception, it has to go back there when you return
[20:20:08] apeiros: I've been bitten too often by well-intended libraries which tried to "tidy up" the backtrace and in turn made my bugsearch multiple times more annoying.
[20:21:21] matthewd: apeiros: I'm pretty torn.. a nontrivial library can leave the backtrace awful to read for "normal" use -- but if you do need to care about parts it's hiding, yeah, not fun
[20:22:31] apeiros: like "Exception foo in bar\n[POSTPROCESSED BACKTRACE, ORIGINAL IN $!.original_backtrace]\n…tidied backtrace…"
[20:24:07] RubyLearner: I'm still trying to wrap my mind around what you guys wrote... thanks, I'm starting to get a few internal eurekas in my mind... How did you guys learn this? Do you suggest some resource where I can learn Ruby in this level of detail? Because the abstraction kinda puzzles me too much, I only feel clarified when I actually see it happening in my mind
[20:24:59] bawsky: I am maintaining an app in which users may have a MMR (aka a number defining his ability in a game) and may invite/be invited to teams ONLY if they are not much higher than the highest MMR on team or much lower than the lowest.
[20:24:59] bawsky: The problem is that I get the MMR value from an external API and the value may change at any time (therefore storing locally is not reliable).
[20:25:00] bawsky: The external API used to support batch calls (I send a bunch of player ids, get their MMRs and bam I'm set). The problem is that it does not support batch calls anymore and now I am kinda lost about my options...
[20:25:49] bawsky: I am referring specifically to League of Legend's API - it used to support batch calls on v2, but v2 is going to be deprecated (and with that, batch calls)
[20:26:13] apeiros: rubyLearner: I already had a good understanding of the callstack when I learned my first lang with exceptions, so the way they work seemed natural to me. somewhat "the way I'd have done it"
[20:26:37] matthewd: rubyLearner: I personally prefer to learn one abstraction layer at a time -- accept that "and then it just does stuff", then return later to try to understand how that part works in turn [where it'll be building on yet another abstraction, etc]
[20:26:46] apeiros: and to understand the callstack - well, I had years of time. I started around age 8 ;-) no idea when what understanding formed in my mind.
[20:28:44] RubyLearner: matthewd: I like that suggestion a lot.. .I might be too stubborn.. because I'm reading a ruby book and whenever I don't fully understand something, I start googling for ages, it takes too much time. I would love to find a book or webite that just told me everything haha.
[20:29:05] apeiros: you can also ease the burden by querying only the strongest and weakest few players of the team
[20:29:38] elomatreb: I found it helpful to understand the need for exceptions, look at languages like C where you have to carefully check for special error return codes all the time
[20:29:54] RubyLearner: apeiros: wow, you started early.. I wish I was that smart to get into programming at an early age.. it's a fascinating universe
[20:30:28] elomatreb: Then you can see Exceptions are a formalization of that mechanic that is designed to keep you from confusing an error value with an actual return code
[20:30:47] matthewd: rubyLearner: I'd like to confidently say "horses for courses, go with whatever learning style feels like it suits you"... but I worry that there's always another abstraction layer, and then another -- you have to stop at some point, or you'll end up learning subatomic physics instead of programming ;)
[20:31:03] apeiros: elomatreb: eh, there's a point in that. the issue is, it's a kind of "if you have that other additional knowledge, you'll understand this additional knowledge" :D
[20:31:32] apeiros: but it's a good point and I think it becomes stronger with "revisit things you learned once you have alternative perspectives"
[20:31:35] prubini87: Does anyone know a good-for-dummies, concise tutorial on concurrency? Something not overcomplicated, for a starter hehehe :S
[20:32:20] elomatreb: apeiros: I like learning/understanding by understanding the history/reasons for creation of something
[20:32:25] RubyLearner: matthewd yeah, it's definitely a trap I fall into all the time... you feel this urge to “get it”, but it's like water, it seems haha
[20:33:11] apeiros: you suddenly have to question things you took for granted, or always thought "wow that sucks" and suddenly understood, why it was not improved.
[20:34:21] apeiros: rubyLearner: ok. I think elomatreb's advice is something you should remember for later then. it's a good idea to learn more than one language. it helps understand why the other language works the way it works :)
[20:34:35] bawsky: apeiros: I'm looking at client side being the first option - and then sending the data to the backend to do the dirty job (a problem is that a player may have up to two different MMRs and I still need to grab the highest; we even have a class for treating that case...)
[20:35:00] RubyLearner: also, I have this urge to write everything I study, I use this great tool called Workflowy for that... I definitely solidifies the knowledge, but it also is a trap, it sucks a lot of time
[20:35:39] bawsky: alternatively, I guess I'll probably do it serverside anyway and use the "too old or not" approach.
[20:36:23] matthewd: rubyLearner: To that end, I'd say your approximation is pretty well close enough... I'd just refine it to note that the backtrace is a *representation* of the call stack. So it's not technically the thing that's driving the unwinding (looking for rescue clauses), but the distinction is unlikely to matter.
[20:48:29] RubyLearner: thanks a lot guys.. tremendously helpful.. for those of you who like to write and take notes on stuff you study, I'd really recommend this tool “Workflowy”.. it's a pretty awesome outliner I've been using for years to try to organize my brain.. helps a lot to memorize stuff :)
[20:54:13] nesoi: I have some old code that uses Time.parse, that worked on an old system but isn't working. Could someone take a look and perhaps offer a hint? https://gist.github.com/anonymous/4d311c1351dca51cc61fbdc83a2b0f86
[20:56:57] nesoi: right I know it's originally a Time, but in the DB it's a varchar and is human-readable as time
[20:57:04] apeiros: it worked because it converted your Time to a String and parsed that String converting it back to the Time it was before. hurray for useless waste of CPU cycles :)
[21:00:02] nesoi: I'm not specifying the activerecord version. actually r came from an api call, not a db. and the API has changed so the format could have changed… nevermind, I'm unprepared and need to research it more. thanks for the hints!