4 ms·
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 reason
by betwixthewires 6y ago
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?
- joelbluminator 6y agoDepends 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.
- tachyonbeam 6y agoIMO 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.
- joelbluminator 6y ago> 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.
- vidarh 6y ago> 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.
- oezi 6y agoI 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.
- jonnytran 6y agoYes. 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.
- betwixthewires 6y agoThat'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.
- lloeki 6y agoDo 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/normandy https://github.com/lloeki/rebel https://github.com/lloeki/rebel
- rantwasp 6y agothis is so true. Ruby is so much more than Rails.
- cercatrova 6y agoCheck out Julia, it's getting big in scientific and data communities.
- dunefox 6y agoCan recommend, it's pretty elegant, fun, and efficient. Also: https://github.com/JuliaPy/PyCall.jl https://github.com/JuliaPy/PyCall.jl "This package provides the ability to directly call and fully interoperate with Python from the Julia language."
- rajangdavis 6y agoFrom 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.
- betwixthewires 6y agoParticularly 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.
- lloeki 6y agoThat’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 .
- geraldbauer 6y agoSee 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/ https://planetruby.github.io/gems/ PS: (And yes, the website itself is built with jekyll and ruby, see https://github.com/planetruby/gems https://github.com/planetruby/gems ).
- claudiug 6y agoin ruby you have the async gems from https://github.com/socketry/async 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 https://github.com/thbar/kiba
- dgregd 6y agoOnly 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.
- AlchemistCamp 6y agoI'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.
- dgregd 6y agoRuby 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.
- hxegon 6y agoWarning: 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 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'
- ascendantlogic 6y agoBoth 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.
- jkmcf 6y agoThe 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.
- Xixi 6y agoLearning 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...