Skip to content
New issue

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

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

Already on GitHub? # to your account

Get rid of VerEx() and "from" import #23

Open
Mahi opened this issue Mar 29, 2017 · 3 comments
Open

Get rid of VerEx() and "from" import #23

Mahi opened this issue Mar 29, 2017 · 3 comments

Comments

@Mahi
Copy link

Mahi commented Mar 29, 2017

I personally dislike the current behavior of:

from verbalexpressions import VerEx

foo = VerEx().find(...).anything_but(...)

As opposed to an arguably more Pythonic way:

import verbalexpressions as verex

foo = verex.find(...).anything_but(...)

I would like to contribute and implement the functionality in question, but I need to know first that it would be a welcome change -- else I'd be just wasting everyone's time.

What do you guys think, would it be cleaner to implement it to support module scope function calls? Obviously each call to these module scope functions would still create a new VerEx object internally.

@jehna
Copy link
Contributor

jehna commented Mar 30, 2017

The VerEx format is originally copied from Javascript implementation, which originates from the Javascript's native RegRxp object writing format.

I agree lowercase format would look more pythonic.

@jehna
Copy link
Contributor

jehna commented Mar 30, 2017

On the other hand, you could see verbalexpressions as a "regular expression builder", and thus imitating a string builder.

In this case the Python implementation should be something like:

ve = new VerEx()
ve.first('http://')
ve.maybe('www.')
ve.then('google.com')

...like compared to e.g. Java's StringBuilder

@Mahi
Copy link
Author

Mahi commented Mar 30, 2017

Maybe it's just me, but I find the string building way very unpythonic. It just makes sense to have this instead:

ve = VerEx()
ve = ve.first('http://')
ve = ve.maybe('www.')
ve = ve.then('google.com')

Yes, it's longer, but also more clear and explicit. This is also how SQLAlchemy works -- a very similar library but for building SQL instead of regex.

Also, not supporting the string builder would allow something like this:

generic_ve = VerEx().first('http://').maybe('www.').then('example.com/')
videos_ve = generic_ve.then('videos')
images_ve = generic_ve.then('images')
documents_ve = generic_ve.then('documents')

With the string building example of yours, documents_ve would end up being videosimagesdocuments

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants