Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Ruby is nicer to read than Python. Here's how each language reverses a string:

# Ruby

string.reverse()

# Python

string[::-1]

Which looks better?

Edit: I'm not sure why this is being down voted. It's a true statement.

Edit2: With all the down voting on Hacker News recently, I'm about to quit sharing my knowledge here. Maybe pg will do something about this. It needs to change otherwise good people will stop posting here.

Edit3:

irb(main):002:0> x = "hacker"

irb(main):003:0> puts x.reverse()

rekcah

>>> x = "hacker"

>>> print x[::-1]

rekcah



I think possibly because it's 'fiddling around the edges'. Sure, it's nice to have a way to reverse a string, but you don't do that very often in practice - assigning to lists, calling functions, etc. are all far more common.

But yeah, I hear you on the downvoting.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: