What's the deal with Deno? We talk with a major contributor to find out. Listen now.

New answers tagged

1

Separation of Concerns Your function is doing too much. It is: Converting the float to a fraction Converting the fraction to a string of digits Printing the string of digits You should separate these. Float to Fraction First, let's move the float-to-fraction code into its own function. from typing import Tuple def float_to_fraction(value: float) -> ...


3

Value Objects The following shows what most users would consider unexpected behaviour: from ccomplex import Complex a = Complex(5, 4) + Complex(3) b = a a.re = -a.re print(b) # "-8 + 4i" Values are usually considered to be immutable. Since Python uses objects to represent values, and objects have identity which can be shared, the best practice ...


4

inLeadingZeros I find dubious; wrong name probably 0x00_00_03_44 would be output as "344" whereas conventional would be a two-fold "0344" (or even interspaced as "03 44"). The reason that from left-to-right one can create a byte by two chars. The exceptional case probably can be dealt with in front. Error if (digit != 0) { ...


3

Looks pretty good. I see you implemented modulus in mod. It's also called absolute value, and that's the name Python uses. If you implement __abs__, then Python's abs function can use it. Then abs(Complex(3, 4)) would give you 5.0. Just like Python's own abs(3 + 4j) does. Another useful one is __bool__, which lets you declare zero as false, as is standard in ...


3

It takes some time to navigate through all the error logging to reach the code that actually does the line ending conversion. Avoiding standard library functions doesn't mean you can't write some utility functions yourself, like a wrapper around WriteConsoleW to prevent passing all those arguments throughout the code.


5

Overall design Code makes heavy use of data as a file with a known size. I'd favor a stream approach where the conversion is done as data arrives and then written, negating the need for any large buffers. mode_overwrite design In my opinion, re-writing a file should not destroy the original until after the new file is completely written. I'd favor writing ...


Top 50 recent answers are included