#ruby - 19 September 2018
« Back 1 day Forward 1 day »
[00:30:11] Radar: Is there a shorter / cleaner way of doing the comparison in this code? https://gist.github.com/radar/f079875d0379600e9fc2446cb513ebf8
[00:30:32] Radar: I think asking answer to check an internal value (question) from a separate class is a smell, but I can't think of a shorter way to write rit.
[00:39:38] Radar: Here's a bigger file that I'm playing around in: https://gist.github.com/radar/26a95a7e9b6dfc2558af6e2b6dea27bd
[00:39:53] Radar: I like: answers.select(&for_question(question)).select(&:low?), but it does two loops through the questions
[00:40:09] Radar: If there was a way somehow to combine the functions and only make one loop it'd be better
[00:41:10] baweaver: I _could_ make it play nice with both hash and array matchers at once to do something more like this:
[01:10:24] havenwood: Radar: Interestingly, with your code example, the multiple iterations are faster than a single pass: https://gist.github.com/havenwood/e0ac0fec4b53143603b687530d818175
[01:13:53] havenwood: TruffleRuby is an order of magnitude faster overall, but single iteration clearly wins.
[01:32:29] havenwood: baweaver: I'm curious what numbers you get on TruffleRuby with that 6-core... :)
[01:33:59] baweaver: Xcode is good, brew is now unborked (mac clone works great for non ruby things)
[01:34:12] baweaver: "Make sure that `gem install ffi -v '1.9.23' --source 'https://rubygems.org/'` succeeds before bundling."
[02:13:33] baweaver: havenwood - https://gist.github.com/havenwood/a69ac7262062a20c7c24efc5950d9614#gistcomment-2710344
[02:18:10] al2o3-cr: i asked because if you not doing multiprocessing singular core will perform faster.
[07:54:02] TvL2386: hey guys, question about documentation of code: Since ruby always returns the result of the last evaluation in a method, something may be returned that the author didn't intend to or simply is not interested in. Should I then document what it returns, or should I document it returns nothing?
[07:54:40] TvL2386: I feel like I should change all my methods to return nil if I'm going to document that
[07:55:46] ZzZombo: Document the actual result type. Put `nil` as the last statement where necessary.
[07:57:38] ZzZombo: That's what I stick to. I always make sure the last expression produces the expected result, use explicit `return`, or put `nil` down at the end.
[08:08:33] ruby[bot]: old_relik: we in #ruby do not like pastebin.com, it loads slowly for most, has ads which are distracting and has terrible formatting. Please use https://gist.github.com
[08:40:09] ruby[bot]: masterasia: we in #ruby do not like pastebin.com, it loads slowly for most, has ads which are distracting and has terrible formatting. Please use https://gist.github.com
[08:40:47] apeiros: and yes, it's just as if you'd not closed the class and added that code at the end
[08:50:45] apeiros: I think it is documented somewhere. no idea where, though. Been a while since I learned that :D
[09:53:42] TvL2386: marz_d`ghostman: sounds cool! My next little rails project will also use mongodb (mostly for learning purposes)
[10:01:32] marz_d`ghostman: chichou_: I tried searching for one, it appears activerecord is the most popular
[10:11:33] chichouw: and I wasn't right either, it doesn't even extend activemodel but it's just a development dependency somehow
[11:34:12] nfk: i can't believe i spent like 4 hours yesterday debugging firefox csp, sinatra, rack-protection and my app when the cause was NoScript running in my firefox...
[11:47:19] donofrio: nfk, don't beat yourself up too much, next time "Private browsing" for your testing
[12:01:46] nfk: after all, i do about half of my googling in private or incognito just so that algorithm didn't start spamming me with lawnmover or lisp framework results
[12:02:44] alireza: How can I call `return order.total unless eligble?(order)` before children logic
[12:07:14] nfk: some easy things first: 1) it's good that you're using @percent to indicate that it's a percentage but if you're actually doing math on it, it's much safe to just keep it as a float and format it as a percentage only when shown in a human friendly manner
[12:09:03] nfk: that way if stuff goes sideways you'll end up with 0.2% discount where it should have been 20% instead of substacting 20, because someone forgot to do the conversion
[12:09:39] nfk: alireza, hey, you have to be careful with money, if you bill me €-5, i'll take them and the product, thank you
[12:10:59] alireza: so I can abstract out percentage logic outside or just provide a simple keyword argument which indicates that
[12:13:17] nfk: alireza, it's just a good practice, when it comes to money, to avoid using percentage as your internal representation
[12:14:24] alireza: but my question is how to call `return order.total unless eligible?(order)` in parent class
[12:15:43] nfk: alireza, and i'm sharing my opinion on how i'd avoid some pitfals, speaking of which, i would have order.base_total and order.total
[12:16:09] nfk: that way, again, if stuff goes sideways, you won't end up repeatedly applying the same discount
[12:18:04] alireza: but first I'm going to elminate `return order.total unless eligible?(order)` in children classes
[12:18:12] nfk: you'd likely also want to do all your discounts in one place (i.e. pass in order and some hash of all potentially applicable discounts)
[12:20:16] nfk: alireza, i think that if you redo your discounting to all happen in one place, then you won't have that issue in the first place but that's just me
[12:26:26] nfk: yeah, i see a lot of abstraction with very little code, which is why i called that code spaghetti
[12:27:13] nfk: alireza, my gut feeling without considering that spaghetti is that when you call super the self it's being called on is not what you think it is but that's just my first hunch
[13:30:33] BrainWork: hi. i know absolutely nothing about ruby, but i am a programmer with many years of experience in other languages such as php, C++, even assembler. What is a good resource as a 'crib note' to kickstart some starting knowledge in ruby please?
[13:30:50] BrainWork: i have no goal except to learn the basics of another language relatively quickly
[13:31:26] BrainWork: there's lots of documentation out there but much of it is either a dry reference manual or assumes beginner status
[13:45:03] nfk: i remember having quite a bit of fun with those when i started, though it was some online interpreter rather than a set of local files
[13:46:22] nfk: BrainWork, this might be of interest to you: https://news.ycombinator.com/item?id=9308684
[18:21:12] nfk: Oh, derp, I'm testing my webapp on both firefox and google chrome and i'm getting different colors!
[18:35:37] nfk: On one hand I feel like pursuing this rabbit but I know that color management is gonna be one hellish rabit hole. Especially on linux. After all, all my profiles (other than my mpv vo_gpu one) is set to a test profile with wacky colors - if anything was capable of picking them up, I'd immediately notice that
[19:44:21] AndreYuhai: Hi, how can we test stuff on Travis which requires username and password? Any sources?
[19:47:07] havenwood: AndreYuhai: https://docs.travis-ci.com/user/environment-variables/#defining-encrypted-variables-in-travisyml
[20:09:37] Dirak: Hi, I'm a JS dev, and I need to learn Ruby for a company I'm interviewing with. What are the legit resources for learning Ruby on the level of 'you don't know js' and 'eloquent js'
[20:17:35] oz: Dirak: there's a nice list or learning material at https://www.ruby-lang.org/en/documentation/
[20:23:55] Dirak: My friend told me Ruby is a way of thinking and a philosophy so I need my reading material to redpill me
[20:25:30] nfk: and oz already linked you with pretty much the stuff everyone learns from (obviously from the ones that fit their taste)
[20:26:32] nfk: as for the ones you listed, i have no idea about their teaching style as i learned js the hard way - by writing application code before the days of node
[20:27:33] nfk: ecmascript as a language is so simple that i'm always baffled by people who need to learn it
[20:29:09] Dirak: like that the max int is 2^58. And that callbacks take the form (err, data) as their signature
[20:31:24] nfk: also i was under impression that 58 usable bits for memory addresses on 64 bit arches was an implementation approach rather than a language feature
[20:31:27] Dirak: I have a friend who works at an ecommerce company. Every million transactions or so, their company magically lose a penny cuz of JS's Number imprecision. They call it the JS tax
[20:44:24] nfk: actually, how would they end up losing money? it was a bit less than I thought - just mere 2.8e17 but that's seems to be enough to track the world's economy at a fraction of penny/cent precision
[21:34:29] ruby[bot]: +bb nine_milli_!*@*$#ruby-banned *!*@c-76-23-234-152.hsd1.ct.comcast.net$#ruby-banned
[21:40:16] nfk: if you meant nil?, then... you might be able to not have one if you essentially uprooted or replaced the entire runtime
[21:45:16] nfk: Dirak, oh, i just realised i automatically removed the ? from .nil because you were asking a question, sorry
[21:56:49] nfk: my gut feeling is that it just might be to avoid a circular definition, because object_id has to return an object?
[22:03:01] nfk: Dirak, anyway, my bad, << is the bitwise operator, and it's also doing the same job in ruby: a = 1; puts a; a <<= 2; puts a
[22:03:39] nfk: what you might be confused about is the fact that it's just a method (just like in C++), which means that you can define your own /, + and, yes, <<
[22:33:21] hays_: anyone who uses rubocop--is it fair to say that driving the number of "offenses" to zero is not usually practicable
[22:33:51] hays_: I'm finding some cases where.. it doesn't make sense to make the method shorter, or ABC complexity makes sense
[22:55:31] marz_d`ghostman: I'm using dispatch and I have these lines: autocmd FileType ruby let b:dispatch = 'rspec %' nnoremap <F9> :Dispatch!<CR> but I'm getting an erorr: || make: *** No targets specified and no makefile found. Stop.
[23:19:52] hays_: baweaver: it seems basically impossible to use optparse in a way that won't violate a rubocop rule