From: "NAKAMURA, Hiroshi" Date: 2006-06-06T10:42:02+09:00 Subject: Re: FasterCSV RCR? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, James Edward Gray II wrote: > That's why we have foreach(). Better to use that and gain all the > familiarity of Ruby programmers who are use to things working that way. > I still can't think of any good reason not to just follow Ruby's > interface as much as is possible and natural. To do anything else > forces programmers to adapt their expectations for no reason I can > understand. I think I still have not been able to explain well what's the difference of our viewpoint I think. You think a CSV object is an IO. But I don't think so and I defined Writer and Reader in csv.rb. It's not 'natural' from my viewpoint. That's why I think 'foreach' and 'readlines' should not be added. I feel a sentence "Comma Separated Value is an IO" strange. What do you think about it? FasterCSV should be CSVIO or CSV::IO, no? >> I know you are considering that IO-ish methods are important. But I >> don't think CSV object should handle IO methods like fcntl, fileno, >> seek, tell, tty?, and so on. Would you please tell me typical and >> pragmatic examples of reader style, except 'each'? > > If people only did what I could think of, programming would be very > boring. ;) It took me five or ten minutes to make all those methods > available and now they are there if someone needs them. Agreed to the first sentence. But I don't think we should do all we can do even if it's easy. > I can tell you that it has already come in handy. I got a bug report > that the line numbers in errors were off, because CSV allows embedded \n > characters in fields. To fix it, I overrode IO's lineno() method with > correct behavior. This seems very natural and the added bonus is that > you can now get a CSV aware line number. Thank you for the example. CSVIO#lineno or CSV::IO#lineno seems reasonable for me. But half of methods you defined as a delegator still seems not meaningful for me. # * binmode() # * close() # * close_read() # * close_write() # * closed?() # * eof() # * eof?() # * fcntl() # * fileno() # * flush() # * fsync() # * ioctl() # * isatty() # * pid() # * pos() # * reopen() # * rewind() # * seek() # * stat() # * sync() # * sync=() # * tell() # * to_i() # * to_io() # * tty?() # above is excerpted from faster_csv.rb/0.2.0 >>> * I always have to think, "Now do I want the *_line() method or the >>> *_row() method here..." >> >> Users don't need to use *_line and *_row methods I think. When do you >> use generate_line? > > I'm pretty sure we want to have our CSV library support data not in > files. Am I missing something? Is there a better way to get a CSV > string with your library? Please use CSV::Writer for that. str = '' writer = CSV::Writer.create(str) writer << [1,2,3] ... writer << [x,y,z] writer.close puts str >>> * Most methods take a field separator and a row separator, but >>> foreach() and readlines() only take the row separator. >> >> See IO.foreach and IO.readlines. > > That's comparing apples and oranges. IO.foreach() doesn't need to be > aware of fields, but CSV.foreach() does. IO.open() doesn't support a > field separator or a row separator, but your CSV.open() does because it > is needed. Hmm. I think "same name and different method arguments" is a bad design because it confuses users. But you already use (pseudo) keyword argument style so you are thinking "but just adding arguments could be a good design", right? It could be. I need more time to think about it. >>> Here's a selection of some features from my CHANGELOG that I am not >>> aware of in CSV: >> >> Thanks. I'll look into this. I hope those features are pluggable into >> csv.rb and other modules like DBI, spreadsheet related things, HTML >> table formatters, etc. I think some of these features are table >> specific, not CSV. > > This leads me naturally to the question: is there any good reason to > reinvent FasterCSV, when we could just use FasterCSV? ;) I wrote 'introduce' and meant 'I won't reinvent table specific implementations. I'll just get it from faster_csv, if it is pluggable'. Regards, // NaHi -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.1 (Cygwin) iQEVAwUBRITdFh9L2jg5EEGlAQIIEAf/VkUVW5+fzbBF4vBDpoAMQkfWC6OE/k58 XE8aIs5tQkvPT3k+63BuDnwbWqLTY6l346HRPAOmpqOna+99rYhXgy8kA6RbmI0A btX0xtHSvb37TzugnY0GavZE2ABo00LYvdPn8xV/IrogVApN5Do/530Zv2AqbCMI k2mG8am60JRS1OhwOSjEUHamBuCqiC26qu02t5MLTX+vtAyTXTCAOxTwKjciGW9p NCj+nDadDI97kCmbikQMn/mcDvXDZ6fxSfvjIE4rNkCzav0RUxKHLSa9nqOiRGVD SPAaEDB5DhqFvEcRCsC+2QKtKAKqYfffN1Tbyvf3fC/KM5dZUmMpZA== =3UM7 -----END PGP SIGNATURE-----