info-sather
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

File open modes


From: Norbert Nemec
Subject: File open modes
Date: Tue, 3 Oct 2000 16:18:21 +0200
User-agent: Mutt/1.0.1i

Alternative aproach: Why not have different classes for the different 
open modes? That would be the only way that makes sense to me! (Of 
course you still have different modes for append and create, but that 
should be possible to handle!

On Tue, Oct 03, 2000 at 11:48:55AM +0000, Fergus Henderson wrote:
> address@hidden (Quinn Dunkan) writes:
> 
> >The FILE class has open_for_this, open_for_that, etc. which are just wrappers
> >around various fopen modes.  I'm curious as to why it doesn't simply provide 
> >a
> >open(fname:STR, mode:STR):SAME or create method.
> 
> Probably for the same reasons that Ada, C++, Haskell, and Mercury all
> provide their own interface rather than using fopen() mode strings.
> 
> >I see the mode string in
> >fopen as being a "little language", like printf format strings, that becomes 
> >a
> >large set of unwieldy methods when moved to another language.
> >
> >mode string pros:
> >compact
> >easy to read
> >easy to write
> >
> >cons:
> >must be learned for "easy to read" and "easy to write" to be true
> 
> How many C programmers know what "a+b" means in a mode string?
> 
> I would argue that the Sather/Ada/C++/Haskell/Mercury approach is more
> readable than the C approach.
> 
> Readability is much more important than writability,
> because code is written once, but during code reviews
> and maintenance it is read many many times over.
> 
> Additional cons for the C approach include
>       - error-prone (e.g. you might try using "rw"
>         to open a file in for both reading and writing)
>       - can lead to portability problems
>         (e.g. some implementations may silently accept
>         "rw" and do what you expect, while others may
>         do something that you don't expect and don't want;
>         also omission of "b" causes a lot of porting
>         problems between Unix and non-Unix systems)
> 
> -- 
> Fergus Henderson <address@hidden>  |  "I have always known that the pursuit
> WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
> PGP: finger address@hidden        |     -- the last words of T. S. Garp.

-- 
-- ______________________________________________________
-- JESUS CHRIST IS LORD!
--          To Him, even that machine here has to obey...
--
-- _________________________________Norbert "Nobbi" Nemec
-- Hindenburgstr. 44  ...  D-91054 Erlangen  ...  Germany
-- eMail: <address@hidden>   Tel: +49-(0)-9131-204180



reply via email to

[Prev in Thread] Current Thread [Next in Thread]