People posting Ruby questions often post their code as if it were given in a Interactive Ruby Shell (IRB) dialogue, but given the IRB prompt is redundant, annoying, and slows down reading, I think it will be a good idea to discourage people from posting the code like this, and encourage them to post in a static script form, unless giving an interactive dialogue is really necessary. I propose this point to be considered as one criterion for editing as well. Similar things may be said for other languages that have an interactive mode.

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

I have a similar conflict with scala code. It looks like this:

scala> val b = List (4, 11, 17)                    
b: List[Int] = List(4, 11, 17)

scala> val bs = sortSuperSetSum (b)               
bs: scala.collection.immutable.IndexedSeq[Int] = Vector(4, 6, 10, 11, 15, 17, 21)


  • unfriendly for cut'n' paste
  • harder to read
  • make horizontal scrolling more likely

but on the other hand it

  • produces additional information
    • about types
    • values
  • proves executable code

Of course the user can have both, he groups his code, and only shows few interesting, formatted results as comment:

val b = List (4, 11, 17)                    
val bs = sortSuperSetSum (b)               
// IndexedSeq[Int] = Vector(4, 6, 10, 11, 15, 17, 21)
  • Is it similar with irb?
  • Do you have links?
share|improve this answer
Thanks for your opiniton. And thanks to Peter, now my question has a link to wikipedia on irb. You can see its pretty much redundant. In ruby, results are usually shown by # => .... –  sawa Mar 21 '11 at 13:11
add comment

As a heavy Python user, I find using the shell can be useful sometimes. I agree that the Ruby shell puts too much garbage that distracts from the real code though. My solution is to use the --simple-prompt option, which makes it far more readable:

$ irb --simple-prompt
>> puts 'hello world'
hello world
=> nil

The => nil still gets in the way (is there a way to remove it?), but I think this is at least bareable.

share|improve this answer
I didn't know about --simple-prompt. Interesting. –  sawa Mar 21 '11 at 13:14
you certainly can avoid the =>nil. Try using both of these switches at once: irb --prompt "inf-ruby" --noinspect –  abm Jul 8 '11 at 5:20
add comment

IRB's output can be refined to the desired level. Rather discourage its output usage, we can recommend users to try using both of these switches at once:

irb --prompt "inf-ruby" --noinspect

So the output looks like:

C:\Users\ABM>irb --prompt "inf-ruby" --noinspect

irb(main):001:0> puts 'Hello World'

Hello World

share|improve this answer
That will be better, but if there is no particular need to show the promt in the questions/answers, then it is better to not have it at all. –  sawa Jul 10 '11 at 6:49
I would second your opinion. But this practice is adopted by many bloggers and bash/terminal (*nix/ape) type stakeholders. So its too much to hope that this practice would be avoided at a greater scale in python/ruby and other highly console-dependent languages especially in linux/apple platforms (coz they've a powerful shell base!) WindOS7 & Vista, OTOH, by introducing powershell with .net integration (not very popular thus far), it seems they're also vouching for this custom and yet it's probable that we would see some post with "This is windOS console".split(" c") kind of syntax. :) –  abm Jul 10 '11 at 10:53
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .