# File modes

**URL:** <https://www.ruby-forum.com/t/file-modes/142726>\
**Category:** Ruby\
**Created:** [July 10, 2008, 9:53pm UTC](https://www.ruby-forum.com/t/file-modes/142726 "2008-07-10T21:53:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [July 10, 2008, 9:53pm UTC](https://www.ruby-forum.com/t/file-modes/142726/1 "2008-07-10T21:53:39Z")

</div>

A post on Arc  
[[Arcane Sentiment: Arc gets I/O right](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

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [July 10, 2008, 11:34pm UTC](https://www.ruby-forum.com/t/file-modes/142726/2 "2008-07-10T23:34:27Z")

</div>

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](http://prometheus.rubyforge.org/ruby-nuggets/classes/IO.html)

cheers  
jens

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [July 10, 2008, 11:37pm UTC](https://www.ruby-forum.com/t/file-modes/142726/3 "2008-07-10T23:37:23Z")

</div>

On Jul 10, 1:48 pm, “Martin DeMello” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> A post on Arc [[Arcane Sentiment: Arc gets I/O right](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. 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

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [July 10, 2008, 11:41pm UTC](https://www.ruby-forum.com/t/file-modes/142726/4 "2008-07-10T23:41:29Z")

</div>

On Thu, Jul 10, 2008 at 2:29 PM, Jens W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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](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

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [July 10, 2008, 11:50pm UTC](https://www.ruby-forum.com/t/file-modes/142726/5 "2008-07-10T23:50:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Martin\_DeMello](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f17d59/32.png) [@Martin\_DeMello](https://www.ruby-forum.com/u/Martin_DeMello)\
**Post date:** [July 10, 2008, 11:49pm UTC](https://www.ruby-forum.com/t/file-modes/142726/6 "2008-07-10T23:49:40Z")

</div>

On Thu, Jul 10, 2008 at 2:32 PM, Daniel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 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
