Live data from Hacker News

Ruby is beautiful (but I'm moving to Python)

wit.io

41–50 of 68 posts

Re: Ruby is beautiful (but I'm moving to Python)

#41
What he says about higher order functions rings very true for me. I learned Python before Ruby, and while I love using both languages, in Ruby I really learned for the first time the power of higher order functions because they are thrown in your face when using it. They are everywhere in the standard library and the syntax makes them very convenient to read and write. They are idiomatic Ruby.

Once I learned Ruby, I started using higher order functions in other languages. Learning Ruby changed the way I wrote Python. Learning Ruby even changed the way I wrote Java! While I code mostly in Python, C#, and a little Racket these days, I'll always remember Ruby fondly for changing the way I thought about coding.

As a side note, The other thing Ruby opened my eyes to was metaprogramming. Ruby's metaprogramming facilities are dead simple compared to Python's, which I feel changed practically every release from 2.2 onward. Of course the Lisps take the cake when it comes to code generation, but Ruby's ability to easily manipulate symbol tables is a nice easy way to start wrapping your head around the idea of code that generates code if your brain has already gotten used to C-style syntax and finds homoiconic s-expression-based languages a little strange.

Re: Ruby is beautiful (but I'm moving to Python)

#42
post #18

Previous discussion: http://news.ycombinator.com/item?id=1947723 OP appears to have changed domains.

I did, sorry that messed up the HN dupe filter. I git three-letter domains much more than ones inspired by sentences :)

s/git/dig/

Re: Ruby is beautiful (but I'm moving to Python)

#43
post #40

In Ruby, everything is an object and responds to messages. And it turns out that we can ask a number if it’s even or odd. In other words, numbers have our criterion function built in, and we don’t have to define it at all. I absolutely hate this. In fact, I'm not a huge believer in object-oriented programming in general. even? Is not an operation that integers perform. Integers do not contain methods -- they are data…

I don't get your argument. What's the difference between module Numeric def even? # ... end end and even? :: (Numeric t) -> a Both declare functions that consume something implementing the Numeric type/protocol, and return something else. I don't see the practical difference between them, other than the calling syntax of the result.

First, the even function is only defined for integers, not general numeric types. Second, type classes are not objects. Ad hoc polymorphism is used to denote different actions for different types but it doesn't break typing. The type integer is not the type object-integer:

    even? :: Integer -> Bool
I am actually thoroughly confused where you got your type specification. Were you trying to say:

    class Integral a where
      even? :: a -> Bool

    even? :: (Integral a) => a -> Bool
The reason why this disturbs me is because I find it difficult to draw the line at why even? should be even? :: (Integral a) => a -> Bool instead of even? :: Integer -> Bool. This doesn't make sense -- it's not a good use for typeclasses. There aren't many different categories of types which have a semantic notion of being even but a different implementation or type restriction. Even is just... even. It's just an operation on the integers. There's no need to bring ad hoc polymorphism in here.

Re: Ruby is beautiful (but I'm moving to Python)

#44

In Ruby, everything is an object and responds to messages. And it turns out that we can ask a number if it’s even or odd. In other words, numbers have our criterion function built in, and we don’t have to define it at all. I absolutely hate this. In fact, I'm not a huge believer in object-oriented programming in general. even? Is not an operation that integers perform. Integers do not contain methods -- they are data…

Your rant isn't an argument, it's an opinion. I can just as well say integers are objects like any other and even? makes perfect sense as a method on them because that's the entire point of objects in the first place, binding state and behavior together into a single smarter package because it's a convent method of organizing code.

I agree 100% that it is my opinion. I would wager that most rants are opinions.

As far as this being the point of objects -- I see no state. I see no behavior. All I see is a function which maps the set of integers to booleans. That's it. It's just a function. The only reason we need packaging or modules at all is to prevent name collisions and importing the world.

Re: Ruby is beautiful (but I'm moving to Python)

#45

In Ruby, everything is an object and responds to messages. And it turns out that we can ask a number if it’s even or odd. In other words, numbers have our criterion function built in, and we don’t have to define it at all. I absolutely hate this. In fact, I'm not a huge believer in object-oriented programming in general. even? Is not an operation that integers perform. Integers do not contain methods -- they are data…

>Why do we constantly feel the need to wedge objects into everything in existence Because... it's convenient? Do we need a reason?

I fail to see how

    i.even?
is any more convenient than

    even? i
except that even? has now somehow entered into the set of functions worthy to be part of the integer-fake-object while others have not.

Re: Ruby is beautiful (but I'm moving to Python)

#47

Earlier quoted context omitted.

>Why do we constantly feel the need to wedge objects into everything in existence Because... it's convenient? Do we need a reason?

I fail to see how i.even? is any more convenient than even? i except that even? has now somehow entered into the set of functions worthy to be part of the integer-fake-object while others have not.

It's more consistent (no wondering what's a method and what's not for most common situations) and it stops the global namespace getting littered up with functions that are only relevant to certain types.

To a Rubyist, knowing that Ruby is an object oriented language, it is clear one is sending a message to i. With the latter example, it is not clear what even? belongs to and what it expects to receive.

Re: Ruby is beautiful (but I'm moving to Python)

#48

In Ruby, everything is an object and responds to messages. And it turns out that we can ask a number if it’s even or odd. In other words, numbers have our criterion function built in, and we don’t have to define it at all. I absolutely hate this. In fact, I'm not a huge believer in object-oriented programming in general. even? Is not an operation that integers perform. Integers do not contain methods -- they are data…

I completely agree. I like how most responses to your rant hone in on the fact that it's a simple syntactic change, but utterly fail to get the point that composition of stateless functions a la Joy is totally magical, and opens up a whole world of possibilities that mutating, unchainable, uncomposable methods cannot.

For starters, and given that this is a thread about scientific computing, having stateless functions that mirror mathematical ones gives you robust, efficient approaches for parallelism and optimization that are completely lost (or horribly intractable) once you start boxing numeric types just so some OOPhead can put a dot after them.

Re: Ruby is beautiful (but I'm moving to Python)

#49
post #22

Earlier quoted context omitted.

These kinds of projects can take years to take hold; you can't expect people to just all switch right away. Blog posts like this just need to be commented on with a link to those libraries. Eventually some big lecture, class or project will use one of those libraries and a whole new group of people will supplement the community. This doesn't just go for Ruby, it applies to any language Ruby performance in general is…

There's more inertia here than you may be thinking. See this recent HN headliner about the difficulty of getting the NumPy/SciPy community to merely move from CPython to PyPy: http://technicaldiscovery.blogspot.com/2011/10/thoughts-on-p... If that's a challenge, good luck getting a lot of NotProgrammers to move to a completely different language. Besides, if I may be blunt, who in Rubyland cares if these guys are on…

You make good points, they're not blunt. I've just read the same basic blog post many times complaining that there's no SciPy in Ruby. Again, I'm not in the sciences so I'm out of my element talking about it. I'm just trying to make the simple point that there does seem to be people out there wanting science libraries for Ruby

Re: Ruby is beautiful (but I'm moving to Python)

#50

Earlier quoted context omitted.

Characterizing the Ruby philosophy as "you are a special snowflake" is, well, starting a flamewar

Honest question, how would you characterize it?

With Ruby, the flexibility of being able to do things in more than one way makes it necessary to learn conventions rather than just the language spec. Sometimes breaking those conventions can have a tremendous upside. Some people find that upside worthwhile and others don't.
Post reply on HN