15 ms·
Ruby 2.6
- maxfurman 8y agoI am always happy to unwrap my Christmas present from the Ruby team! Some questions about this release: - Are there any benchmarks for the new JIT? - Why was `(Date.today..(Date.today + 1)) === DateTime.now #=> true` false in Ruby 2.5? It seems correct that right now is between today and tomorrow. Is it because one is a Date and the other a DateTime?
- koolba 8y agoBeen a while since I’ve used any Ruby but isn’t the first expression a range where’s the second a single value? It’d be like [0,1] === 0
- chrisseaton 8y ago> isn’t the first expression a range where’s the second a single value? `===` conventionally means 'matches', or 'includes', so an aggregate on the LHS and a scalar on the RHS is typical. It isn't defined for `Array` beyond being the default of equality - I don't know why - but it is defined for `Range`.
- anamexis 8y agoAbout your question, the reason is that `===` is aliased to `Range#include?` which checks if the argument is a discrete element contained in the range. That range of `Date`s does not include any `DateTime`s, so the inclusion check returns false. `Range#cover?` on the other hand, just uses >= and <= to check .
- ciconia 8y ago> Are there any benchmarks for the new JIT? From the horse's mouth: "...apparently JIT on Ruby 2.6 failed to be ready for production." [1] [1] https://medium.com/@k0kubun/ruby-2-6-jit-progress-and-future-84e0a830ecbf https://medium.com/@k0kubun/ruby-2-6-jit-progress-and-future...
- Rafert 8y agoBenchmarks here: https://medium.com/@k0kubun/ruby-2-6-jit-progress-and-future-84e0a830ecbf https://medium.com/@k0kubun/ruby-2-6-jit-progress-and-future... tl;dr: your Rails app is not faster with this feature in this version, but might be in the future.
- Koshkin 8y ago> (Date.today..(Date.today + 1)) === DateTime.now #=> true It took me a minute to parse this. (I have never had this problem with Python or JS.)
- maxfurman 8y agoSorry - this is pasted out of the article, and refers to a change in the semantics of the === operator for Ranges.
- yxhuvud 8y agoNote that you would almost never use the === directly - usually it is done by invoking a case statement, so it would be like case DateTime.now when Date.today..(Date.today + 1) .. do something else .. or not end
- igouy 8y agofwiw https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/ruby.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... Some of those Ruby 2.6 programs are faster with --jit and others are faster without --jit faster or similar: nbody #2, fasta #6, fannkuchredux #2, spectralnorm #4 slower with --jit: binarytrees #5, pidigits #5, regexredux #3, revcomp #5, mandelbrot #2, knucleotide #1
- alfredmuffin 8y agoIs it a good time to learn Ruby? I mostly do React and Node + Java work professionally, but I've been looking into Ruby as a fun side project language. I would appreciate any anecdotes!
- unixhero 8y agoIt a language made to make you as a developer happy. So, yes.
- theredbox 8y agoAs good as any time. You will loose a lot of performance when compared to v8 but the ruby paradigm is subjectively much more pleasant to work with.
- faitswulff 8y agoEnumerable methods are almos always what make me want to ditch Javascript for Ruby.
- jonahx 8y agoHave a look at: https://ramdajs.com/ https://ramdajs.com/
- zephyrfalcon 8y agoES6 has map, filter, reduce, etc... and anonymous functions which can be used in lieu of Ruby blocks.
- xiphias2 8y agoFor me it is too much fun. I love that I can use most of the standard library without thinking / looking at the documentation, and not needing to wait for compilation. But at the same time I hate that I love a language that performs so bad compared to being closer to the metal.
- rakoo 8y ago
- rurban 8y ago> non-ASCII constant names This is actually a security risk, avoiding all Unicode security recommendations. See e.g. http://websec.github.io/unicode-security-guide/visual-spoofing/ http://websec.github.io/unicode-security-guide/visual-spoofi... All they did was open the floodgates: https://github.com/ruby/ruby/commit/f852af0e59899157ef695edccbe86d51fc04d23b https://github.com/ruby/ruby/commit/f852af0e59899157ef695edc... no rtl checks, no spoofing, no mixed script checks, no normalization.
- tedunangst 8y agoHow is it it a security risk to name a constant in source code?
- dr_zoidberg 8y agoHe linked a resource that explains visual spoofing, an "attack technique" in which an attacker registers a domain that renders exaclty the same as yours, but actually isn't (because it uses unicode points which render the same --or very similar-- to latin alphabet letters). I woulnd't go as far as saying "it's a security risk", but on some situations it may lead to weird bugs in which you think you're referring to one constant/variable and you're actually referring to another (visually equivalent/the same) const/var.
- pawelmurias 8y agoit can be used to create malicious pull requests that are visually indistinguishable from correct ones
- dragonwriter 8y ago> it can be used to create malicious pull requests that are visually indistinguishable from correct ones If your only check on the correctness of submitted code is visual inspection, you've got a much bigger problem than Unicode confusability.
- saagarjha 8y ago
- mmahemoff 8y ago> Constant names can now start with non-ASCII capital letters. I am not sure how useful this is Very? If you want to code in non-Latin languages. Also, π = 3.14159
- ascar 8y agoI'm not sure about this being good for coding in non-latin. It might actually encourage behavior to mistreat ruby constants as regular variables. IIRC constants are not really constant, but only visual help for reading code and ruby just issues a warning on reassignment and these warnings are not shown by default. I can totally imagine new devs just trying out non-ascii variables, see it not crashing and then actually writing all their code using constants.
- matt4077 8y agoI don't quite understand how this change makes the (somewhat remote) misunderstanding you describe any more likely than it previously was for people using ASCII only. I also just tried and was duly warned upon reassignment, a setting I don't remember changing.
- jwdunne 8y agoRe-assignment warns by default. I tried it, exploring to see what was possible. It indeed worked but threw a warning. I hadn't changed configuration.
- dragonwriter 8y ago> I can totally imagine new devs just trying out non-ascii variables, see it not crashing and then actually writing all their code using constants. Ruby already supported non-ascii identifiers for variables; 2.6 added support for non-ascii first characters of constants, which must still be capital letters, as had always distinguished constants from variables. It doesn't make anything non-ascii a constant, it just makes constants consistent with other identifiers in terms of non-ascii support, while preserving the “initial capital means constant" rule. And, as sibling comments note, reassigning a constant produces a warning, so devs making a mistake and using constants for variables (regardless of ascii-ness) will quickly be informed of their error.
- akulbe 8y agoI was trying to go download the latest Ruby or even read the latest release notes, but the site seems to be down. It's still ruby-lang.org, right?
- akulbe 8y agoWeird. I googled "ruby 2.6 download" and links from the results worked, but simply trying to browse to "ruby-lang.org" times out.
- steveklabnik 8y agoIt just resolved for me. Maybe it'll clear up for you soon!
- augustl 8y agoReally like the idea of using lazy ranges instead of magic negative indices! I.e `xs[6..]` instead of `xs[6..-1]`.
- pulisse 8y agoNegative indices aren't magic. They follow the obvious wraparound (modular) pattern: Negative `i` indexes the element in array `a` located at `i % len(a)`. If they worked any other way it'd be madness.
- mmahemoff 8y agoTrue, they're not magic, it just looks ugly for the most common case of fetching to the end of the array. The new syntax is much nicer than -1.
- viraptor 8y agoI don't think you got that index calculation right. -1 in array of 5 elements is located at 5-1 == 4, not at 1%5 == 1.
- kvakil 8y agoIt depends on how you define the modulo operator [0]--there are definitions where (-1)%5 == 4 and definitions where (-1)%5 == -1. Presumably the GP is referring to the former case. [0]: https://en.wikipedia.org/wiki/Modulo_operation#Remainder_calculation_for_the_modulo_operation https://en.wikipedia.org/wiki/Modulo_operation#Remainder_cal...
- pulisse 8y agoI don't follow your point. We're concerned with the value of -1 % 5, not 1 % 5. There's no definition of the modulus operator on which -1 % 5 = 1.
- viraptor 8y agoPhrasing issue, I think. I understood "Negative `i` indexes the element" as `i` itself being positive. Like you'd say "negative 1 indexes" (i is 1), not "negative -1 indexes" (i is -1)
- ajmurmann 8y agoRuby used to be my most beloved language. I've since developed a strong appreciation for good type system. However, working with collections of any kind in Ruby is just such a joy. The methods around it are so well thought throug and make writing code a joy that in most other languages just would be tedious. On top of that the Ruby team is constantly working on making that aspect even better. I truly don't understand why it seems to me that no other language I use makes even an effort to provide something similar. Getting a map, a reduce and a filter function seems to be as far as most standard libraries are willing to go.
- yxhuvud 8y agoTry Crystal and you get the joy of Ruby enumerables together with a static type system.
- briandear 8y agoCrystal is nice, but my love affair with Swift is going strong. Not exactly Ruby syntax but pretty similar in terms of simplicity. I am a Rubyist who feels right at home with Swift. But for the new year, I definitely want to give Crystal a fair shot!
- pkulak 8y agoKotlin is my new love. Best collections library of any language I've used, great type system, coroutines are amazing, and all of it integrates perfectly with 25 years of rock-solid Java libraries.
- kodablah 8y agoWhile the collections library may be better than others, it has a great many warts, many of which aren't discoverable until you've used it a long time. Some of these warts are a result of JVM interop requirements. It's not just the collections library, while the language is great and better than others, there are mounds of bugs and poor design decisions.
- diminish 8y agoAm I the only one to find -rcX and -previewX type of versioning confusing. like how much time is remaining etc.
- stevev 8y agoThis will be fun. I’m glad we now have some performance improvements to some common methods. For those considering playing with Ruby, you should! One thing I’m surprised not many has mentioned what makes ruby unique and awesome, BLOCKS!
- dreix 8y agoAren't they like arrow functions in JavaScript?
- avandecreme 8y agoJust parameters that are functions, except that you can only have one per function. I still fail to see the advantage of blocks over being able to pass functions as arguments like in other languages.
- kbp 8y agoOne nice feature of blocks is that `return` will return from the enclosing function, rather than the block, so you can write: def find(x, l) l.each do |y| return y if y == x end end Where in Lisp you'd use (return-from find x) and in other languages you might pass in a continuation or use a special return value protocol. It's a nice solution for higher order functions that are supposed to feel more language-level. Also, you can pass functions as arguments like in other languages; lambdas behave like you would expect them to.
- ufmace 8y agoA lot of this kind of stuff is more about language and standard lib culture than strict language features. Ex - Rust actually has exceptions, technically, in the form of Panics, and you can infact catch them. But the culture of Rust is strongly against using panics in that way. Basically never catch panics and only allow them to happen when you're okay with the whole program blowing up. Use Option and Result and check them if you care about your program not blowing up. Similarly, Ruby has nice blocks, and many other languages have similar closure support. But Ruby's support is so built-in from day 1 and heavily used in the standard library and the general culture of Ruby gems. Many of the methods in Enumerable take blocks, making it easy to chain a bunch of functional stuff together, even without any support gems and from the earliest days of Ruby.
- maximegarcia 8y agoone shot mode [1] for coverage will be handy in production as it has quite no overhead. Happy xmas Ruby devs! [1] https://bugs.ruby-lang.org/issues/15022 https://bugs.ruby-lang.org/issues/15022
- saagarjha 8y agoWhat is the complexity of set operations on arrays? This seems a bit too much sugar to me, to the point where people will end up writing inefficient code because they will thing these methods are more performant than they really are. Usually, I like to see explicit conversions to sets to make the performance characteristics explicit.
- 40acres 8y agoI haven't used Ruby before but I'd have to guess that their Array implementation utilities table doubling, if this is the case operations like concat, union, and difference should be linear.
- deleted 8y ago[deleted]
- mmahemoff 8y agoIn most real world applications, the cost of doing an in-memory data manipulation like this is negligible compared to I/O, waiting for the database etc. It's already the wrong language for someone who wants to squeeze out every CPU cycle, and imo it's a Good Thing for a language upgrade to embrace its strengths ie syntax sugar in the case of Ruby, as long as the perf hit isn't out of control. I'd agree developers should pick the right data structure for the job and some APIs can obscure the cost to the point of misleading developers into woefully wrong decisions. I just don't think it's the case with array ops like union as it's easy enough to handle them efficiently. I too would be interested to see any benchmarks though.
- saagarjha 8y agoI might be more receptive to this if this was added to all collections, then, rather than just arrays. (Maybe it was? I don’t write Ruby, so I don’t know for sure. Maybe Ruby doesn’t have a generic “collection” protocol?)
- mmahemoff 8y agoInteresting point. Ruby has an Enumerable module, but these methods were added only to Array. Since the main native collections (Set/Hash/Array) all support them now, they could probably be added to Enumerable in the future, with class-specific optimizations if necessary.
- Lordarminius 8y agoFantastic Christmas present from the Ruby team. Ruby is alive and well despite all the rumors of it's demise. I predict a resurgence in its use over the next few years. Can't wait to examine and try out the new features.
- JamesAdir 8y agoWhat makes you think there'll be a resurgence in its use in the next few years?
- j1elo 8y agoFor when Ruby 3.x? They should release soon, if we are to start seeing some decent adoption by 2028. /pythonicsarcasm
- lloeki 8y agoThe access to AST will allow for neat hacks like PonyORM on Python, which could be a way for me to improve Rebel::SQL. Tentative hacks by decompiling bytecodes or using Parser, while fun, proved practically unsatisfactory. https://ponyorm.com https://ponyorm.com https://gitlab.com/lloeki/rebel https://gitlab.com/lloeki/rebel