DEV Community

Discussion on: Please stop using Ruby

Collapse
 
northbear profile image
northbear • Edited

Actually I don't care what comes early or later. The point is what more or less comfortable to use in practice. It's absolutely subjective.
By example I am eager with Ruby for ability to write one-liners like:

ruby -e "Dir[\"./**/*.*\"].map{|i| File.dirname(i)+' '+File.extname(i)}.inject(Hash.new(0)) {|h,a| h[a]+=1;h}.sort_by{|k| k[0]}.each {|k,s| puts \"#{k} => #{s}\"}"

This one for example calculates how many files of what types exist in current directory and it subdirectories. I write similar one-liners in bash CLI without editor. How to write similar things things in python, I have no idea.
I know Python pretty well. I use it everyday for ALM automation for already 3 years. But anyway there still is wondering things in Ruby for me.
Rails is "the only tool ruby need for" mostly for people that usually far anough from ruby community. It's just popular internet mem that far from actual state.

Thread Thread
 
kyegupov profile image
kyegupov • Edited

I don't envy any person that would support such "one liners", but here's the Python version:

python3 -c 'from pathlib import Path; from collections import Counter; from os.path import splitext,dirname; c=Counter(); c.update(dirname(x)+" "+splitext(x)[1] for x in Path(".").glob("**/*")); import pprint; pprint.pprint(c)'

which one is easier to read, what do you think?

Your claim that you know Python "pretty well" seems dubious.

Good engineering is about writing a code which is reliable and easy to maintain. In my experience, Ruby's track record is abysmal on both counts.

P.S. Since I'm in the golfing mood, here's an one-liner in a statically typed language, which would be OBVIOUSLY not as elegant as the wonderful Ruby, right?

echo 'package main; import "os"; import "fmt"; import "path/filepath"; func main() { c := make(map[string]int); filepath.Walk(".", func(f string, _ os.FileInfo, _ error) error {c[filepath.Dir(f)+" "+filepath.Ext(f)]+=1; return nil}); for k,v := range c {fmt.Println(k, v)}}' > /tmp/a.go && go run /tmp/a.go
Thread Thread
 
northbear profile image
northbear • Edited

To talk about "easiness to read", you should learn more about functional programming and Ruby, of course. It's difficult for everyone to understand text or code if language it's written by is not known well.

I'm impressed that you reach an insight that not all prog.languages looks the same good in different applications.
So you still need only couple of steps to reach things that I talk about in beginning. And everyday exercises is very good habits. So You are definitely on the right way. Good job!

But your way to discuss here is boring me. I don't see any point to continue talk in this style. Good luck!