335
submitted 10 months ago by 257m@lemmy.ml to c/programming@programming.dev
you are viewing a single comment's thread
view the rest of the comments
[-] escapesamsara@discuss.online 23 points 10 months ago

Python is legitimately the best language by far for the vast majority of non-performance critical tasks, and most tasks that need to be developed for are not performance critical.

[-] navi@lemmy.tespia.org 7 points 10 months ago

I really enjoy typescript these days. Is there a Python typed equivalent?

[-] TerrorBite@meow.social 6 points 10 months ago

Python has had syntax support for type annotations for a while now. The Python runtime doesn't enforce the typing at all, but it can be enforced by a linter or by your IDE. And I believe you can introspect the type annotations at runtime, because they are actually part of the syntax.

There's even an alternative way of doing type annotations through specially formatted comments, just in case you might still need to write code that is backwards compatible with Python 2.

@escapesamsara @navi @programming

[-] TehPers@beehaw.org 2 points 10 months ago

mypy is great, but it doesn't come close to what you can do with TypeScript. I don't think that's necessarily a jab at Python (though TypeVar's limitations do come up here and there), more just throwing TypeScript on a pedestal.

[-] TerrorBite@meow.social 0 points 10 months ago

@TehPers I really wish Python had a satisfying way to do interfaces.

[-] TehPers@beehaw.org 1 points 10 months ago

I really wish Python had multi-line lambdas. Sadly Python is very opinionated in ways I don't quite understand, but I can at least respect while using it.

For interfaces, honestly all I can suggest is using an ABC with only @abstractmethods. It's not perfect, but it's basically what you'd do in C++ anyway. If you're looking for an interface that models data, you could look at dataclasses or TypedDict (depending on what kind of data it is), but it's just not going to match what's possible in TS sadly (mapped types, conditional types, complex union types, custom type guards, etc).

load more comments (2 replies)
load more comments (13 replies)
this post was submitted on 01 Sep 2023
335 points (96.1% liked)

Programming

16210 readers
104 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS