6 ms·
I am a bit in shock. Accidental string concatenation. Python just lost a lot of reputation in my brain.
by oaiey 5y ago
I am a bit in shock. Accidental string concatenation. Python just lost a lot of reputation in my brain.
- ErikCorry 5y agoMisspelling a variable on the lhs of an assignment just causes a new variable to be created with the new name. That's a lot worse in my book.
- ReleaseCandidat 5y agoI'd say unexpected behavior is always worse than expected one. Yes, you'll certainly find somebody who doesn't know what 'not statically typed' means, but ... And yes, there are also C(++) users, that expect strings to be concatenated like that.
- obua 5y agoYou seem to also not know what "not statically typed" means. It certainly does not mean "not properly scoped".
- ReleaseCandidat 5y agoYes, of course. But you see that no scope keywords exist in Python. But there exists `+` to concatenate strings (too).
- fragmede 5y agoKeywords like namespace, no; but functions and classes and modules provide for a lot of scoping opportunities.
- ReleaseCandidat 5y agoThe problem is `fop` should be `foo`: foo = 5 fop = 6 Keywords like `let` solve this problem: let foo = 5 fop = 6 # error
- ErikCorry 5y agoOr := for declaration like Go and Toit
- ReleaseCandidat 5y agoYes, or another symbol instead of `=` for assignment, like `<-` (F#)
- deathanatos 5y agoNot entirely: let foo = a(); let foo = b(foo); let fop = c(foo); let foo = d(foo); (Which is valid, e.g., in Rust.)
- TheEzEzz 5y agoYou do get a warning, though. And most Rust projects I've seen usually adhere to 0 warnings.
- renox 5y agoI hate variables shadowing, I'm very surprised that they allowed it in Rust, I saw an unpected behaviour caused by variable shadowing in C++ (global variable hidden by member variable) just last week..
- Too 5y agoA good IDE has many other safety nets for that error. Auto completion, highlight matching variable, gray out unread variables and warning of unused assignment. I’ve written lots of python and can’t recall ever having this issue. More likely is a logic typo of two similar variables like length_x vs length_y, where a “let” wouldn’t have saved you anyway if both are already defined. JavaScript, pre strict TS, on the other hand, where missing var implied global was a real motherload of bugs. Or kotlins “val” vs “var” changing semantics completely…wow. But those are different concepts from basic definition I know.
- wruza 5y agoI left python around the times of 2/3 drama, are nonlocal and global not there anymore?
- oaiey 5y agoWhile I agree, this is somehow something I expect. Implicit string concatenation without operator or function around it sounds just like a terrible idea. It breaks the basic syntax concept of `foo X bar`. On the other hand it is probably very handy with DSLs and things like that.
- wruza 5y agoNot so much DSLs, it's probably something as banal and ancient as usage = ( 'usage: foo [options] filenames...\n' ' -f force concatenation\n' ' -c for convenience\n' ) print usage Edit: forgot to add parentheses
- jstx1 5y agoThat’s a complaint against the entire type system, nothing to do with misspelling.
- samhw 5y agoIt has nothing to do with the type system? It's an issue with implicit declaration. You could very easily require explicit declaration while retaining the selfsame type system.
- jstx1 5y agoHuh, you're right. It would be bizarre to see something like this in Python though. I've never even thought of it as being implicit declaration.
- version_five 5y agoI dont think that's the same kind of thing. Your example is a tradeoff that anyone who uses a language that doesn't require explicit variable declaration faces, and it's pretty tough to argue such languages really shouldn't exist. Missing an operator resulting in explicit behavior is much more subtle and not even obvious behavior. For those who use python, it is worse.
- shultays 5y agoit's pretty tough to argue such languages really shouldn't exist Well, I agree with OP so that is at least two people. I really don't see it as a good trade.
- SomeCallMeTim 5y ago> ...it's pretty tough to argue such languages really shouldn't exist. "Shouldn't exist" is too strong. Dynamic languages that let you create a new variable via assignment shouldn't be used to create non-trivial software. How about that? Scripting languages have a place. That place is 100% in creating quick-and-dirty scripts and tools. Or in doing some kind of one-off data transform (as is common in machine learning scenarios). Anything that has a life span of two weeks or less, or a code length of fewer than a hundred lines? Yeah, script languages rock for that. Explicit/static typing adds vastly more value to large projects than the cost of the overhead. The fact that you can't really gain that value in Python means that Python should be relegated to quick and dirty scripts. Same for JavaScript, Ruby, and other completely dynamic languages. You'll note that all of these languages are getting types one way or another, meaning that there are a lot of people who do recognize their value. Though TypeScript is years ahead of the rest in the completeness and sophisticated of its type system; bugs like the comma bug detailed by OP, along with simply every JavaScript "wat" bug, simply can't happen in TypeScript in strict mode. And static types enables entire other categories of bugs to be detectable via a linter as well.
- simonw 5y agoI've been building non-trivial software in dynamic languages for twenty years. They work great. I'd take a project in a dynamic language with a decent test suite over a project without tests in a statically typed language any day of the week.
- voltagedivider 5y agoIsn't that common for all/most languages that don't require explicit typing?
- samhw 5y agoIt would be impossible in any language that requires either explicit typing or some kind of 'let' keyword. (Or, in the fringe case, a language like Go which uses a different operator for initialisation-plus-assignment.)
- voltagedivider 5y agoExactly. That's why I asked about languages that don't require explicit typing. My point is that it's a feature of many languages rather than a Python idiosyncrasy.
- xigoi 5y agoJavaScript (strict mode) doesn't have explicit typing, but it still requires variables to be declared.
- dragonwriter 5y agoDeclaration and explicit typing are logically orthogonal, but few if any languages require typing but not declaration. Lots require declaration but not typing.
- 5y ago
- colpabar 5y agoI was going to comment something like "who would even use this?" and then I remembered that I have in fact used that feature :) It's a somewhat "nice" way to write long strings and keep the code from getting too wide. I never did it inside an array, but I found breaking up a long string into smaller ones and wrapping them in parens without a comma was convenient, for things like error messages. But that's just what comes with a hyper flexible language like python. You can do lots of things in lots of different ways, but you can also screw things up just as easily, and your IDE won't tell you because technically it's valid code.
- oaiey 5y agoI completely get that. That is a very nice feature for building DSL or libraries with special needs. But it makes the overall language very dangerous. Is this "operator" overloadable on each type in Python? And that scares me a lot. I think I have to reevaluate my position towards Python.
- housecarpenter 5y agoIt's not really an operator. It's part of the syntax of string literals. "foo" "bar" is an alternative way of writing the string literal "foobar". If foo is not a string literal, foo "bar" is invalid syntax.
- oaiey 5y agoOkay... So it is not a implicit operator. That is good. Some small reputation points are regained. Thanks.
- silisili 5y agoWhy not just use plusses? Or perhaps a join func, which would accomplish the same. I get the use case as you described it, but it just seems like minimal effort to accomplish and have some semblance of explicit/safety.
- 5y ago
- atleta 5y agoNot sure if it's irony or not. After all, this is not really accidental string concatenation but an easy to make type error which can go undetected due to the dynamic typing (and the lack of thorough type annotation in most code). The string concatenation in itself should not be a problem as it's really just string constants. (But again, it might be irony exactly because of this :) )
- oaiey 5y agoUnfortunately no irony. I come from a programming platform (C#) where productivity is a key element of language design. I highly doubt that Anders Heijlsberg would have accepted such a error prone concept like a literal free implicit operator on a key type like strings.
- atleta 5y agoWell, I guess it's true for most language that productivity is intended to be a key element of design. (For python, definitely. But I also remember James Gosling saying this about Java.) This implicit concatenation seems to come (inherited?) from C. I kind of remembered that some languages do support it for braking strings into multiple lines conveniently. I'm a bit surprised that it works even on line (I've never used it, because why would have I), but you'll likely to make the mistake on multiline statements anyway. I've also checked and it doesn't work in java (which I kind of remembered, though I mostly do python these days).
- amelius 5y ago> for braking strings into multiple lines conveniently What is inconvenient about just adding a + at the end or beginning of the line?
- ErikCorry 5y agoIn most languages an array with 3 elements has the same type as an array with 2 elements so the type system isn't going to warn you about the difference between ("foo" "bar", "baz") and ("foo", "bar", "baz")
- ehsankia 5y agoC/C++ has the exact same thing, no?