Skip to content

proposal: More Type-Safe File Handling #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gopherbot opened this issue Nov 13, 2009 · 3 comments
Closed

proposal: More Type-Safe File Handling #142

gopherbot opened this issue Nov 13, 2009 · 3 comments

Comments

@gopherbot
Copy link
Contributor

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).
@gopherbot
Copy link
Contributor Author

Comment 1 by vomjom:

Hmm, it looks like the necessary interfaces already exist in the "io" package.  Also, 
my desired behavior can be emulated simply by typing declaring "f" as "var f 
io.ReadCloser" in my example and using the appropriate functions from "io".
So, this proposal isn't really necessary.  Please close it.  Sorry for any 
inconvenience.

@gopherbot
Copy link
Contributor Author

Comment 2 by vomjom:

By the way, I think it would be useful if users could close issues that they reported.

@agl
Copy link
Contributor

agl commented Nov 13, 2009

Comment 3:

Status changed to Invalid.

mwhudson pushed a commit to mwhudson/go that referenced this issue May 22, 2015
Also alow more CMP variants.

	CMP $0, ZR           eb1f03ff	negs	xzr, xzr
	CMP $5890452, ZR     1800019b	ldr	w27, 0x00000034
	                     eb1b03ff	negs	xzr, x27
	CMP ZR, ZR           eb1f03ff	negs	xzr, xzr
	CMP R1, ZR           eb0103ff	negs	xzr, x1

	CMP ZR, R3           eb1f007f	cmp	x3, xzr
	CMP ZR, RSP          eb3f63ff	cmp	sp, xzr

	CMP $0, RSP          eb3f63ff	cmp	sp, xzr
	CMP $452, RSP        f10713ff	cmp	sp, #0x1c4
	CMP ZR, RSP          eb3f63ff	cmp	sp, xzr
	CMP R1, RSP          eb2163f	cmp	sp, x1

These are illegal:
	CMP RSP, ZR
	CMP RSP, R1

Fixes golang#142
Fixes golang#143
@mikioh mikioh changed the title Proposal for More Type-Safe File Handling proposal: More Type-Safe File Handling Aug 31, 2015
@golang golang locked and limited conversation to collaborators Sep 4, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants