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

TIFF wrapper compatibility broken due to all function names being lowercase. #51

Closed
pieleric opened this issue Nov 28, 2016 · 7 comments

Comments

@pieleric
Copy link
Contributor

The latest git HEAD, since commit bdce54f, has broken compatibility with all our code.
All the methods of the TIFF class have been renamed to only be lowercase.

So simple code like this is broken:

    f = TIFF.open(fn, mode='r')
    if f.IsTiled():
        bits = f.GetField('BitsPerSample')
        sample_format = f.GetField('SampleFormat')
        typ = f.get_numpy_type(bits, sample_format)
        im = f.read_tiles(typ)
    else:
        im = f.read_image() # Fist image

Now, both .IsTiled() and .GetField() don't exist, as they've been renamed to .istiled() and getfield().
Note that the Python convention is to either have CamelCase, or lower_case names, however, it is not recommended to use lowercase without separation (because it makes names hard to read).

IMHO, in this case, as it's wrapper doing a simple mapping of C functions to Python methods, it makes sense to use the same convention as the C library, so that it's more obvious that they are just direct mapping. For the more complex methods, like read_image(), it's also fine to follow a different convention, as they are not a direct mapping of the C library, but additional helper code.

So, I'd suggest to revert the renaming of the methods. If needed, I can provide a patch.

@pearu
Copy link
Owner

pearu commented Nov 28, 2016

Hi @jat255, @pieleric !

I agree that compatibility has been broken by the mentioned commit and we'll need to fix it. Actually, there are more than 20 methods that names were changed. All need a fix.

However, we need to take into account that now there exists users who use CamelCase and users who use lowercase in their applications.

While I would not normally use CamelCase for method names in Python programs, in this particular case, indeed the convention was taken from C library. Introducing lower_case would be third conventions that would make things even more confusing, IMHO.

I see the following possible solutions:

  1. Use CamelCase and lowercase in parallel.
  2. Use CamelCase and lowercase in parallel but give warning to a user when it uses lowercase: lowercase naming will be removed in future versions.
  3. Use CamelCase and lowercase in parallel but give warning to a user when it uses CamelCase: CamelCase naming will be removed in future versions.

My preference order of solutions is 1, 2, 3.

What do you think?

Best regards,
Pearu

@geekofhearts
Copy link
Collaborator

geekofhearts commented Nov 28, 2016 via email

@cmbruns-hhmi
Copy link

I agree with @pieleric that lowercasewithoutunderscores is a terrible naming convention. Perhaps having both CamelCase and lower_case_with_underscores would be OK, as long as someone is willing to maintain this convention.

It looks to me like commit bdce54f was an overeager underthought commit. It combines so many changes together in one giant blob. The commit message claims to be supporting PEP8. But, for example, the systematic removal of spaces around the assignment operator is the exact opposite of what PEP8 demands. (The only place such spaces should be removed is when setting named argument values in function calls.)

@pearu
Copy link
Owner

pearu commented Nov 28, 2016

When using Python magic, let us be explicit:

def CamelCase(...):
  ...
camelcase = camel_case = CamelCase

@jat255
Copy link
Contributor

jat255 commented Nov 28, 2016

@cmbruns-hhmi I agree completely. I needed this library to work for my compatibility and it hasn't been updated in years, so I just submitted what I needed. Feel free to change it however is needed. No offense taken...

@pieleric
Copy link
Contributor Author

If it was just up to me, I'd just drop the lowercase method names, as they've never been there in any stable release (as far as I understand).
However, as it's not in any of the options @pearu is proposing, then I'd just tend toward solution 1 and keep the code simple. In particular, let's not bring in a third name for the methods (ie, lower_case), that really not usual for Python libraries to offer every possible naming convention for all the methods.

@pearu
Copy link
Owner

pearu commented Nov 28, 2016

Thanks, @pieleric!

@pearu pearu closed this as completed Nov 28, 2016
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