5 ms·
The lack of a static type-system is IMO what makes these one-character mistakes very annoying. The compiler can't tell you something is wrong, so you're just le
by aylmao 5y ago
The lack of a static type-system is IMO what makes these one-character mistakes very annoying. The compiler can't tell you something is wrong, so you're just left to figure out why things are broken, just to realize it was the smallest of typos.
- aeturnum 5y agoI love how simple and forgiving Python is for small projects. The "trailing comma creates a tuple" situation comes out of, as far as I can tell, a desire to create maximally convenient syntax in the scenarios where tuples are intended. I think that's great for small code! I just wish that the core team would take that same zeal for a "pythonic" experience with small code and use it to develop more scaled-up systems for dealing with larger code bases. My idea is to enforce strong pre-conditions on function calls using type hints, but I am sure there are other ways to do it.
- iooi 5y agoIf you use mypy (as anyone should for any non-hobby Python usage) then Python has one of the strongest type systems available. Optional types, generics, "Any" escape hatches, everything you could want.
- aeturnum 5y agomypy is a great project and I agree that basically every project at scale should use it. However, I think you're wrong about the strength of the Python type system and what a good type system can "get" you. I think mypy both does an amazing job at static checking and that more powerful type systems go far beyond static checks and into changing how you structure and write code. The newly introduced "structural pattern matching" they just introduced[1] is an example of the kind of feature that could be usefully expanded by making type a first-class part of the Python runtime. Again - the dynamism of Python means teams can write amazing extensions to Python (like mypy), but that isn't a replacement for the core team having a plan for how they think typing information should be used at runtime. Their current answer seems to be "nothing," which disappoints me. [1] https://www.python.org/dev/peps/pep-0622/ https://www.python.org/dev/peps/pep-0622/
- yawaramin 5y agoWould mypy have caught any of the issues highlighted in the article?
- Too 5y agoNo. Mypy only cares about types, it would only have been caught if something was expecting tuple of certain length, otherwise not. The problem in the article is more related to syntax, not types, with the problem that both forms are valid syntax with different but still very similar outcome. Pylint on the other hand can find it with implicit-str-concat check enabled.
- jen20 5y ago> one of the strongest type systems available. This is simply not true - Python with mypy isn’t even as strong as Typescript, let alone Rust, F#, Haskell and so forth.
- DangitBobby 5y agoFor a language that is so incredibly picky about it's whitespace rules, it's a little laissez faire on the string-concatentation/tuple syntax side. I say this as someone who loves python and uses it extensively.
- trulyme 5y agoThe "trailing comma creates a tuple" bug actually comes from a disconnect between what people think defines a tuple (parenthesis) and what really does (comma). I always put parenthesis around a tuple for clarity.
- tayo42 5y agowhats the reason for allowing like foo, to be a tuple? why not make this a syntax error? is there a use for single value tuples?
- trulyme 5y agoYes, single tuple values are useful for example for passing to a function which expects a tuple (because it might expect zero, one or multiple values). The thing is, your example is the way tuple should be defined. The parenthesis are merely allowed (and ignored). Why? I see this as a mistake of language creators. But to be fair, it is difficult to make a perfect language (or anything really), and Python is pretty close imho.
- tyingq 5y agoC lets me do this, and doesn't say much about it. char ch_arr[3][10] = { "uno", "dos" "tres" };
- anyfoo 5y agoC's type system is neither very static nor outstandingly helpful by today's standards, yes.
- yawaramin 5y agoOn the other hand a good type system doesn't: # let ch_arr = [ "uno"; "dos" "tres"; ];; Error: This expression has type string This is not a function; it cannot be applied.
- _ZeD_ 5y agoThis is not a good type system. It's a bad language where you can invoke functions without parentesis
- vmladenov 5y agoWhy should function arguments be delimited by parentheses? We don’t do that in Bash or Objective-C, for example
- _ZeD_ 5y agoto be able to detect the difference between "this expression is a function" and "this expression is the result of the computation of a function" the parentheses are not for function arguments, are for "invocation".
- yawaramin 5y agoCan you show an example of how they could be confused?
- 5y ago
- anyfoo 5y agoFully agreed. If python had a proper static type system, those typos would hardly matter, and you'd have the best of both worlds: Convenient, concise syntax, but still confidence in your code. I say "had a proper type system", but actually it turns out that it does have something like that: When I use python for anything else than a most tiny script now, I use "mypy"[1] which implements static typing according to some existing Python standard (whether that came about because of mypy or the other way around, I don't know). It is so, so good to have mypy telling me where I messed up my code instead of receiving a cryptic, weird runtime error, or worse, no error and erratic runtime behavior. Because not knowing that a particular type is unexpected and wrong, values often get passed along and even manipulated until the resulting failure is not very indicative of the actual problem anymore. [1] http://mypy-lang.org http://mypy-lang.org
- wiredfool 5y agoI’m not clear how a type system would pick up a missing comma in a list of strings, unless the type was specific enough that the contents of the list or the length was encoded in the type.
- anyfoo 5y agoTrue, in this particular case that would only help for fixed length strings, which is far from the encompassing case. I was thinking more generally and lost what the actual issue here is about.