4

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.

3 Answers 3

2

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)

It's

  • 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?
1
  • 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
    Commented Mar 21, 2011 at 13:11
2

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.

2
  • 1
    I didn't know about --simple-prompt. Interesting.
    – sawa
    Commented Mar 21, 2011 at 13:14
  • you certainly can avoid the =>nil. Try using both of these switches at once: irb --prompt "inf-ruby" --noinspect
    – abm
    Commented Jul 8, 2011 at 5:20
1

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



irb(main):002:0>
2
  • 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
    Commented Jul 10, 2011 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
    Commented Jul 10, 2011 at 10:53

You must log in to answer this question.

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