Am 06.09.2011, 17:39 Uhr, schrieb Steven Schveighoffer
<[email protected]>:
On Tue, 06 Sep 2011 11:11:27 -0400, Andrei Alexandrescu
Honest, C's openmode strings have been around for so long, they hardly
confuse anyone anymore. I'd rather use "rw" and call it a day.
That's not a valid fopen string ;)
Sorry, but I had to laugh. There could not have been a better counter
example for using fopen strings. I can live with them, but it is one of
the bad designs in C that could use an alternative.
Enums are used in: Unix, Windows, Delphi, Haskell, Lisp, C++, C#,
OCaml, Go
fopen strings are used in: C, Ruby, PHP, Python, NodeJS
Java has reinvented mode strings:
http://download.oracle.com/javase/1.4.2/docs/api/java/io/RandomAccessFile.html#RandomAccessFile(java.io.File,
java.lang.String)
Other languages also distinguish only between a fixed set of cases, like
read, write and append. I found Scala and Perl to do that.
In the end a string just like an enum with the enum being statically
checked and the string being shorter. Every character corresponds to an
'ored' enum value. They can both be extended with flags that work with
Windows and Posix, like 'create only if non-existent' or hints that may
work on one system only, like exclusive access.