file modes

Discussion in 'Ruby' started by Martin DeMello, Jul 10, 2008.

  1. A post on Arc [http://arcanesentiment.blogspot.com/2008/07/arc-gets-io-right.html]
    made an excellent point - file modes are essentially exposing a low
    level implementation detail for a high level feature. Would be nice to
    have File.open_read, open_write and open_append (or less clunky names
    if anyone can think them up; it's the principle of the thing) to
    support the common cases.

    martin
     
    Martin DeMello, Jul 10, 2008
    #1
    1. Advertising

  2. Martin DeMello

    Jens Wille Guest

    hi martin!

    Martin DeMello [2008-07-10 21:48]:
    > Would be nice to have File.open_read, open_write and open_append
    > (or less clunky names if anyone can think them up; it's the
    > principle of the thing) to support the common cases.

    just added them to ruby-nuggets [1] ;-) (sans the 'open_')

    [1] <http://prometheus.rubyforge.org/ruby-nuggets/classes/IO.html>

    cheers
    jens
     
    Jens Wille, Jul 10, 2008
    #2
    1. Advertising

  3. On Jul 10, 1:48=A0pm, "Martin DeMello" <> wrote:
    > A post on Arc [http://arcanesentiment.blogspot.com/2008/07/arc-gets-io-ri=

    ght.html]
    > made an excellent point - file modes are essentially exposing a low
    > level implementation detail for a high level feature. Would be nice to
    > have File.open_read, open_write and open_append (or less clunky names
    > if anyone can think them up; it's the principle of the thing) to
    > support the common cases.


    I don't agree. First, there are too many possible combinations, making
    separate method names infeasible IMO. Second, tradition. Third, it's
    more code (and more maintenance) for the core developers. Fourth, if
    we follow that line of reasoning for other libraries (think Socket),
    the API will explode.

    Regards,

    Dan
     
    Daniel Berger, Jul 10, 2008
    #3
  4. On Thu, Jul 10, 2008 at 2:29 PM, Jens Wille <> wrote:
    > hi martin!
    >
    > Martin DeMello [2008-07-10 21:48]:
    >> Would be nice to have File.open_read, open_write and open_append
    >> (or less clunky names if anyone can think them up; it's the
    >> principle of the thing) to support the common cases.

    > just added them to ruby-nuggets [1] ;-) (sans the 'open_')
    >
    > [1] <http://prometheus.rubyforge.org/ruby-nuggets/classes/IO.html>


    Neat :) I suggested the open_ because I was wondering how you'd get
    around the fact that there was already an IO.read, but your solution
    looks good.

    martin
     
    Martin DeMello, Jul 10, 2008
    #4
  5. On Thu, Jul 10, 2008 at 2:32 PM, Daniel Berger <> wrote:
    >
    >
    > On Jul 10, 1:48 pm, "Martin DeMello" <> wrote:
    >> A post on Arc [http://arcanesentiment.blogspot.com/2008/07/arc-gets-io-right.html]
    >> made an excellent point - file modes are essentially exposing a low
    >> level implementation detail for a high level feature. Would be nice to
    >> have File.open_read, open_write and open_append (or less clunky names
    >> if anyone can think them up; it's the principle of the thing) to
    >> support the common cases.

    >
    > I don't agree. First, there are too many possible combinations, making
    > separate method names infeasible IMO.


    The modes are still there in .open if you need them; they just aren't
    exposed in the common cases.

    > Second, tradition.


    And if you want them :)

    >Third, it's more code (and more maintenance) for the core developers.


    Not that much more; it's just a few methods

    > Fourth, if we follow that line of reasoning for other libraries (think Socket),
    > the API will explode.


    From what I've seen, that's not necessarily inconsistent with the ruby
    way. Just needs good documentation.

    martin
     
    Martin DeMello, Jul 10, 2008
    #5
  6. Martin DeMello

    Jens Wille Guest

    Martin DeMello [2008-07-10 23:36]:
    > Neat :) I suggested the open_ because I was wondering how you'd
    > get around the fact that there was already an IO.read, but your
    > solution looks good.

    well, it's not completely backwards compatible, since the original
    IO::read would silently take a block. but i thought aliasing it and
    only behaving in the new way if a block was provided, would be ok.
    so i opted for the "less clunky" names ;-)

    cheers
    jens
     
    Jens Wille, Jul 10, 2008
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jakob Bieling

    Q: Why are there file access modes?

    Jakob Bieling, Dec 2, 2003, in forum: C++
    Replies:
    6
    Views:
    381
    jeffc
    Dec 3, 2003
  2. simon place
    Replies:
    5
    Views:
    374
    Michael Hudson
    Aug 27, 2003
  3. erikcw

    Having trouble with file modes

    erikcw, Nov 3, 2006, in forum: Python
    Replies:
    6
    Views:
    298
    Fredrik Lundh
    Nov 4, 2006
  4. tubby
    Replies:
    2
    Views:
    329
    Stefan Schwarzer
    Jan 7, 2007
  5. HMS Surprise

    File modes

    HMS Surprise, May 10, 2007, in forum: Python
    Replies:
    4
    Views:
    370
    HMS Surprise
    May 11, 2007
Loading...

Share This Page