8 ms·
> This is a perfectly cromulent article, but as someone relatively new to Ruby, I don't see the beauty. Perhaps I've spent too much time with the airless asceti
by masklinn 16y ago
> This is a perfectly cromulent article, but as someone relatively new to Ruby, I don't see the beauty. Perhaps I've spent too much time with the airless asceticism of, say, Scheme
Yes. Ruby is beautiful when you come from PHP or Java or C++. If you come from Python it's meh because it's a very similar language (though the community is different and a number of recipes/best practices are very different) at the syntactic and at the semantic levels, and if you come from Lisps, from Smalltalk, from ML or Haskell, etc… then it's not "meh" it's "ugh", because the language is far more complex less orthogonal and far more full of weird corner-cases than what you come from.
TFAA came to Ruby from Java, so Ruby was like seeing the Sistine Chapel for the first time.
- rue 16y agoI have a strong dislike for the now-nearly-meaningless terms "beautiful", "eloquent", "elegant" &c. but for me the deciding factor between Ruby and Python for a project (assuming no constraints from libraries required and such) is Ruby's internal consistency. Python is a bit more haphazard; the infamous `len(str)`, to wit.
- masklinn 16y ago> Python is a bit more haphazard; the infamous `len(str)`, to wit. There is nothing infamous about it. It's a multimethod, the designers of Python decided that mandating the same function for everything (via a common protocol under the covers) was better than risking people implementing a thousand different method names. They did the same with the iterator protocol.
- rue 16y agoI think that is a poor argument since the same is not true of every function. Therefore, it feels inconsistent to me, which is the only basis I can make judgments on.
- masklinn 16y ago> I think that is a poor argument since the same is not true of every function What is not true of every function?
- binomial 16y agoI think the GP was referring to "mandating the same function for everything (via a common protocol under the covers) was better than risking people implementing a thousand different method names".
- adambyrtek 16y agoI wouldn't call Python haphazard, it's just a different approach. Ruby was designed from the ground up as an object-oriented language, and the fact that everything is a method call (message) gives it a touch of consistency. This is different from Python which is a multi-paradigm language. In fact the early releases didn't support objects-oriented programming at all. On the other hand Python may feel more consistent because of the fact that, in contrast to Ruby, there is one obvious way to do something[1]. [1] http://www.python.org/dev/peps/pep-0020/ http://www.python.org/dev/peps/pep-0020/
- derefr 16y agoInstead of a simply giving your subjective aesthetic evaluation, based on some measure of "elegance", you could objectively compare, in HCI terms, the usability of the languages as user-interfaces to the computer. A mouse may be more elegant than a keyboard, but for, say, word-processing, it would have comparatively-horrible usability. Likewise (and this is just a throwaway argument, not the general point I'm trying to make), Lisp may be more elegant conceptually than Ruby, but when trying to find an individual incorrect line of code to make a change, Lisp's "elegant" uniformity actually hinders scanning, whereas Ruby's bumpy, "inelegant" syntax gives your eyes regularized shapes to abstract sections of code into, and thus visually skip them without having to read into their contents. However, as the mouse's elegance matches well with a paint program, Lisp matches well with Turing-complete data-specifications ("code as data.") Usability is not a one-dimensional spectrum, like your partial ordering of "beauty" above, but rather a consideration made separately for each task an interface is used for.
- foljs 16y agoActually, despite all the fanfare about LISP, Haskell, Scheme et al, more useful programs have been written and deployed in, say, Python, than all those combined. What's the last useful LISP program you have used? What proportion does it consist among the other useful programs you use?
- j_baker 16y agoEmacs (ok, so it has a kernel of C code but it's still by and large a lisp program)
- andolanra 16y agoI use Scheme/Haskell for most of my scripting purposes, the only exceptions being the cases where I want to make use of some extant library, in which case I switch to Python/Ruby. I used stumpwm for a while, which was written in Common Lisp, and a few months ago switched to XMonad, which is all Haskell. All my editing is done in Emacs, which uses a variety of Lisp (elisp.) Given that close to 100% of my time is spent in XMonad, and >50% of my time is spent in Emacs, and every session involves at least some interaction with my collection of scripts... I'd say I use quite a lot of useful programs written in those fanfare-laden languages.
- axod 16y agoFWIW, I come from Java and find Ruby to be fairly ugly. It's all subjective, but I prefer concise, exact non ambiguous readable code. From a google for 'ruby sample code'... http://www.fincher.org/tips/Languages/Ruby/ http://www.fincher.org/tips/Languages/Ruby/ print " with no line breaks." printf("\n\nprintf ... %7.2f,... %s.",3.14156,"me") Eugh brackets are optional for invoking functions? So I can no longer just look for () after a name to determine what is a function invocation? def welcome(name) puts "howdy #{name}" end "end"? Seriously? Verboseness... (This is one of the things that for me, makes ruby very ugly. It's needless verbosity and doesn't have any advantage over using {} ). "hello".upcase() => "HELLO" "hello".upcase => "HELLO" Yuck. So how do you know what's a function and what's a variable? balance = -10.0 puts "Bankrupt" unless balance > 0.0 Starting to look like cobol here... 'unless'? seriously? Why is that nicer than an if statement? Java code has a very exact, easy to parse syntax. We all know it, and it's easy to learn - {} for code blocks, () for method invocations, etc That's just for starters.
- clyfe 16y agoRuby can use both "{...}" and "do ... end", with a slight difference between the two (precedence): def some_method { ... } def some_method; ... end obj.something # "something" is allways a method # never a var, say accessor (getter, setter &c ...)
- steveklabnik 16y agodef cannot have {}, it needs ;/end. {} or do/end work for blocks, however.
- clyfe 16y agoindeed, you are right
- axod 16y agoHaving optional beauty isn't really any beauty at all though. I'm just more at home with exact, specific concise well structured syntax. I know it's an extremely unpopular opinion to hold, especially round these parts, but I don't see any beauty in Ruby syntax. Same with Python...
- bad_user 16y agoI'm a Python programmer, and I find code written in Ruby to be more beautiful. It's just a personal preference, but I find anonymous code blocks to be a lot more elegant and intuitive than decorators + with statements + for comprehensions. I also like that classes are open, and that you can execute code inside the declaration of a class and that self is implicit ... making tasks suited for the __metaclass__ concept in Python trivial. I also find Lisp / Haskell and ML to be really ugly ... as in, I could never look over a piece of code and understand what it is doing without learning the language first (with the learning curve being as steep as it gets). the language is far more complex less orthogonal and far more full of weird corner-cases than what you come from But that's the price you pay for convenience. E.g. I don't appreciate that ML doesn't have a simple concept like operator overloading, or that in LISP every DSL still looks like LISP. I don't like that a Smalltalk application is not portable between implementations or that applications are big, monolithic images of the virtual machine with everything included, even the IDE. It's easy to get into these mine-is-bigger-than-yours contests, especially with languages, but you know what works better than formulating half-baked opinions? Results. It's a lot better to shut up and show me some code ;)
- masklinn 16y ago> I also find Lisp / Haskell and ML to be really ugly Wow. > I don't appreciate that ML doesn't have a simple concept like operator overloading ML operators are nothing more than functions. The issue of "operator overloading" comes from the type system and the simplicity of the language. > or that in LISP every DSL still looks like LISP You might want to read on Scheme reader macros. > I don't like that a Smalltalk application is not portable between implementations It's true that you don't have this issue in Ruby as the "standard" is simply the original implementation (aka there is no standard at all, and not really any competing implementation). > or that applications are big, monolithic images of the virtual machine with everything included, even the IDE. That definitely isn't the case. That's not the case in GNU Smalltalk, and most commercial smalltalk let you create a stripped production image which contains only the necessary code.
- mnutt 16y ago
- 16s 16y agoRuby 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
- anthonyb 16y agoI 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.
- deleted 16y ago[deleted]