• 0 Posts
  • 19 Comments
Joined 2 years ago
cake
Cake day: September 24th, 2023

help-circle


  • it does a great job yelling at me to keep methods short and simple

    Yes style things like that are what I would consider trivial. I also think those are actively bad lints. Yes methods should be short in general, but making it a hard enforced limit means you end up getting sidetracked by refactoring when you only wanted to add one line to a method.







  • The biggest praise i have is, it follows the UNIX philosophy, do one thing and do it well.

    That isn’t a pro on its own, and it’s also a very wooly rule. Uv does one thing and it does it well - Python project management.

    the issue comes down to resources required to maintain a super complex thing

    They seem to be managing fine. I guess having a company back it is enough. But that is also probably my biggest worry about it - what if Astral goes away (which given their apparent lack of business model I suspect they eventually will)? Hopefully uv is popular enough by that point it won’t die.

    I DONT GIVE TWO SHIATS IF ITS FASTER

    It’s literally 10x faster. I’m not sure what kind of person wouldn’t care about that.




  • Easily above average code for Python. I’m going to pick on one method:

    def _set_float_icon(self, is_floating: bool):
                """ set the float icon depending on the status of the parent dock widget """
                if is_floating:
                    self.float_button.setIcon(self.icon_dock)
                else:
                    self.float_button.setIcon(self.icon_float)
    

    First, Python does have ternary expressions so you can

    self.float_button.setIcon(self.icon_dock if is_floating else self.icon_float)
    

    Second, what does this code do?

    foo._set_float_icon(true)
    

    Kind of surprising that it sets the icon to icon_dock right? There are two easy fixes:

    1. Use *, is_floating: bool so you have to name the parameter when you call it.
    2. I’d probably rename it to _update_float_icon() or something.

    Also use Black or Ruff to auto-format your code (it’s pretty well formatted already but those will still improve it and for zero effort).


  • But don’t you loose polymorphism?

    No. You’ll have to be more specific about what kind of polymorphism you mean (it’s an overloaded term), but you can have type unions, like int | str.

    Your points 1-3 are handled by running the code and reading the error messages, if any

    Not unless you have ridiculously exhaustive tests, which you definitely don’t. And running tests is still slower than your editor telling you of your mistake immediately.

    I probably didn’t explain 4-6 well enough if you haven’t actually ever used static types.

    They make it easier to navigate because your IDE now understands your code and you can do things like “find all references”, and “go to definition”. With static types you can e.g. ctrl-click on mystruct.myfield and it will go straight to the definition of myfield.

    They make the code easier to understand because knowing the types of variables tells you a lot of information about what they are and how to use them. You’ll often see in untyped code people add comments saying what type things are anyway.

    Refactoring is easier because your IDE understands your code, so you can do things like renaming variables and moving code and it will update all the things it needs to correctly. Refactoring is also one of those areas where it tends to catch a lot of mistakes. E.g. if you change the type of something or the parameters of a function, it’s very easily to miss one place where it was used.

    I don’t think “you need to learn it” really counts as slowing down development. It’s not that hard anyway.

    I can understand the appeal for enterprise code but that kind of project seems doomed to go against the Zen of Python anyways, so it’s probably not the best language for that.

    It’s probably best not to use Python for anything, but here we are.

    I will grant that data science is probably one of the very few areas where you may not want to bother, since I would imagine most of your code is run exactly once. So that might explain why you don’t see it as worthwhile. For code that is long-lived it is very very obviously worth it.


  • Just in case that’s a genuine question, the reasons people like static types are:

    1. Catch more bugs.
    2. Catches bugs earlier (while you are writing the code). This is sometimes called “shift left”.
    3. Fewer tests needed.
    4. Code is easier to understand.
    5. Code is easier to navigate.
    6. Refactoring is much easier.
    7. Development speed is faster (due to the above points).

    Often people say it slows development down but it’s actually the opposite. Especially for large projects or ones involving multiple people.

    The only downside really is that sometimes the types can get more complicated than they’re worth, but in that case you have an escape hatch via the Any type.




  • Well, if you want to have Pip-installed tools available generally (e.g. until distros started screwing it up, pip was the best way to install CMake), the suggestion was to have a venv for the user that would be activated in your .bashrc or whatever.

    I think that would work, but then what happens if you want to use a project-level venv, which is really what they’re designed for? If you create and activate a venv when you already have one activated does it all work sensibly? My guess would be that it doesn’t.