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

Make instance naming optional #952

Closed
dvdsgl opened this Issue Mar 10, 2015 · 12 comments

Comments

Projects
None yet
8 participants
@dvdsgl
Copy link

dvdsgl commented Mar 10, 2015

I apologize if this issue has already been discussed ad nauseum, and I'm sure the reasoning behind instance naming is robust, but I need to share my experience:

After adding 50 instance declarations to my app over the past few days, none of which I plan to reference from JavaScript, I felt like I was doing work that the compiler should be doing for me when writing down typeclass instance names. I'd really appreciate it if instance names were optional, so if I omit the name like:

instance Show Foo where
  show (Foo x) = x

Then the compiler comes up with some unique name for this that I never need to worry about. If I want to provide a name for any reason, I can continue to do so with the current syntax.

@paf31

This comment has been minimized.

Copy link
Member

paf31 commented Mar 11, 2015

The compiler used to do this, but the names were so ugly that they made the code practically unreadable at times. Making them optional is an interesting option.

@jdegoes

This comment has been minimized.

Copy link

jdegoes commented Mar 11, 2015

👎 Will lead to bad code generation and error messages. For me personally, I can type 50 names in less than a minute -- typing has never been a bottleneck for me, it's more thinking about how to design the code and also debugging it. Names interfere with the latter.

@andyarvanitis

This comment has been minimized.

Copy link
Contributor

andyarvanitis commented Mar 12, 2015

In the context of the C++11 backend, the instance names aren't used, so I've also been thinking optional names would be nice. I can't speak to what effect it would have in JS, or on the error messages. Would a simple hash (if optional and not provided) work without negatively affecting much? It seems that as long as the error messages include line numbers it would be ok, but I'm not an expert on it.

@joneshf

This comment has been minimized.

Copy link
Member

joneshf commented Mar 12, 2015

I'd say it depends on what you're wanting out of the backend. If you want to generate code that others will still use, then optional names is a bad idea. If you don't care what people do with the generated code, then enforcing names is a good thing. Since the current js backend still wants people to read the output, keeping names mandatory is a good idea. If a different backend (could still be js, could be C++11) didn't care about readable output, then names wouldn't even be necessary.

@andyarvanitis

This comment has been minimized.

Copy link
Contributor

andyarvanitis commented Mar 12, 2015

Not another argument for or against, but just to clarify: in the C++11 backend, the instance names do not appear at all in the generated code.

Also to clarify: readable generated code is definitely still a goal of the C++11 backend.

@user471

This comment has been minimized.

Copy link

user471 commented Jul 18, 2015

I also would like to see this feature. Compiler can just generate guid. If someone needs a instance name he can simply add it. Why to force people to do something if they don't need it.

@puffnfresh

This comment has been minimized.

Copy link
Contributor

puffnfresh commented Jul 18, 2015

I'm of course a 👍

@paf31 paf31 closed this Aug 8, 2015

@michaelficarra

This comment has been minimized.

Copy link
Contributor

michaelficarra commented Aug 8, 2015

Why was this closed?

@paf31

This comment has been minimized.

Copy link
Member

paf31 commented Aug 8, 2015

I closed it because this is one of a few issues which seem to crop up every few months. The only reason for it seems to be that it's a mild inconvenience to choose and type a name, and I can think of three reasons against:

  • Choosing a naming scheme which guarantees global uniqueness and is pleasant to read is difficult. I don't want hashes or GUIDs in generated code.
  • Renaming a class or type has the possibility to break working FFI code.
  • As @jdegoes mentioned, poor error messages.

I generally like to leave these things open for discussion, but we don't seem to be able to reach a consensus, and at some point, a decision has to be made. I don't think it's worth it, sorry.

@jdegoes

This comment has been minimized.

Copy link

jdegoes commented Aug 8, 2015

I think this is the best decision. Seriously, we probably spent more time on this ticket than any of us will spend writing instance names in a whole lifetime. 😉 😆

@user471

This comment has been minimized.

Copy link

user471 commented Aug 8, 2015

we probably spent more time on this ticket than any of us will spend writing instance names in a whole lifetime

What if ps will become popular? Then thousands programmers will write this useless names.

@paf31

This comment has been minimized.

Copy link
Member

paf31 commented Aug 8, 2015

Locking this, discuss it on IRC if you like.

@purescript purescript locked and limited conversation to collaborators Aug 8, 2015

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.