• 0 Posts
  • 51 Comments
Joined 9 months ago
cake
Cake day: September 24th, 2023

help-circle
  • Yeah I have yet to really use Deno in anger because so many people are like “but Python exists!” and unsurprisingly we now find ourselves with a mess of virtual environments and pip nonsense that has literally cost me weeks of my life.

    Though if you’re using Numpy that source like “proper work” not the infrastructure scripting we use Python for so I probably would go with Rust over Deno. I don’t know of mature linear algebra libraries for Typescript (though I also haven’t looked).

    IMO probably the biggest benefit of Rust over most languages is the lower number of bugs and reduced debugging time due to the “if it compiles it probably works” thing.


  • that’s a tough sale to the product team

    Sounds like you’re not the boss enough!

    I agree Rust has a pretty steep learning curve so it’s definitely reasonable to worry about people learning it, especially existing employees. Though I don’t really buy the “easier to hire people” argument. There are plenty of Rust developers actively looking for Rust jobs, so I suspect you get fewer candidates but the ones you do get are higher quality and more interested.

    But anyway I don’t think that argument holds for Deno. Typescript is in the same difficulty league as Python. Anyone that knows Python should be able to transition easily.







  • I can give you some basic Python set-up advice (which is hard-won because nobody tells you this stuff):

    1. Use pyproject.toml, not requirements.txt. It’s better and it’s the recommended way.
    2. Always use type annotations. I saw you used it a bit - well done! But just use it everywhere. Add declarations & type annotations for your class member variables. You’ll thank me later! Also prefer Pyright to Mypy; it is far far better (and the default for VSCode).
    3. I would recommend using Black to autoformat your code. It’s easily the best Python formatter. You can automate it using pre-commit.
    4. ALWAYS PUT MAIN IN A FUNCTION. You should not run any code at a global scope. Do it like this:
    def main():
      ...
    
    if __name__ == "__main__":
        main()
    

    There are two reasons:

    1. Generally it’s good to keep variables to the smallest scope possible. Putting everything in a global scope will just mean people start using it in their functions, and then you have a mess.
    2. Any code you put in a global scope gets run when you import a module. Importing a module should not have any side effects.

    Other minor things:

    1. Path has a crazy/neat override of the / operator so you can do Path("foo") / "bar" / "baz.txt".
    2. Don’t use assert for stuff that the user might reasonably do (like not choosing a background image). assert is meant to be for things that you know are true. You are asserting them. Like “hey Python, this is definitely the case”.
    3. TK is an ancient shitty GUI toolkit. I would recommend QT instead (though it will probably be more pain to set up).


  • That’s not really true. C# and Java are reference-based, uses GC and can be multithreaded, and are very comparable to Rust/C++/C performance. Certainly no more than twice as bad. Whereas Python is probably 50x as bad.

    The real answer is that Python developers have deliberately avoided worrying about performance when designing the language, until maybe 2 years ago. That means it has ended up being extremely dynamic and difficult to optimise, and the CPython implementation itself has also not focused on performance so it isn’t fast.

    But I agree the aim of offering C/C++ speed is never going to be met with Python syntax.








  • Are you suggesting that you prefer to do the type validation upon execution?

    No. But I would like them to actually be done! If you just write some Python code and put type hints in it and don’t do anything else then those types are not checked at all. It requires some set up and a third party tool to use them properly.

    It is a bit more complicated than that. Here’s a quote

    That quote is exactly what I was saying. It does not require any particular processing or type hints.

    Type checkers can and do differ in whether they accept a particular piece of code.


  • Salty huh

    Very. Python’s shit tooling has cost me literal weeks of my life. It’s so bad. Have you ever used Go or Rust? If not go and try them and then you will realise that it doesn’t have to be like that.

    Saying you need to set up type hinting in Python shows that you’re the one assuming it’s a hassle like TS

    I’m not assuming. I have done this. It is absolutely a hassle. TS isn’t exactly hassle free but it’s still better than Python.

    where you need a different runtime to have access to something the language (JS) should have provided from the start.

    You mean like MyPy or Pyright? At least Typescript defines the semantics of its type hints. Python only defines the syntax! You can have multiple type checkers that conflict with each other!

    Everything you need is provided by typing, which is included in a Python install. Just import it and start using it.

    If you do that, nothing will actually be checked. You need to explicitly run pyright in CI.


  • Yes it is good because it’s completely true. Of course this question is going to attract a lot of Python developers who haven’t used Typescript and don’t know what they’re missing so I’m not surprised by this response.

    Most Python developers still don’t even use static type hints. I guess partly because the Python tooling catastrophe makes it a quite a pain to set them up.


  • FizzyOrange@programming.devtoPython@programming.devPython beginner
    link
    fedilink
    arrow-up
    2
    arrow-down
    14
    ·
    edit-2
    1 month ago

    (Ignore the downvotes on this comment btw; I’ve obviously touched a nerve with Python developers.)

    Depending on what you want to do I would consider learning JavaScript instead:

    • You already have a JavaScript environment in your web browser (just press ctrl-shift-J).
    • If you want to do anything web related you basically have to learn and use JavaScript .
    • The Python tooling story is a complete disaster. If you want to spend all your time fight your tools Python is for you. Especially on Windows. JavaScript (which uses NPM) is not perfect but it is significantly better.
    • It’s like 50x faster.
    • Overall JavaScript (with Typescript anyway, which you can learn later) is a better language than Python. A notable exception is Python’s support of arbitrary precision integers. Using 64-bit integers in JavaScript is a right pain. But that won’t remotely be an issue for a beginner.

    There are a couple of situations I would maybe pick Python:

    • AI. For better or worse (it’s worse) the entire AI ecosystem is based around Python so you don’t really have much choice here if you want to do AI stuff.
    • Scripts to automate integration of third party services. Generally more common for projects like AWS or whatever to provide Python libraries than JavaScript ones, so it can be easier in Python.

    It really depends on what kind of projects do you want to do?