News for hackers. Stuff that matters.
Re:Things to use in Python 3 by croh on Wednesday May 15, 2019 @12:44AM (#19916488)
1. f-string and extended-iterable-unpacking reminds ruby. i was really missing them.

2. pathlib is cool. will come pretty handy.

3. Data classes sounds good but there should be only one way to do things, even you end up writing few more lines.

4. type-hints are ok for very very big projects.

5. No comment on implicit-namespace-packages yet as still trying to understand solid use-case.

Re:Things to use in Python 3 by DonaldPShimoda on Wednesday May 15, 2019 @01:19AM (#19916616)
> Data classes sounds good but there should be only one way to do things

Dataclasses greatly simplify generation of simple classes which are unnecessarily filled with boilerplate. I'd argue that they are the one way to do this, and that choosing to manually implement the same naive `__init__` function for every simple class you write is the "wrong" way.

(Here I take "simple class" to mean a class which takes in some values during initialization and stores them without anything terribly interesting going on during that initialization. A simple class can have methods defined on it, though.)

> type-hints are ok for very very big projects.

D:

> No comment on implicit-namespace-packages yet as still trying to understand solid use-case.

I think it's just... trying to keep your directories "clean"? I also don't really understand the use of this haha.

Re:Things to use in Python 3 by croh on Wednesday May 15, 2019 @01:46AM (#19916744)
> Dataclasses greatly simplify generation of simple classes which are unnecessarily filled with boilerplate

I would love to solve these boilerplate kinds of problems using plugging like emmets. Magic like this feels good when writing but troubles during debugging and customizing.

Additionally naive programmers always use such features in wrong situation if they don't get use-case. I really feel sad after seeing so much bad-django-code in production.

Re:Things to use in Python 3 by dfinninger on Wednesday May 15, 2019 @02:02AM (#19916799)
> 4. type-hints are ok for very very big projects.

Great for smaller ones too! I type annotate every function, even

    def parse_args() -> argparse.Namespace:
        pass
at the top of simple scripts. With a good IDE (VS Code fits here too), the extra language lookups/insight you get are awesome. Command+mouse_hover gives me a great bit of information about args passed into the function if I annotate the inputs.
Re:Things to use in Python 3 by oselhn on Wednesday May 15, 2019 @02:45AM (#19916966)
I tried to use type hints but I do not see enough value in them to justify making code more complex. It looks to me that they are similar to hungarian notation as they make refactoring harder but they are not reliable and does provide little value in checking program correctness. They are just documentation embedded into variable declaration used only for linting so I tend to not trust them.
Re:Things to use in Python 3 by feanaro on Wednesday May 15, 2019 @04:26AM (#19917397)
Why do you say they are not reliable? Are you unfamiliar with mypy?
Re:Things to use in Python 3 by oselhn on Wednesday May 15, 2019 @05:53PM (#19924157)
Because it is not used by runtime. Mypy is just linter which adds additional restrictions on code which are not enforced by interpreter. You can have false positives so correct python code must be fixed to pass linter checks. In my opinion if you need static type checks you should use statically typed language and not hurt your coding speed by such partial solution. Also majority of python libraries do not use type annotations so you are limited to your code.
Re:Things to use in Python 3 by feanaro on Thursday May 16, 2019 @04:23AM (#19927136)
Well, yes, this is exactly how the type checkers of statically-typed languages work: as linters, during compilation. The largest difference is that typing in Python is gradual, so not everything needs to be typed as you say.

I agree that statically typed languages are preferable. I don't consider static typing optional so I'm glad Python is growing a solution that supports it, though.

In my experience, mypy works surprisingly well. It doesn't hurt my coding speed at all but enhances it to levels that were not previously possible in Python, due to a lack of typing. False positives are rather rare.

Re:Things to use in Python 3 by baq on Wednesday May 15, 2019 @07:08AM (#19918220)
don't use them if you don't validate them with mypy or similar.
Re:Things to use in Python 3 by baq on Wednesday May 15, 2019 @07:07AM (#19918216)
> there should be only one way to do things, even you end up writing few more lines.

the zen of python never mentioned that you should exclusively code in machine code.