Skip to content

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

Open

Description

@Mahi

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.

Activity

  1. jehna commented on Mar 30, 2017

    @jehna
    Contributor

    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.

  2. jehna commented on Mar 30, 2017

    @jehna
    Contributor

    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

  3. Mahi commented on Mar 30, 2017

    @Mahi
    Author

    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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions