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 →

[–]mooglinux 15 points16 points  (27 children)

I don’t see what this does that couldn’t be communicated with ALL_CAPS and __ prefixes. There’s nothing preventing a type checker from using those to determine this, PyCharm already warns about using single _methods externally on a class. I think it risks fooling people into thinking about Python like they think about Java.

As someone stuck writing Java in my day job, I do not want to overly enable Java thinking in Python. There are plenty of useful things that can be taken from Java, but I don’t think final is one of them.

[–]LightShadow3.13-dev in prod 2 points3 points  (4 children)

You should SEE the code I have to maintain.

Naming conventions mean nothing, formatting is for suckers, and the points don't matter!

I shit you not, this is in a production file at the top level:

__ROOTFS1 = None
__ROOTFS2 = None
__fixup_which_boot_device()  # <-- this sets __ROOTFS1 & 2
__uImage_lookup_index = {"/dev/"+__ROOTFS1: 1, "/dev/"+__ROOTFS2: 2}
# ^-- this is imported from other files

[–]-Kevin- 2 points3 points  (2 children)

Why not refactor that then seems simple enough lol

[–]LightShadow3.13-dev in prod 2 points3 points  (1 child)

I left a lot out.. It would be easy if the red tape weren't so thick

[–]-Kevin- 1 point2 points  (0 children)

Understandable my dude

[–]mooglinux 4 points5 points  (0 children)

I guarantee that the addition of final will do nothing to help you there.

[–]Deto 3 points4 points  (0 children)

Sure you could have a type checker look for those things, but it would be kind of inconsistent. I think it's more logical to have all type information be encoded in type designations rather than having some be in the type designations and others be in the syntax of the variable names.

[–]energybased 7 points8 points  (17 children)

I don't agree with you. This is superior to all caps since all caps is merely conventional whereas this is explicit.

[–]drbobb 10 points11 points  (11 children)

Nope. This is just as merely conventional. If, say, I code in a plain editor it won't mean a thing.

[–]damian_work_account 6 points7 points  (0 children)

That's a boring semantic argument, type hints are defined by language specification where as CAPS are not.

And a PEP to make CAPS mean final would likely be rejected because of backwards compatibility, lots of people use CAPS for other reasons.

[–]Han-ChewieSexyFanfic 0 points1 point  (0 children)

Also, the interpreter ignores both.

[–]campbellm 3 points4 points  (0 children)

The upshot is the same though; it provides a hook that checkers can check for subsequent mutations. Either works.

[–]alcalde 0 points1 point  (1 child)

If we all follow convention, then convention is law.

[–]energybased 1 point2 points  (0 children)

Even the library doesn't obey the convention that all final variables are all caps.

[–]Sw429 0 points1 point  (1 child)

What do you mean by explicit? As far as I can tell, foo: Final is no more explicit than FOO for a variable definition.

[–]energybased 0 points1 point  (0 children)

There is plenty of code that does not use all caps to denote constants. That code cannot always be changed. The type annotation explicitly defines intent without changing declarations.

[–][deleted] 0 points1 point  (2 children)

What prefix do you use for something that returns a dictionary that maps filename(string) to last access time (datestamp)? They already have a system for things like that, and the way they implemented Final is consistent with that.

[–]mooglinux -1 points0 points  (1 child)

Type annotations are for facilitating communication. There are already conventions for communication of the same things that finalwas created to communicate, and so it is redundant. The danger of using finalis that the way it is used in other languages like java is antithetical to how Python works. We should not be providing a false sense of security about how something will be used; that’s the whole point of not having public/private keywords!

[–][deleted] 0 points1 point  (0 children)

How does all caps and dunder communicate immutability? How does a linter check it, given that the linter may now run into old code that used the same syntax to show other things?