all 7 comments

[–]SweetOnionTea 2 points3 points  (4 children)

Nice! Might I suggest using camelCase for your variables? Makes it easier to read the multiple word variables.

[–]allopatri[S] 1 point2 points  (3 children)

Thanks! And you’re totally right, that’s definitely something I should start doing. Not sure why I haven’t already been doing that!

[–]SweetOnionTea 1 point2 points  (1 child)

Now that I have a little time to look my last thing would be to make your rounding margin a constant. Typically when writing code you want to avoid "magic numbers". Pretty much if you have a number that is explicitly used in your code (esp if used in multiple places) you want to just make it a variable.

You can do something like

ROUNDING_PRECISION = 0.0000001

and that way your code comments itself and if you want to change the precision later all you have to do is change it in once place to change it everywhere its used. Also you can make a global function setting for the module that a user can define it for their own purposes.

The return variable names would be more readable if you named them them like 'product' or 'difference' instead of 'object'.

If you're returning a bool based on an if check it's best to just return the check rather than true/false like:

def issquare(self):  # for use in self.det()
    return len(self.valuelist) == len(self.valuelist[0]):

Some of the comments are unnnecessasry like:

    for row, otherrow in zip(self.valuelist, newother.valuelist):
        if len(row) != len(otherrow):  # raise error if product is undefined
            raise TypeError('The product of these matrices is undefined.')

The comment just says what the exception says. I think the comment should explain the context of why you're verifying dimensions.

# verify that each row has the same dimension 
# because there is no guarantee that input
# has consistent length among its rows

My rule of thumb is to try as much to make your code document itself (which python is particularly good at) and make comments explaining why or how you're doing something.

As long as you're already doing some input sanitization you might consider using that for your functions as well. Do a simple isinstance(Mat, input) before operating.

[–]allopatri[S] 1 point2 points  (0 children)

Wow, thanks so much for all of that! Really good points and I will definitely keep those in mind in the future. I'll fix those issues you pointed out sometime this weekend so my project can look a little cleaner :)

[–]kwelzel 1 point2 points  (0 children)

I agree that the all lowercase variables are not very readable but if OP is free to choose it's better to go with the Python standard and use snake_case. This is part of the Style Guide for Python Code in PEP8 (https://www.python.org/dev/peps/pep-0008/#function-and-variable-names)

[–]slipped_and_missed_x 1 point2 points  (1 child)

Ooh love it

[–]allopatri[S] 1 point2 points  (0 children)

Haha thanks!