Skip to content
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

alternative names for single-letter constructors #29

Closed
radix opened this issue Mar 19, 2015 · 12 comments
Closed

alternative names for single-letter constructors #29

radix opened this issue Mar 19, 2015 · 12 comments

Comments

@radix
Copy link
Contributor

radix commented Mar 19, 2015

The single-letter constructors can be pretty annoying

  • they're hard to search for in a module
  • they very easily conflict with local variable names

It'd be nice if we had alternative, longer names for v, s, m, and b.

@radix
Copy link
Contributor Author

radix commented Mar 19, 2015

For m, I can imagine just overriding pmap itself to allow **kwargs in addition to the positional arguments: pmap({'a': 1}, b=2) -> pmap({'a': 1, 'b': 2})

however, this doesn't work for v, s, and b, because a single-element *args would be ambiguous, so that's not a generalizable idea...

@tobgu
Copy link
Owner

tobgu commented Mar 19, 2015

I see your point but also value the shortnames for their conciseness.
Some (not necessarily good) alternatives:

import pyrsistent as p
p.v(1, 2, 3)
from pyrsistent as pv
pv(1, 2, 3)

Make a file with your own aliases and import from that file instead of directly from pyrsistent.

If you do come up with a good set of aliases I'm willing to include them. I don't have any of the top of my head but will think a bit about it.

@tobgu
Copy link
Owner

tobgu commented May 5, 2015

No really good ideas for this one as of yet. If you like living on the edge you may want to check out a hack I did a couple of days ago. :-)

https://github.com/tobgu/pyrthon

@frol
Copy link

frol commented Aug 21, 2015

I also find one-letter names a bit weird (un-Pythonic). I'm not sure when pmap, pvector, pset were introduced, but they seem to fix the weirdness and has to be encouraged to be used.

@tobgu
Copy link
Owner

tobgu commented Aug 24, 2015

pmap, pvector, pset, m, v, and s all came to be at the same time. Perhaps the short hands should be deprecated but then a descent alternative must exist. I'm thinking about pushing for https://github.com/tobgu/pyrthon a bit more but I haven't actually tested it extensively myself.

@radix
Copy link
Contributor Author

radix commented Aug 24, 2015

wow, pyrthon is scary :) you could make registration a bit nicer by using a source-file coding declaration, e.g. # coding=pyrsistent, and have the codec do the transformation

@tobgu
Copy link
Owner

tobgu commented Aug 25, 2015

Thanks, will look into the coding option. I've never implemented anything using it before.

@radix
Copy link
Contributor Author

radix commented Aug 25, 2015

Using it this way would definitely be a hack, since the mechanism is meant to be used for specifying the encoding of the source text (e.g. utf-8 vs ascii or whatever), but may be nice compared to having to register the modules externally.

Anyway I don't think I'd inflict either of these solutions on my production codebase, just a thought :)

@eugene-eeo
Copy link

Rust uses Vec; so a nice alternative is to rename them into Vec, Map, Set (although the last one might be a little controversial). Personally I find it a very attractive alternative to the other single-letter solution. At least they're shorter than list or dict ;)

@radix
Copy link
Contributor Author

radix commented Aug 30, 2015

oh, by the way, about that coding thing, I found an old repo where I experimented with it: https://github.com/radix/python-parsing-shenanigans

@manishtomar
Copy link

+1. I don't find the necessity to have single-letter names.

@tobgu
Copy link
Owner

tobgu commented Jun 12, 2018

I will close this issue. I think there are a bunch of projects relying on the single letter initializers, they are not going away because it would break backward compatibility badly.

@tobgu tobgu closed this as completed Jun 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants