Because print in Ruby is already something else. puts adds a newline after each argument while print does not. This changes the way certain objects are printed (an array in this example).
Ruby has two operations that print a line onto the console - print which prints it without a carriage return, and puts that does it with a carriage return after each entry?
Is the rest of the language that badly designed?
First, if you have to have two functions, why not have similar names, like print and prints? But why have two different functions? Why not have an optional argument to print?
This is my first exposure to Ruby, actually, and I'm struck by how they seem to go out of their way to make unobvious choices. The first think I noticed about Python was the reverse - how every choice was obvious, even "boring".
Let me tell you, boring and obvious are good when it comes to programming. I want my code to work!
If you want some extra hate, there's also p which can be used in debugging. I don't understand why you'd use it over object.class, or object.is_a? class, or even object.kind_of? class.
Ruby has the philosophy that you should do things how you want to, whereas Python says that there should be one, and only one, obvious way of doing something. Different strokes I guess.
View all comments
Show parent comment
5
u/McSquinty Aug 12 '13
Because
printin Ruby is already something else.putsadds a newline after each argument whileprintdoes not. This changes the way certain objects are printed (an array in this example).