Live data from Hacker News

Happy Birthday, Ruby

github.com

161–170 of 239 posts

Re: Happy Birthday, Ruby

#161
post #14

Ruby was my re-entry into programming. Before it, I had tried programming in highschool (c++) and, while I did well at it, felt like it wasn't for me. I was going to go into some other field like Photography instead. By chance I had to do a programming class in college, and they had put me into the wrong one by accident - a final year software project in Ruby. I did really well at it, fell in love with the language a…

Me too actually. I flirted with programming around uni-time and after - PHP, java, friggin' ada - and just couldn't see myself enjoying it so I went into network management instead. 10 years later I was thoroughly sick of that, so started to look around and heard about this little language called Ruby - and it was love at first sight. Then this little software project called Rails started to gain momentum and there w…

I don't get this Elixir as the natural progression for Rubyists. OO/mutable Ruby and functional/immutable Elixir are worlds apart beyond the superficial syntax similarities.

Re: Happy Birthday, Ruby

#162

Earlier quoted context omitted.

(defn fizz-buzz [n] (map #(cond (= 0 (mod % 15)) "FizzBuzz" (= 0 (mod % 5)) "Fizz" (= 0 (mod % 3)) "Buzz" :else %) (range 1 n)))

(def fizzbuzz-nums (range 1 101)) (defn fizz? [n] (zero? (% n))) (defn buzz? [n] (zero? (% n 5))) (defn fizzbuzz? [n] (and (fizz? n) (buzz? n))) (defn fizzbuzz [n] (cond (fizzbuzz? n) "FizzBuzz" (fizz? n) "Fizz" (buzz? n) "Buzz" :else n))) (def fizzbuzz-list (map fizzbuzz fizzbuzz-nums)) (apply println fizzbuzz-list)

Simple.

But this brings up a debate I've been having with some folks. I have the memory of a gnat, so I can't keep a lot of context in my head. I prefer the previous two examples to this one, simply because with this one, I have to remember a lot more contextual vocabulary.

It's a pet-peeve of mine to pull up a source file, and then have to ping-pong around between 50 different function calls, when the entire thing could have been written linearly in fewer than 50 lines of code.

On the other hand, small functions like yours are easier to verify at a glance and move on. I haven't figured out what the right trade-off is.

Anyone else want to weigh in on this conundrum?

Re: Happy Birthday, Ruby

#164
post #72
post #39

Earlier quoted context omitted.

Check out Crystal - Its statically typed, compiled, and a near one to one implementation of Ruby. https://crystal-lang.org

Is it backwards compatible with Ruby?

No. And it varies wildly - some Ruby files may run with just a couple characters (or even none) being different, and other may require a total rewrite.

Re: Happy Birthday, Ruby

#165
post #3

> Ruby isn't the most beautiful language out there Huh, I sure think it is. I wonder what the author thinks the competition might be? Ruby has its issues for sure, but aesthetics ain't one of them - far and away my favourite out of any major language.

I'm not sure what language would be more beautiful than ruby, to be honest, and it's not even my favorite language to use. Let's do a mini code challenge in the thread -- implement fizzbuzz in the most beautiful way you can, in the most beautiful language you know:

  (1..100).each { |n| { 15 => 'FizzBuzz', 3 => 'Fizz', 5 => 'Buzz' }.find { |d, s| n % d == 0 }.then { |_, s| puts s || n } }

Re: Happy Birthday, Ruby

#166
post #16

Ruby is the very least favorite of all the programming languages I've had to use regularly over my career. Its syntax strongly favors cuteness over familiarity. Wherever Ruby can diverge from expectations to give you a pointless little tickle of whimsical inventiveness instead, it seems to do so. Visually it looks like an unwanted love child of Pascal and Python. There's no clear rhyme or reason to the use of sigils…

I don't understand your bit about "cuteness over familiarity". Can you give an example outside that's not Rails-related (given that Rails seems to be the main source of your concrete complaints)? Sigils in Ruby actually do have strong and clear meanings. And the difference between symbols and strings is a useful distinction. And contrary to your statement, Ruby's stdlib is far more complete and more internally consis…

It's not the best example, but Ruby is the only language I can think of where an expression (e) fails to parse but ((e)) parses.

I find that it encourages a bad kind of code golf that leads to hard to maintain code.

Re: Happy Birthday, Ruby

#167

Earlier quoted context omitted.

But you’re writing an ActiveRecord migration. It’s explicit in the same way that echoing a string out is ‘puts’ instead of ‘print’ because this is Ruby and not Python.

what if you're on a team where your responsibilities are divided and you only touch ActiveRecord sporadically? What does ActiveRecord consider the plural of "fish"?

You can change the inflections if you need to do so. ActiveRecord by default considers fish to be an uncountable noun, so the plural would be "fish".

Re: Happy Birthday, Ruby

#168

Earlier quoted context omitted.

> There is no real magic in Rails For most parts of Rails, I agree. There is one very important one where I don't: ActiveRecord's internal behaviors are opaque enough at most levels where you care about your database to be fairly called "magic". Having to reverse-engineer ActiveRecord to make my database stop puking and to generate a make developers who know Rails but not databases not get upset that now the solution…

Fair enough, I would say that the internals of ActiveRecord/Arel/etc can be complicated but also do a lot of work. I watched a number of presentations by tenderlove and had a bit of background/interest in that area to start with. "Go watch this guy's videos about relational algebra and SQL generation" is probably not what you want to hear when there's a bug though. By the time you've gotten there though you've certai…

Honestly, these days? Writing my own SQL and using languages with static typing. I'll take a little longer to write code to make thinking about it easier.

I still use Ruby nontrivially for stuff like command line tools, though.

Re: Happy Birthday, Ruby

#169
post #139

Earlier quoted context omitted.

So...eh. Ruby has the easiest data access tools, between ActiveRecord and Sequel (which I prefer), out there. I don't know too many folks who'd disagree with you about that. But where you're happy with Rails taking a few lines, I am as of late big on Kotlin (because I agree with you regarding Java) encouraging me to be correct . I'm building a new product using Spring Boot, Kotlin, and JDBI and while, yes, there's bo…

The problem with boilerplate is not the typing of it (that can be automated), but the reading of it (that can't really be automated until programmers are replaced with AI). It hides semantically useful code in mountains of noise. I agree with you about the usefulness of a language that helps in thinking about a problem, but I feel like boilerplate is a kind of tech debt we tend to underrate.

I agree with you regarding the reading of boilerplate; that's in particular why I like JDBI. It abstracts the boilerplate of building out a data access layer; you write an interface and it automatically builds the implementation from parameterized SQL queries on the classpath.

Between that and Spring Boot (which is fairly batteries-included but makes it clear when you're going off the happy path in ways I can deal with), I feel remarkably good about my choices with this and similar recent projects.

Re: Happy Birthday, Ruby

#170

Earlier quoted context omitted.

I'm not sure what language would be more beautiful than ruby, to be honest, and it's not even my favorite language to use. Let's do a mini code challenge in the thread -- implement fizzbuzz in the most beautiful way you can, in the most beautiful language you know:

#!/usr/bin/env ruby puts((1..100).map do |n| "#{:Fizz if (n % 3).zero?}"\ "#{:Buzz if (n % 5).zero?}" .then .find { |s| !s.empty? } || n end)

I'm curious: do you genuinely find that beautiful?To me all the enumerable/map/frozen string literal stuff seems pointlessly overcomplicated compared to the simplicity of just writing down what you're supposed to do:

  (1..100).each do |n|
    a = String.new
    a 
(Disclaimer: not my code, on mobile so I stole that off GitHub)
Post reply on HN