4 ms·
Honest question - I'm very familiar with Ruby and for my automation tasks I tend to use it almost exclusively. Of these, is there anything that - 1. Ruby can'
by thunderbong 7y ago
Honest question -
I'm very familiar with Ruby and for my automation tasks I tend to use it almost exclusively. Of these, is there anything that -
1. Ruby can't do
2. Or is more complex / complicated to do in Ruby
- nurettin 7y agoHonestly, I've done a lot of professional work in both languages, and there is pretty much nothing you can't do with ruby that you can in python. There is no intrinsic difference in power of expressiveness between the languages. Although ruby is lagging a little behind with the asyncio syntactic sugar stuff. You may reach a point where there simply isn't any client written for the service you are trying to automate in either language. And python got more love in that aspect what with all the being the number one preferred scripting language on planet earth, but in case your target of automation provides a simple rest or websocket protocol you could easily do without a dedicated client library for it.
- mattlondon 7y ago> [Python] being the number one preferred scripting language on planet earth Is it? I'd imagine JavaScript usage/execution is probably way way higher.
- sampo 7y agoBut people don't use javascript to write scripts. Javascript is mostly used in writing web services.
- wilsonrocks 7y agoI mostly write javascript now for my day job... But python is nicer for scripts... The asynchronous nature of node makes it a pain for me
- josteink 7y agoAsync/await largely solves that though.
- wilsonrocks 7y agoTo an extent... If you're using something that supports promises and not callbacks, which not all of the things you want to use to write an actual script do.
- josteink 7y agoYou can easily transform a callback into a promise via simple glue-functions: let result = await CallbackPromise.from(some.callbackConventionFunction, param); Then you get a unified form for the code-base.
- nurettin 7y agoYes python is more preferred when choosing a scripting language and javascript is more executed in browsers. And the two do not contradict.
- nailer 7y agoI think you're both correct. For sysadmin definition of scripting, python would be most popular. For the 'fast to write' definition of scripting then sure, JavaScript.
- thunderbong 7y agoThanks. I really don't have any idea about the asyncio syntatic sugar that you mention. Can you point me to some books / articles?
- nurettin 7y agoOh async/await is just python's and javascript's way of executing functions concurrently within the same process. asyncio emerges as a rewrite of a standard library to support this idiom. Browsers that execute javascript ES6 and node v7 onwards have this feature. Instead of passing callbacks to functions and have them executed concurrently, you create a task or future (in python 3.6+) or a Promise (in javascript) and await that. That is very useful because it untangles the callback-inside-callback structure. There's a comparison between node and python's async/await syntaxes here https://medium.com/@interfacer/intro-to-async-concurrency-in-python-and-node-js-69315b1e3e36 https://medium.com/@interfacer/intro-to-async-concurrency-in... For ruby I found this article which shows the gist of what we are trying to accomplish with async/await (we want to gather a bunch of promises and await all their results and have them run concurrently in an event loop so that when one is waiting for IO to complete, the other one takes over and runs) https://www.codeotaku.com/journal/2018-06/asynchronous-ruby/index https://www.codeotaku.com/journal/2018-06/asynchronous-ruby/...
- thunderbong 7y agoI understand async/await as I'm conversant with NodeJs. When you mentioned asyncio, I assumed it be something specific in the Python library. In case of Ruby, I've found these libraries (ruby gems) to be very useful. 1. Sidekiq - https://github.com/mperham/sidekiq https://github.com/mperham/sidekiq 2. RocketJob - https://github.com/rocketjob/rocketjob https://github.com/rocketjob/rocketjob What I'm guessing you're saying is that this kind of behavior is available natively in Python, whereas in Ruby, it is achieved by some roundabout fashion.
- nurettin 7y agoYes, async functions are natively available in python3.6+ and node7+, and requires a gem in ruby. Ruby can also use fibers and eventloop to do concurrency using just the standard library, but it is missing the async/await syntactic sugar.
- bastih 7y ago1. no 2. no, not really - however there may be libraries that python has that ruby doesn't have Side note: Ruby has more syntax to grok, which makes it harder to read (for me). On the other hand Python does have its own idiosyncrasies and subtle behaviors. However, Ruby also has some features (like multiline inline functions) that one may easily miss in Python, but they haven't been worth switching over for me.
- UncleEntity 7y agoPython has multiline inline functions--perhaps you mean lambda?
- bastih 7y agomy bad: meant multiline lambdas.
- blackrock 7y agoI researched Ruby, but the syntax idiosyncrasies of the language made it appear to be created by an amateur. Like weird language constructs to do something, that makes you go, "huh! What kind of random junk is this?" Some people obviously swear by it, and thus created Ruby on Rails. Python does have some weird features as well, but I try to steer away from it, and keep my code simple and boring. My primary concern is how efficient the code is executed as it gets translated into machine code. The cost/benefit ratio of switching to Ruby never quite seemed worth it. So I continue to stick with Python, for applications that are not time execution sensitive. For all others, there's Java, then C++, then C itself.
- swyx 7y agoyou say “created by an amateur” like it’s an insult. some of the best things we have are created by total amateurs. thats how this works. i’m not 100% on the life histories of Matz and Guido but wasnt Guido kind of also an amateur too?
- andai 7y agoThey were both involved academically with language design.
- Izmaki 7y ago"...Python, for applications that are not time execution sensitive. For all others, there's Java, then C++, then C itself." That is assuming you know how to work with data structures and algorithms the right way. A O(n^n) implementation runs slow in C as well.
- lawik 7y agoI'd say the languages are largely equivalent. Roughly the same level of abstraction, roughly the same technical trade-offs. Highly productive, lots of people enjoy them, not very strict. What Python does have specifically for automation in my eyes is that it is often the default language for most Raspberry Pi-related hardware libraries. So if you want to build home automation on accessible and easy hardware, the Pi is very welcoming to Python just in terms of making things easy, providing libraries. It is also heavily supported for machine learning and computer vision which is related. Again, this is generally just a matter of library support. I don't know the Ruby ecosystem well enough to say if it has equivalents to all the Python scraping, fuzzy matching and such libraries out there. But I expect it does. So that bit is probably a wash. Hope that gives a perspective.
- thunderbong 7y agoYes, I know about Python's extensive ML libraries. Didn't know about it being the default language for Raspberry Pi libraries. Thanks. I've been planning to look at both learning some ML and doing some small Raspberry Pi projects. That's good motivation for diving into Python!
- oefrha 7y agoHonestly, variations of this question has been asked too many times to be taken as an “honest question”. See also: Rails developer hijacking Django thread. It’s weird lots of Ruby developers feel the need to shout “don’t forget ruby!” when nice things about Python are posted. Just take your pick, who cares. Btw, I know, assume good faith, yada yada.
- OrgNet 7y agoThere's micropython for the esp8266... not sure if ruby has been ported
- HelloNurse 7y agoPython is significantly more popular than Ruby. It doesn't mean that it's a better programming language, but a library for X or an example of how to do X are significantly more likely to exist for Python than for Ruby, and there are other popularity advantages like more implementations.
- Can_Not 7y agoIf you like ruby, checkout crystal.