News for hackers. Stuff that matters.
Re:Why I'm still using Python by Barrin92 on Friday December 30, 2022 @04:51PM (#34190538)
I think that's a take in the category of 'you don't want types, you want better names'.

Static types are very useful for compilers but looking at a function and seeing int -> int -> int -> string -> bool -> int, says very little about the semantics of a program. It's always the names and documentations that tell human beings how to make sense of a program.

When we put things in record types, the sense-making value isn't in the static analysis but in the fact that our vague collection of parameters now has a proper name that indicates what it's all about.

Re:Why I'm still using Python by dragonwriter on Friday December 30, 2022 @05:10PM (#34190691)
> Static types are very useful for compilers but looking at a function and seeing int -> int -> int -> string -> bool -> int, says very little about the semantics of a program.

Sure, but on the other hand a type of APIProxyEvent -> LambaContext -> APIGatewayProxyResponse says quite a bit more about the semantics.

Unless a function is highly abstract, int -> int -> int -> string -> bool -> int is probably an underspecific type signature.

EDIT: To be clear, I generally find that the thesis “you don’t want types, you want better names” comes from assuming bad types, and suggesting replacing them with good names. And, for casual inspection, yes, good names may be superior to bad types. On the other hand, I can’t statically check good names, I can statically check types (good types, or bad-because-underspecific types, but good types, as well as telling me more as a reader, will also statically catch more possible errors.) Ultimately, what I want is good types and good names,

Re:Why I'm still using Python by Barrin92 on Friday December 30, 2022 @06:55PM (#34191629)
It's not so much assuming bad types as saying that names and types properly used serve different needs. For example, if you have types defined in your program, you could literally replace them with some random characters and the type-checking would be equally good, for the compiler, even if you don't undestand a thing. The value of types really is in the structure they represent, and enforcing certain constraints, not in any human understanding of the program. You could even have badly structured types with decent labels.

When you're using types as a means to check names you're likely to misuse types. Synonyms are a good example of this, where people will make so many types each type only ever occurs once, instead of having a well named variable of a more generic type.

Re:Why I'm still using Python by dragonwriter on Friday December 30, 2022 @08:20PM (#34192278)
> It's not so much assuming bad types as saying that names and types properly used serve different needs.

Different but overlapping needs, yes.

> For example, if you have types defined in your program, you could literally replace them with some random characters and the type-checking would be equally good, for the compiler, even if you don't undestand a thing

Sure, but for human consumption you want good names of types, not just good logic of types, just like you want good names of variables.

But, while you can (without types) overload names of variables with the human information that would be in names of types, this is bith less ergonomic that separating the two kinds of names, and doesn’t support type logic the way types that are both well-structured and well-named do.

> The value of types really is in the structure they represent, and enforcing certain constraints, not in any human understanding of the program.

I could not agree more strongly with this, it is no more true of types than it is of the rest of code: yes, with any part of code the logic is was matters functionally, but humans maintain the code, so if its not written (both names and structure, within the variations that produce correct behavior) for human understanding, its less useful, and potentially useless.

> When you're using types as a means to check names you're likely to misuse types.

I don’t know what this is referring to. If there is a statically verifiable feature, it is a real type constraint.

> When you're using types as a means to check names you're likely to misuse types. Synonyms are a good example of this, where people will make so many types each type only ever occurs once, instead of having a well named variable of a more generic type.

Synonyms/aliases (at least in languages I am familiar with) are explicitly not types, but alternate names for types. They aren’t checkable, only the underlying type is. They are useful in much the same way as named constants.

Re:Why I'm still using Python by Aaargh20318 on Friday December 30, 2022 @07:11PM (#34191745)
The other day I had to make sense of some Python code that used numpy heavily. It was an absolute disaster to figure out what the code was actually doing because of Python's lack of proper typing.

Take for example, the numpy.dot function. This is from the documentation:

> numpy.dot(a, b, out=None)#

> If both a and b are 1-D arrays, it is inner product of vectors (without complex conjugation).

> If both a and b are 2-D arrays, it is matrix multiplication, but using matmul or a @ b is preferred.

> If either a or b is 0-D (scalar), it is equivalent to multiply and using numpy.multiply(a, b) or a * b is preferred.

> If a is an N-D array and b is a 1-D array, it is a sum product over the last axis of a and b.

> If a is an N-D array and b is an M-D array (where M>=2), it is a sum product over the last axis of a and the second-to-last axis of b:

So to figure out what this call to dot actually does and what it's output type is I need to know the actual types of 2 inputs. Of course, those inputs are the results of other function calls, that are also dependent on the types of multiple inputs. When reading code you have to manually keep track of each type as you read through it, you have to look up every function to see what it does and what it can return under what conditions.

Programming languages are not for computers, they are there for humans to understand what is going on. Python absolutely fails at this because python code is almost totally unreadable. It is at best a write-only programming language.

Re:Why I'm still using Python by habinero on Saturday December 31, 2022 @04:22AM (#34194898)
You're complaining about a library, not Python.
Re:Why I'm still using Python by lelanthran on Saturday December 31, 2022 @01:45AM (#34194285)
> Static types are very useful for compilers but looking at a function and seeing int -> int -> int -> string -> bool -> int, says very little about the semantics of a program. It's always the names and documentations that tell human beings how to make sense of a program.

Sure, agreed, but if a program contains poorly named types then it's a good bet that if types were not mandatory, those authors who could not be bothered with properly naming their types would be equally incompetent at naming their variables, parameters and functions.

IOW, if author competence is important for typed programming to be readable, then it is even more important for untyped languages!