(May-06-2019, 08:57 AM)buran Wrote: Again, I can just speculate, but I think it's mess exactly because you try to keep everything in one function and thus use a lot of if statements depending on type. I think, even with some repeating parts, that you cannot put in a separate function to avoid repeting, it will be easier and you will end up with more readable and structured code to deal if for each type you have different function and it's strightforward
in this case there is just one if test for the case of Decimal to tweak the formatting position a bit. the rest of it is the same, though i will need to do more when i include complex and probably Fraction.
(May-06-2019, 10:12 AM)Gribouillis Wrote:for the major types there's about 80 lines of code where one of the types is handled slightly different for certain values. i don't want to have 4 copies of this code (where 1 of them has one line slightly different). if i have to make a general logic change, i would have to keep all copies in sync ... increased maintenance. and reading the code of 6 to 8 pages worth the reader won't necessarily see the difference right away. the ideal would be to have a single expression with a test for type of argument data that the compiler can isolate and make the 4 type-selected functions for.buran Wrote:you try to keep everything in one function and thus use a lot of if statements depending on typewhich is a blatant non pythonic attitude.
i'm still a firm believer in the idea that a single thing should be expressed just once no matter how many places it is used, especially when differences in different places can throw things out of sync. and i believe in making code clear and easy to read, including the difference in logic when that difference may be too subtle to notice.
the cost of development and the cost of maintenance are what i try to reduce the most. the cost of others trying to learn from this code is a secondary cost to reduce.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.