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?
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?
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'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:
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.
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.
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.
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.
Any suggestions on which practical language to complement Javascript for web dev? Also, use cases for functional programming language, is it even useful?
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.
I'd go for Elixir's Phoenix or, if you really need some heavy duty API gateway -- Rust's Actix-web 3.x.
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.
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.
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.
Ruby doesn't have functions, but you can obtain a first class value for any method by calling the method `method` on any object.
The syntax in Python also leaves much desired (e.g. use of underscores) and most of Ruby's quirks are Perlisms such as $1.
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...
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.
PS: (And yes, the website itself is built with jekyll and ruby, see https://github.com/planetruby/gems ).
i dont know for data manipulation but i guess also ruby has it. maybe this https://github.com/thbar/kiba