5 ms·
I particularly like this bit: from returns.result import Result, Success, Failure def find_user(user_id: int) -> Result['User', str]: user = User.
by dr_kiszonka 4y ago
I particularly like this bit:
from returns.result import Result, Success, Failure
def find_user(user_id: int) -> Result['User', str]:
user = User.objects.filter(id=user_id)
if user.exists():
return Success(user[0])
return Failure('User was not found')
user_search_result = find_user(1)
# => Success(User{id: 1, ...})
user_search_result = find_user(0) # id 0 does not exist!
# => Failure('User was not found')
https://returns.readthedocs.io/en/latest/pages/result.html https://returns.readthedocs.io/en/latest/pages/result.html
- pharmakom 4y agoPython is deeply incompatible with this style. No do-notation, crippled lambdas, slow function calls. If you want to write Rust/OCaml maybe use Rust or OCaml?
- intelVISA 4y agoHow am I going to PIP all those CVEs with dune/cargo?!
- baq 4y agoCurrent Python is. Languages evolve. Nothing wrong in importing good ideas from other languages, bonus points if long standing warts get fixed at the same time.
- Kwpolska 4y agoI don't think Python is ever going to get multi-line/fully-featured/less-ugly lambdas.
- dragonwriter 4y agoVery many languages only have single-expression lambdas, Python isn’t unusual in that, its just that nontrivial single expressions in Python are extremely ugly (to the point where most people think they are much more limited than they are.) The lambda issue in Python isn’t really about lambdas, but the readability and expressiveness of expressions.
- pharmakom 4y agoPython would be so much better if it was expression orientated. I don’t think it would even detract from Pythons design goals at all.
- dragonwriter 4y agoI agree, but given the Zen and the disruption when print moved to a function from a statement, I don’t see a good evolution path to get much closer. OTOH, small improvements in what can cleanly be expressed in an expression could still have big payoffs for Python.
- erik_seaberg 4y agoImporting from __future__ worked well to make language changes opt-in. It was a mistake to start breaking backward compatibility by default.
- Kwpolska 4y ago> Very many languages only have single-expression lambdas Which languages are those? Java, C#, C++, Rust, JS, Swift, Kotlin, Scala, Ruby, PHP, and Go all allow defining multi-line anonymous functions that can contain any statement normally allowed in a function.
- datadeft 4y agoIt was not designed to those things and there are many other languages that are way better in many aspects of software engineering than Python ever will be with type checks and other relatively minor improvements. I consider Python as the lingua francua that gets the job done, easy to train new programmers to use it and there are several C/C++/Fortran/Rust libraries written so it can do things performant enough to be relevant. There was nothing new introduced by Python that other languages took from it which shows that there is nothing groundbreaking about it. I think Python is the quick and dirty, not too smart glue languages with a mediocre module system and many footguns. I think Sussman pointed out that the world needs more library gluers than it needs very smart software engineer who create those libraries. Python is the proof of this theory.
- pphysch 4y ago> There was nothing new introduced by Python that other languages took from it which shows that there is nothing groundbreaking about it. Not strictly true, Python's approach to readability (syntax) inspired languages like Kotlin, GDScript, to name a couple. But the bigger picture is that Python has spawned prominent frameworks/DSLs in virtually every domain, so to suggest that it is a dead-end of innovation is not quite correct.
- _a_a_a_ 4y agoseems you can now sort of write Scala in Python
- esafak 4y agoThe language that's winning by setting an example. edit: I like Scala. Being emulated is a compliment. Come on guys, no need to throw a fit!
- adamckay 4y agoI really don't. Raise a `NotFound` exception in the method and catch that instead when you're calling...
- Hasnep 4y agoI prefer having failures in the type signature so the type checker makes sure they're handled, although it depends on the failure, occasionally I just raise an error like you suggest.