ubsuny / CP1-24-HW3

Homework 3 template for CP1-24
1 stars 16 forks source link

Resistance in a wire functional program. #28

Closed kylemasc917 closed 6 days ago

kylemasc917 commented 1 week ago

This is the folder and modules that contain the Resistance in a Wire algorithm which uses functional programs outlined in the homework assignment to calculate the resistance in a wire for an inputted resistivity constant, cross-sectional area, and various lengths of wire. As well as the unit test module for the algorithm that checks against expected values and error such as a zero input or no input at all.

kylemasc917 commented 1 week ago

I've deleted the binary files and made the requested changed aside from the lambda function as seemingly no matter how I implement it pylint views it as redundant.

laserlab commented 1 week ago

I've deleted the binary files and made the requested changed aside from the lambda function as seemingly no matter how I implement it pylint views it as redundant.

Yeah, I tried multiple ways now too since my suggestion doesn’t work. It just looks like that a lambda functions serve any purpose here … I guess a better way would be to give the resistance generator the function for calculating the resistance:

resfunc = lambda rho, length, area: rho * length / area)
def resistance_generator(rho, area, lengths, resfunc):
    """Generator function that creates resistance values of a wire of different lengths"""
    # Generate resistance for each length by applying the lambda function
    for length in lengths:
        yield resfunc(rho, length, area)
kylemasc917 commented 1 week ago

I'm troubleshooting the changes above you suggested but it still gives the pylint error and while the algorithm works fine with these changes the unit test has broken down in a way that I'm unsure how to fix, and the resfunc is giving a pylint error in itself lowering the score further.

laserlab commented 1 week ago

I'm troubleshooting the changes above you suggested but it still gives the pylint error and while the algorithm works fine with these changes the unit test has broken down in a way that I'm unsure how to fix, and the resfunc is giving a pylint error in itself lowering the score further.

Thanks for checking. I guess I’m out of ideas then too, maybe using a lambda function here is just not useful and one should just use a real function in this case. Do you want to discuss your code in class? It would be a good example for how to use a function in a function.

laserlab commented 1 week ago

I'm troubleshooting the changes above you suggested but it still gives the pylint error and while the algorithm works fine with these changes the unit test has broken down in a way that I'm unsure how to fix, and the resfunc is giving a pylint error in itself lowering the score further.

I just checked your lint score now and it is up to 9.58/10

laserlab commented 1 week ago

Yes this gives me a 10/10:

…
    def resfunc(rho, length, area):
        return rho * length / area
    # Generate resistance for each length by applying the lambda function
    for length in lengths:
        yield resfunc(rho, length, area)

and with a direct generator it could be: yield (resfunc(rho, length, area) for length in lengths) but that’s probably not very readable

kylemasc917 commented 1 week ago

I'm troubleshooting the changes above you suggested but it still gives the pylint error and while the algorithm works fine with these changes the unit test has broken down in a way that I'm unsure how to fix, and the resfunc is giving a pylint error in itself lowering the score further.

Thanks for checking. I guess I’m out of ideas then too, maybe using a lambda function here is just not useful and one should just use a real function in this case. Do you want to discuss your code in class? It would be a good example for how to use a function in a function.

Yes I wouldn't mind discussing it but what version would you prefer the current pull request version, the updated version with the resfunc and broken unit test, or something else?

laserlab commented 1 week ago

Would be best to discuss all versions