Live data from Hacker News

Ruby delights built into the language

technology.doximity.com

81–89 of 89 posts

Re: Ruby delights built into the language

#81

I appreciate the Ruby love in this post, but it's worth pointing out that the author is clearly new to the language. I say that because he writes Ruby as if he's writing some other language, and not idiomatic Ruby. This: dirp = Dir.open(".") for f in dirp case f when /\.rb\z/ print f, "\n" else # do not print end end dirp.close Could be made much more Ruby-native (and simpler!) as: Dir.open('.').each do |f| puts f if…

You couldn't be more wrong, and a simple Google search of the author was all you had to do lol. It's pretty clear here (given his background) that the author is writing in a style to make the code examples more accessible to a wider audience.

As a non-ruby developer, I find the initial example indeed much more readable.

Re: Ruby delights built into the language

#82

As a newb, what editor to use for Ruby? It's one of those languages that VS Code does not cover properly and I can't really find good setup for nvim or emacs. RubyMine works wonders but I'm poor. Also, why is Ruby "editor responsiveness" (not sure what to call it) so much worse than e.g. Python?

VS Code with Ruby extensions is what most people use from my experience.

I have no idea what you mean by editor responsiveness.

Re: Ruby delights built into the language

#83

I appreciate the Ruby love in this post, but it's worth pointing out that the author is clearly new to the language. I say that because he writes Ruby as if he's writing some other language, and not idiomatic Ruby. This: dirp = Dir.open(".") for f in dirp case f when /\.rb\z/ print f, "\n" else # do not print end end dirp.close Could be made much more Ruby-native (and simpler!) as: Dir.open('.').each do |f| puts f if…

Probably worth mentioning that each of those code snippets links out to a core sample in the ruby/ruby repository. There is a source link directly above the code you posted. https://github.com/ruby/ruby/blob/ruby_3_1/sample/dir.rb

Re: Ruby delights built into the language

#84
post #52
post #44

Earlier quoted context omitted.

That snippet looks like Python/Lua/C with the for, case and close being used. Ruby is one of those languages that like Lisp/Scheme, Smalltalk or Haskell requires you to know what is going on as well as what is available to come up with a clean/simple solution. I think finding good Ruby resources that are up to date are few but I believe most of the stuff out there still works in recent versions.

> That snippet looks like Python/Lua/C with the for, case and close being used Not really Python like at all - apart from the one line with for. Python doesn't have a case or when statement, or syntax level regex, doesn't open or close directories, and for files it would idiomatically would use the context manager for file access rather than closing it. But it also doesn't look like any Ruby I've seen or written eith…

For the record, Python didn't have a case or when statement. It does now, recently added to version 3.10.

Re: Ruby delights built into the language

#85
post #52

Earlier quoted context omitted.

> That snippet looks like Python/Lua/C with the for, case and close being used Not really Python like at all - apart from the one line with for. Python doesn't have a case or when statement, or syntax level regex, doesn't open or close directories, and for files it would idiomatically would use the context manager for file access rather than closing it. But it also doesn't look like any Ruby I've seen or written eith…

For the record, Python didn't have a case or when statement. It does now, recently added to version 3.10.

Doh, spending too long in Ruby lately - got some catching up to do.

Re: Ruby delights built into the language

#86
post #81

Earlier quoted context omitted.

You couldn't be more wrong, and a simple Google search of the author was all you had to do lol. It's pretty clear here (given his background) that the author is writing in a style to make the code examples more accessible to a wider audience.

As a non-ruby developer, I find the initial example indeed much more readable.

That's why LOC doesn't mean anything and I find the latter way more readable except for the fact ruby puts "if" behind for a single liner which isn't really comfortable reading.

Re: Ruby delights built into the language

#87

most of the posts here are criticisms of the OPs efforts. they seem misplaced. Ruby lacks accessible, consistent, example-based explorations that cover the breadth of the language in practice-- as a programming language, rather than just a dsl for OO and REST apps. I'm fairly new to Ruby and to programming in general. I've found so far that Ruby is sorely underdocumented. Coming from JS, where we have MDN, the docs f…

> array.each on an array of intergers will not behave the same as an array of strings What do you mean by this?

The discussion is in the chat history of the ruby channel in matrix chat. (lol)

Alas, logs aren't easily accessible in the element android app (which is what i've got).

Re: Ruby delights built into the language

#88

As a newb, what editor to use for Ruby? It's one of those languages that VS Code does not cover properly and I can't really find good setup for nvim or emacs. RubyMine works wonders but I'm poor. Also, why is Ruby "editor responsiveness" (not sure what to call it) so much worse than e.g. Python?

I recently started using the Solargraph LSP with neovim and it's pretty nice.

Doesn't quite get you to the level of RubyMine in terms of smart-ness, but I find it's close-enough in practice. And I also highly recommend using TreeSitter for syntax highlighting if you're gonna go the Neovim route -- for whatever reason, I've found regex-based highlighters to be unbearably slow on even medium-sized ruby files.

I also work on a project that uses Rubocop for linting which is nice since it gives you some Prettier-like auto-formatting.

There may be some more goodies to be had (e.g. debugging via nvim-dap), but I haven't dug into that yet. As it stands, I'm pretty pleased with my current setup.

Re: Ruby delights built into the language

#89

As a newb, what editor to use for Ruby? It's one of those languages that VS Code does not cover properly and I can't really find good setup for nvim or emacs. RubyMine works wonders but I'm poor. Also, why is Ruby "editor responsiveness" (not sure what to call it) so much worse than e.g. Python?

VS Code with Ruby extensions is what most people use from my experience. I have no idea what you mean by editor responsiveness.

"Dotting" into some property or method for ruby works noticeably slower than for any other language I've ever tried, same for autocomplete.
Post reply on HN