News for hackers. Stuff that matters.
Re:Ruby 3.0 by betwixthewires on Friday December 25, 2020 @03:56AM (#25535226)
I've been considering learning Ruby to replace Python for high level coding and scripting, Python is what I use for most of what I do. Should I? The main reasons I have not are inertia, massive selection of data manipulation libraries in Python, difficulty of async and multithreading in both languages means not much benefit from a usability perspective, and I'm not a fan of the Contributor Covenant CoC.

But I have looked at the syntax of Ruby and find it to be more elegant. Does anyone knowledgeable about it have any useful information?

Re:Ruby 3.0 by hxegon on Friday December 25, 2020 @08:02AM (#25536223)
Warning: opionion from someone who primarily used python a long time ago

Ruby's design is a lot more consistent/predictable/ergonomic than python. the ruby standard library is honestly amazing (see: https://ruby-doc.org/core-2.7.2/Enumerable.html)

Everything is an object, methods take blocks where that makes sense. stuff just feels well thought out and generally when I learn something new about ruby I think 'wow that makes sense' and not 'why would you do it like that'.

There also seems to be much much less churn from a tooling perspective. Learn how gems/bundler works and you're set.

Also, ruby can be a (in my experience) superior replacement for awk.

Brief example, -n is loop over current line as $_, -l is clean up line endings

  cat .zsh_history | ruby -nle 'BEGIN{$x=[]}; $x << $_.encode("UTF-8", invalid: :replace, replace: ""); END{$x.sort_by{ _1.count("|") }}'
I was trying to find some longer pipelines from my command history. encode is stripping out a bunch of invalid utf-8, otherwise it would have just been $x<<$_

or, pick a random line from stdin:

  ls | ruby -e 'puts ARGF.to_a.sample'
Re:Ruby 3.0 by lloeki on Friday December 25, 2020 @04:10AM (#25535299)
Do learn Ruby. You seem to answer your own question! You’re curious about it, worst case you’ll have opened your mind to something else which is only a good thing.

But do not be fooled by Rails, Ruby is quite something else, of which Rails is a very small, opinionated part.

Tips: look at MiniTest source code, Sinatra and Rack source code are quite interesting too.

Shameless plug, a couple of idiomatic Ruby repos of mine:

https://github.com/lloeki/normandy

https://github.com/lloeki/rebel

Re:Ruby 3.0 by rantwasp on Friday December 25, 2020 @01:26PM (#25538089)
this is so true. Ruby is so much more than Rails.
Re:Ruby 3.0 by dgregd on Friday December 25, 2020 @04:45AM (#25535438)
Only if you are going to use Rails. It seems that in all other domains Ruby have lost to Python, Kotlin, Go and others. Personally I love Ruby and Rails, I prefer clean Ruby syntax over Python syntax, however except Rails all other activity is going in other languages. Kotlin code with type inference is as concise as Ruby code but executes 50x faster. Ruby simply won't have ML libraries like Python has.

For a web programming I would switch to Kotlin. However Ktor is still lacking compared to Rails in most important areas for me. In Rails common operations like upload a picture, serve is later in a different resolution, migrate a db, quickly create CRUD forms, etc. are just a few lines of code. In Kolin web frameworks you would have to invest much more time to glue together different libraries to do the same job. Many won't agree with that opinion but for me Rails ActiveRecord is the best part of Rails. There is no a such complete thing for a Java ecosystem. It is a beautiful compromise between ideological (only pure plain Java objects are allowed) ORMs like Hibernate and plain SQL approach like jOOQ.

Re:Ruby 3.0 by AlchemistCamp on Friday December 25, 2020 @05:24AM (#25535588)
I've been using Phoenix rather than Rails as my go to for web development, but I still use Ruby shell scripting. It's dramatically faster to write than Python, Go or Rust, largely because it's got more convenient Unix interop than anything since Perl.

One example is, I've written a script that I can pass a domain name and an email address to. It will then set up basic nginx blocks, install certbo and add a cron job if needed, run certbot, get an https certificate and reconfigure the nginx blocks to reverse proxy incoming requests and force https.

I have no idea what language would have let me write this faster than Ruby did. Maybe Perl if I knew it well. Definitely not Go or Rust.

Re:Ruby 3.0 by dgregd on Friday December 25, 2020 @07:33AM (#25536103)
Ruby started as a shell scripting language so I agree that it is good for that purpose. However the question is how much time one spends writing shell scripting code for personal use. If someone already knows Python and only occasionally writes shell scripting code then in my opinion learning a new language only for that purpose isn't a good investment. I would say Python is good enough for that tasks.

In other words if someone has a good enough tool in their tool-belt for a certain area, then learning another slightly better tool in that area is not a must.

In my opinion it is better to be proficient in a one language than mediocre in two similar languages. If someone is bored and has time to learn both Python and Ruby then why not.

Re:Ruby 3.0 by AlchemistCamp on Friday December 25, 2020 @07:53AM (#25536168)
I'd say Ruby's edge for shell scripting is considerable, but I agree with that strategy and recorded a whole video on the idea: https://youtu.be/bIpgUmn5yK8

tldw; Pick tools that complement each other rather than compete with each other.

Also it's interesting that some languages like C or JavaScript make a good complement to almost anything.

Re:Ruby 3.0 by richajak on Sunday December 27, 2020 @10:39AM (#25551706)
As much as I want to learn new languages, it looks like my brain is not cooperating. Either the syntax is hard to read (eg ruby or elixir) or articulating the same solution (eg python) in Javascript much easier.

Any suggestions on which practical language to complement Javascript for web dev? Also, use cases for functional programming language, is it even useful?

Re:Ruby 3.0 by freedomben on Friday December 25, 2020 @03:51PM (#25538942)
This is essentially my situation exactly!

Ruby is a fine application development language, but an incredible scripting language. Can't recommend it enough for that niche. Nothing else is even close.

Re:Ruby 3.0 by pdimitar on Friday December 25, 2020 @07:12AM (#25536019)
For web development -- Kotlin? Hm, possibly I guess.

I'd go for Elixir's Phoenix or, if you really need some heavy duty API gateway -- Rust's Actix-web 3.x.

Re:Ruby 3.0 by rajangdavis on Friday December 25, 2020 @04:34AM (#25535383)
From the opposite side, I learned Python after learning Ruby (and Javascript) and had a hard time with Python namely with scoping and lambdas.

I think if you care a lot about the philosophy behind Python (have one obvious way to do things, explicit over implicit) and the syntax, then you might have some difficulties picking up Ruby right away.

With that said, I think it's a very enjoyable language; Rails is still a very enjoyable ecosystem; and it works well for scripting especially if you're trying to write organized shell scripts.

Re:Ruby 3.0 by betwixthewires on Friday December 25, 2020 @03:48PM (#25538924)
Particularly I am a fan of the "explicit over implicit" paradigm, and what little tinkering I've done with Ruby, you're right, that does mess with me a little.
Re:Ruby 3.0 by lloeki on Saturday December 26, 2020 @05:32AM (#25542572)
That’s mostly a Rails trait though. I code and choose a mostly explicit approach to Ruby, which lends itself very well to that, especially as it’s how the stdlib is designed .
Re:Ruby 3.0 by ascendantlogic on Friday December 25, 2020 @08:53AM (#25536467)
Both languages have their strengths and weaknesses. I have a Ruby background and have been learning Python more recently. After years of "artisinal" Ruby with heaps of unnecessary metaprogramming magic Python seems nicer to me, but I'm senior enough to be aware of my perceptions not necessarily being reality.

The bottom line is that (A) the more languages you are proficient in the better and (B) as long as whatever problem you need to be solved is solved then the language doesn't really matter.

Re:Ruby 3.0 by joelbluminator on Friday December 25, 2020 @04:05AM (#25535272)
Depends on how much of a drag you feel Python to be. People sometimes want a change for change's sake. If you think you're happier using Ruby well that's a good enough reason to seriously consider it. Outside of machine learning I can't really see any objective advantage one has over the other. Both are super mature, expressive, dynamic languages. The rest is a matter of taste. Jobs wise I'm sure Python has an avdantage, but Ruby has some strong niches (web development, devops) that are always in high demand as well.
Re:Ruby 3.0 by tachyonbeam on Friday December 25, 2020 @04:15AM (#25535307)
IMO Python has more libraries, more developers (people who might want to work on your project with you), and a more simple and intuitive syntax (easier to onboard people). Ruby is a fairly quirky language, eg functions aren't first-class values.
Re:Ruby 3.0 by oezi on Friday December 25, 2020 @07:58AM (#25536202)
I would say that Python is quirky for having functions at all and as a Rubyist it is confusing why some things are functions in Python when they could be methods. This leads to a much simpler mental model in Ruby.

The syntax in Python also leaves much desired (e.g. use of underscores) and most of Ruby's quirks are Perlisms such as $1.

Re:Ruby 3.0 by jonnytran on Friday December 25, 2020 @02:44PM (#25538539)
Yes. Why the f is len() a function in Python? From a design perspective, it makes absolutely no sense. You have to implement the __len__() method in order for the len() function to work. Why isn't it just a method?! And that is the one "right" way to do it. Drives me crazy. And there are countless other examples like that.
Re:Ruby 3.0 by joelbluminator on Friday December 25, 2020 @04:19AM (#25535321)
> and a more simple and intuitive syntax

That's the crux of it here. People really differ about this and OP should check it out for himself. Yes Python has more usage, I hardly think it really affects one's work in any meaningful way. Javascript has tons of developers using it, many times this is a con actually. An explosion of libraries and conflicting views and philosophies.

Re:Ruby 3.0 by betwixthewires on Friday December 25, 2020 @03:45PM (#25538902)
That's another consideration I forgot to mention. A lot of what I do is small FOSS tools and it seems most of the people interested in using and contributing to stuff like that are proficient in Python, whereas the Ruby community seems to circle around Rails and is very small.
Re:Ruby 3.0 by vidarh on Friday December 25, 2020 @06:09AM (#25535781)
> eg functions aren't first-class values.

Ruby doesn't have functions, but you can obtain a first class value for any method by calling the method `method` on any object.

Re:Ruby 3.0 by Xixi on Monday December 28, 2020 @09:23AM (#25559368)
Learning anything new is always a good idea. My (maybe unpopular?) opinion is that Python and Ruby are practically the same language. With different syntax, sure, but the same in the sense that there is a large overlap in terms of what they are good at and bad at. If Python is a good fit, then Ruby probably also is. If Python is not a good fit, then neither is Ruby. Unless you really depend on libraries that are only available in one language (say data manipulation libraries).

So I would personally recommend learning something new that is quite different. For high level coding you could give Elixir a go. I've seen it used at a very high level to orchestrate machine learning jobs running in either Python or Java. Ruby/Python are probably still better for little scripts though. For data manipulation maybe give Julia a go? For lower level programming maybe try Go or Rust?

Whenever I need to reach for async in Python I ponder rewriting the program with Go or Elixir. Python feels like a very high and expressive language with tedious, low level async primitives bolted in...

Re:Ruby 3.0 by jkmcf on Friday December 25, 2020 @05:12PM (#25539436)
The only downside of Ruby, IMO, is it isn't installed everywhere by default, whereas python is.

It also isn't hip anymore, and many of the brains from years past have moved onto Go and Rust based on my casual observation.

Re:Ruby 3.0 by cercatrova on Friday December 25, 2020 @04:22AM (#25535335)
Check out Julia, it's getting big in scientific and data communities.
Re:Ruby 3.0 by dunefox on Friday December 25, 2020 @07:20AM (#25536050)
Can recommend, it's pretty elegant, fun, and efficient. Also: https://github.com/JuliaPy/PyCall.jl "This package provides the ability to directly call and fully interoperate with Python from the Julia language."
Re:Ruby 3.0 by geraldbauer on Friday December 25, 2020 @04:40AM (#25535409)
See the Ruby Advent Calendar 2020, December 1st - December 25th - 25 Days of Ruby Gems [1] that highlights ruby scripts in action for a sampling what you can do with ruby. [1] https://planetruby.github.io/gems/

PS: (And yes, the website itself is built with jekyll and ruby, see https://github.com/planetruby/gems ).

Re:Ruby 3.0 by claudiug on Friday December 25, 2020 @04:42AM (#25535417)
in ruby you have the async gems from https://github.com/socketry/async

i dont know for data manipulation but i guess also ruby has it. maybe this https://github.com/thbar/kiba