Ruby 2.6
anamaria.martinezgomez.name
anamaria.martinezgomez.name
- 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?
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 .
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...
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
tl;dr: your Rails app is not faster with this feature in this version, but might be in the future.
It’d be like [0,1] === 0
`===` 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`.
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.
https://github.com/Kotlin/kotlinx.coroutines/blob/master/cor...
But dang it's nice to do stuff in it.
The GIL would be quite easy to replace otherwise.
IIUC for CRuby it's mostly about how to keep the VM simple. Koichi Sasada is working on an ownership based model like Erlang has, which sidesteps a bunch of theses issues.
I used to love Ruby too but the dynamic typing quickly became a deal breaker. So I set out to find a language that's as pleasant to use on a daily basis, with well designed libraries and collections, but also statically typed.
Kotlin met all these requirements for me.
Knowing exactly what types a method takes and the compiler catching incorrect uses before the code ever runs saves a lot of frustration. Another thing I've enjoyed in Rust include `match` clauses forcing me to define branches for any possibility, especially for `Result` structs. In ruby this isn't possible because anything can be anything.
I have a hunch that single/static dispatch is what tends to cause more problems than merely the presence of nil. It's not nil, but how you use it.
Can you elaborate on how multi-dispatch reduces the issue of nil/null?
I also use static type (typescript) to prevent issues with nil and would like to know how I can achieve the same in a dynamic language.
It's a lot easier for me to reason about and avoid edge cases when I can (more or less) verify at compile time that invalid states are impossible.
This is about more than just catching null values, and also encompasses things like mutually exclusive fields, and access control.
If you're interested, I gave a talk once that dives into these ideas more effectively than I can express in this comment: https://github.com/ShaneWilton/programming-with-types-talk/b...
We were on a really old Mongoid (or carrierwave, or some other gem, can't remember), It was difficult to find the right methods to use and etc.
I understand it was our own fault not to write comprehensive tests or keep all gems up-to-date.
But a dynamic typing language is a lot more "punitive" when we aren't writing perfect code, using perfect design, and/or exercising perfect engineering practices.
It's easy to find what's available in Ruby: https://ruby-doc.org/core-2.5.3/Enumerable.html
Good luck with Clojure: https://clojure.github.io/clojure/clojure.core-api.html
Your example could be improved by using "products.sort_by(&:cost).last"
I try to not use map because often there are methods that already implement filtering. Gotta love Ruby readability.
const list = [ 1, 3, 4, 2, 8, 5];
const [fst, ...snd] = list;
But I suppose that's just a result of JS implementing pseudo-pattern matching. head, *tail = *list
Has worked since 1.8. Don't ask me how I know that :-PYou don't on the RHS, or rather, it's redundant in the given example. On the LHS you need it to prevent single element capture.. and within the ruby language, it's a fairly consistent sigil.
Similar to blocks in Smalltalk and Self, surely?
Still, having worked with ruby a fair bit the past year, it does deliver much of what Smalltalk does (not surprising, as ruby borrows heavily from smalltalk).
https://www.gnu.org/software/smalltalk/manual/html_node/Invo...
Scala even allows multiple blocks to be passed in, used to good effect in the Cats effect `bracket` function, amongst others.
```ruby
def foo &bar
return bar
endfoo {}
# => #<Proc:0x00007ff23783c4e0@(irb):16>
```
But I do agree that I don't quite understand the need for the distinction between procs and methods, or the need for unbound methods; I would think that methods could just be either bound to one object or another, as unbound methods are useless for the fact that they won't work at all unless they are bound.
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.
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.
[0]: https://en.wikipedia.org/wiki/Modulo_operation#Remainder_cal...
Very? If you want to code in non-Latin languages.
Also, π = 3.14159
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.
I also just tried and was duly warned upon reassignment, a setting I don't remember changing.
In terms of data science, python is my go-to and much more tooled for that kind of work. For any kind of desktop app I'll use C++, and for browser extensions / add-ons it's JavaScript.
The only problems I wouldn't go to Ruby for are CPU intensive ones or ones where I need parallel threads (which you already have Java for)
Truffle Ruby ?
https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
> TruffleRuby is progressing fast but is currently probably not ready for you to try running your full Ruby application on. However it is ready for experimentation and curious end-users to try on their gems and smaller applications.
> TruffleRuby runs Rails, and passes the majority of the Rails test suite. But it is missing support for Nokogiri and ActiveRecord database drivers which makes it not practical to run real Rails applications at the moment.
Emphasis mine, but that puts it firmly in the "fun toy" category rather than a viable technology for anything mission critical.
Do we think that's what `jb3689` meant by CPU intensive.
It can be fun and it's as close as Smalltalk will probably get to mainstream acceptance, but if you are hoping for a lucrative commercial skill then probably you have missed the boat. Ruby is mainly used for two what most would now consider legacy things, Rails based websites and Chef based infrastructure. There is still some money to be made in maintenance of course and will be for a few years but the sun is definitely setting on Ruby. But 10 years ago it was super-hot.
But at the same time I hate that I love a language that performs so bad compared to being closer to the metal.
I'm thinking of trying out Julia, as it's dynamic but still has a lot of interesting libraries, but for now I just decided with working with small data, so actually I don't have performance problems.
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.
Real-world performance and asymptotic complexity aren't the same thing.
> Usually, I like to see explicit conversions to sets to make the performance characteristics explicit.
The performance problem with this approach (for certain problems) when you have input arrays and want an output array is that Array->Set and Set->Array conversions are not free, and even if this is better in asymptotic complexity, you aren't always operating at the extends where asymptotic complexity dominates, so you can end up with code that is both excessively verbose and unnecessarily nonperformant just to make asymptotic complexity more apparent.
They should release soon, if we are to start seeing some decent adoption by 2028.
/pythonicsarcasm
This is actually a security risk, avoiding all Unicode security recommendations. See e.g. http://websec.github.io/unicode-security-guide/visual-spoofi...
All they did was open the floodgates: https://github.com/ruby/ruby/commit/f852af0e59899157ef695edc...
no rtl checks, no spoofing, no mixed script checks, no normalization.
Every name needs to be identifiable. Simply enabling XID_Start + XID_Continue for unicode violates all unicode security recommendations. See the recommended Unicode Security Profiles 1-5, http://www.unicode.org/reports/tr39/#General_Security_Profil...
ruby violates all of them. so do many other languages.
BTW identifiers are not just url's, mail addresses or variable names, but also usernames and paths (filenames, directory names). eg with RTL spoofing you can hide ../
nobody cares so far, esp. not Linux filesystems. Garbage in garbage out is a security risk. The old Apple HPFS at least normalized unicode, the new one is again insecure.
If your only check on the correctness of submitted code is visual inspection, you've got a much bigger problem than Unicode confusability.
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.
But I can't see much else that is a realistic security risk (readability and code clarity risks are another story.)