• 0 Posts
  • 25 Comments
Joined 1 year ago
cake
Cake day: July 7th, 2023

help-circle








  • I get the point the author is coming from. When I was teaching first year engineering students programming, the one on the left is how everyone would write, it’s simply how human intuitively think about a process.

    However, the one on the right feels more robust to me. For non trivial processes with multiple branches, it can ugly real quick if you haven’t isolated functionalities into smaller functions. The issue is never when you are first writing the function, but when you’re debugging or coming back to make changes.

    What if you’re told the new Italian chef wants to have 15 different toppings, not just 2. He also got 3 new steps that must be done to prepare the dough before you can bake the pizza, and the heat of the oven will now depend on the different dough used. My first instinct if my code was the one on the left, would be to refactor it to make room for the new functionality. With the one on the right, the framework is already set and you can easily add new functions for preparing the dough and make a few changes to addToppings() and bake()

    If I feel too lazy to write “proper” code and just make one big function for a process, I often end up regretting it and refactoring it into smaller, more manageable functions once I get back to the project the next day. It’s simply easier to wrap your head around

    bakePizza() 
    box()```
    than reading the entire function and look for comments to mark each important step. The pizza got burned? Better take a look at `bakePizza()` then.







  • Clean code would have indentation though, and you can use whatever space you want as indentation. Bonus points if you use tabs so that others with special needs can configure the tab length on their end.

    And I don’t think I’ve encountered an indentation error since the day I learned the language. How often do you encounter that error when writing python scripts? Sounds more like a theoretical problem than something anyone used to python would encounter.



  • A round number is a number that is the product of a considerable number of comparatively small factors (Hardy 1999, p. 48). Round numbers are very rare. As Hardy (1999, p. 48) notes, “Half the numbers are divisible by 2, one-third by 3, one-sixth by both 2 and 3, and so on. Surely, then we may expect most numbers to have a large number of factors. But the facts seem to show the opposite.”

    A positive integer n is sometimes said to be round (or “square root-smooth”) if it has no prime factors greater than sqrt(n). The first few such numbers are 1, 4, 8, 9, 12, 16, 18, 24, 25, 27, 30, 32, … (OEIS A048098). Using this definition, an asymptotic formula for the number of round integers less than or equal to a positive real number x is given by N(x)∼(1-ln2)x+O(x/lnx)

    (Hildebrand).

    https://mathworld.wolfram.com/RoundNumber.html

    Alternatively, a number rounded off to a given precision in whatever numeral system you are using. E.g. ten in decimal may be round if you are dealing with small numbers in the decimal system, but it wouldn’t be particularly round if you were dealing with large numbers or hexadecimal.