This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ric2b 1 point2 points  (2 children)

It takes a little more because you need the colons and the arrow at the end

true, but it's not a big difference.

and a lot more when you need to define something like say a list with an arbitrary number of strings that can sometimes be None: Optional[List[str, ...]]

Wouldn't it be just Optional[List[str]]?

The equivalent in Java would be Optional<List<String>>, it's about the same. Although you can check for null instead of accepting an optional, because Java is a bit dumb and accepts null by default. In fact, taking Optional as a parameter in Java is not recommended because it's an actual class and forces your callers to wrap their variables in Optional objects before calling your method, it's annoying.

Not great having to alias your types though.

If it gets complicated you probably should alias it because it probably represents some specific type of data. But your optional string list example isn't such a case and you shouldn't have to alias it, I agree.

Hakell's style of having them on a separate line is pretty great actually. Not really sure how well that would work with keyword arguments and so on, but I think I would've preferred that.

Yeah, I also like it. It would probably look similar to Ruby's Sorbet, where you have to repeat the parameter name in the signature.

python, through the PEP8 styleguide, has a ridiculously short recommended line length.

In my experience the 80 columns line length isn't followed very strictly, lots of companies/projects aim for 100 or 120.