-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Closed
Labels
Description
by vomjom:
I propose that Go implements a Reader interface for files that are read-
only and a Writer interface for files that are write-only.
The motivation is this type of program:
package main
import "os"
func main() {
f, _ := os.Open("test.out", os.O_CREATE | os.O_RDONLY, 0644);
defer f.Close();
f.WriteString("foobar");
}
It succeeds in running, but doesn't output anything. This kind of error
can be caught safely at compile-time if WriteString() only belonged to a
Writer interface.
Specifically, here's my proposal:
1. Get rid of os.O_RDONLY and os.O_WRONLY.
2. Keep os.Open. os.Open would mean that you are opening a file for both
reading and writing.
3. Make an os.OpenRead() and os.OpenWrite(). These would return read only
and write only interfaces to files.
These Reader and Writer interfaces should be generic enough that they can
be used in other settings (sockets and pipes, for example).