Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
shortening Python code
#11
Are the users of your libraries generally also helping you develop them? I can see why documentation like that in that case is useful. Otherwise, users who aren't developing them are likely more interested in what the functions do, rather than how they're doing it. Good abstractions with good names and automated tests help this. Automated tests are better than comments for this sort of thing because they have the benefit that they will fail if the behaviour doesn't match. Well, should would be a better word. Tests need to be written in a way that actually check the code does what it's supposed to. This sounds obvious, but I've seen submissions for my company's programming test where candidates write tests, but all those tests do is check that no exception is thrown by the functions. This means they're useless, because you could write whatever logic in those functions, even create some bugs and the tests wouldn't fail.
Reply
#12
I care only about readability.

If I find a line too long to separate visually and easy the code fragments in order to know what I am looking at I move some of it to a new line.

Don't bother to count less than 80 characters line or puting some rulers
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#13
(Oct-23-2022, 07:01 AM)ndc85430 Wrote: but all those tests do is check that no exception is thrown by the functions.
indeed, those would be poor tests. poor, at a minimum. or possibly outright wrong.

the test for celcius_to_fahrenheit() certainly must not raise an exception for valid cases. but it must also perform the correct calculations in all the value types intended to be supported which should include all non-complex numeric types that can represent temperature.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020