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.
foo = 5
fop = 6
Keywords like `let` solve this problem: let foo = 5
fop = 6 # error let foo = a();
let foo = b(foo);
let fop = c(foo);
let foo = d(foo);
(Which is valid, e.g., in Rust.)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.
usage = (
'usage: foo [options] filenames...\n'
' -f force concatenation\n'
' -c for convenience\n'
)
print usage
Edit: forgot to add parenthesesMissing an operator resulting in explicit behavior is much more subtle and not even obvious behavior. For those who use python, it is worse.
it'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."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.
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.
I'd take the opposite. I've read too many useless tests in python codebases that can be accomplished by a static type checker. "Decent" does a lot of heavy lifting in your comment. And what about a dynamically typed codebase without any tests? I'm sure they exist.
I'd rather dive into a big ball of mud with a compiler that will help point me to my mistakes before I release them, than having to sift through a ball of mud trying to find that mistake with production services flailing.
That all being said I've worked with both types of languages in successful projects. But I prefer the development experience of the statically typed variety.
There are reasons dynamic language (or specifically Python), but I haven't heard one explanation how it helps writing fewer tests.
The cognitive burden of having to memorize and look for which variables are new vs which are being modified is simply not worth it in my opinion, even for a scripting language. Maybe for esolangs, simple math or first time learning programming.
In any case, it's a short coming of the language (IMO) but not a deal breaker. We learn to live with it.
global x = 1
def setx():
if True:
x = 2 # completely different x
print x # prints 2, visible outside of `if`
setx()
print x # prints 1
This led to a funny keyword 'nonlocal', because you can't simply ignore scoping and pretend that you're BASIC in any serious program.(To my opinion, python had a good start, but lost in the woods for no clear reason. It's a movie mutant of a language, which tried to appeal to non-programmers and somehow succeed, and then realized that non-programmers eventually become ones, and it's not hard. Now it's too late to fix this mess. End of opinion.)
In Scheme, for example, this is not an issue.
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.
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.
Thanks.
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.
So strange that Python has completely different syntax from C, but they chose to copy this obscure syntactic feature _even though they have the plus operator on strings_.
mylongstring = "hello" +
"world"
No idea if python's way of indentations allows this but sounds like it should mylongstring = ("hello" +
"world")
or, without `+` mylongstring = ("hello"
"world") mylongstring = "hello " \
"world " \
"my " \
"name " \
"is"*> The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.
It's common in some languages and used the way you use it. I looked in PEP8 and it seems they don't discuss this.
I think it's a perfectly valid use case, but clearly there are two camps to this. If this is so contentious, I would recommend PEP8 be revised to either explicitly endorse it as a way to split long lines or to explicitly discourage it and recommend the + operator instead.
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 :) )
("foo" "bar", "baz")
and
("foo", "bar", "baz")
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.
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).
What is inconvenient about just adding a + at the end or beginning of the line?