Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@FrodoSwaggins I didn't even know that...
So would variables be in global scope when declaring them in the body of 'if __name__ == "__main__":' -
@FrodoSwaggins i always thought the reason for this has to do with the way Python deals with and treats files(as modules) and thus a variable defined in the if statement that you mentioned is scoped to the innermost funcion, module or class.
I get that, i still think it is stupid and error prone. Talk about polluting the global scope of the file. -
@irene Variable declaration should be ambiguous from assignment like it is in most languages. E.g. "let a = 1; b = 2;"
-
@irene Because having "a = 1;" being declaration and assignment leads to errors and is ambiguous. It can't warn you when you accidentally use the same name for two distinct variables because it thinks it's just another assignment and you have to declare variables as global to be able to use variables from global scope. It's not explicit enough and thus fragile
-
Also when you have a typo when writing to a variable it can't give you a clear error message because it just implicitly declares a new variable
-
People do mistakes. Why design a language in a way that computers can't help you when you inevitably do something wrong. Expliciteness is a good thing (as long as it doen't become too verbose).
The walrus operator is fine btw because it explicitely declares a variable -
retnikt68945yIf you think that, you're using it wrong. You're just not used to python. I started with python, then learnt VBA and C++ and thought the exact inverse.
"wtf why do I have to declare this, it should know it exists because I assigned it" -
@retnikt Maybe. But I have objective arguments that it is worse than using 'let' or 'var'. I mostly don't like Python because it's dynamically typed, these little things are just the cherry on top. I'm definitely not using it wrong though (how would that be possible?)
-
@retnikt It's the other way around that's the problem. When the interpreter knows that the variable is already declared but you don't. This translates into bug that a declared language would have found without manual (i.e. expensive) debugging.
-
@irene Real world example: you have to implement shit in existing code you didn't write and where you don't know every variable by heart. A declared language will complain if you redefine a variable, and the compiler will tell you which line the bug is in.
An undeclared language will instead fuck up the program logic at runtime, and not necessarily in an obvious way.
Quiz question: in which of the scenarios do you think you will be faster fixing the bug?
Computers may be stupid, but they are damn good at automatic checks. That's why it doesn't make sense to do manual work that a compiler could have done as well. -
@irene The computer is a tool, I want it to work with me not just sit around passively doing nothing. I'm still the one doing the work but my human brain can't remember everything perfectly without having to double check like my IDE can
-
@retnikt Even under Windows where good IDEs are available and common, you shouldn't use a build system that depends on any IDE.
Also, this idea is flawed because it works only for small projects. Already medium sized projects have several devs working on the same codebase and merging with Git, SVN or whatever, but not with the IDE. That's why the build chain has to refuse the code, and that's why it has to be a language feature, not an IDE feature. -
retnikt68945y@Fast-Nop when did I say anything about building? You notice that this variable name is already used while you're writing the code, then rename it. So yes it should be an IDE feature.
-
retnikt68945y@Fast-Nop and when you merge code, why would variable declaration pose any problems?
-
@retnikt Variable declaration doesn't put problems, it uncovers them. As to what problems that are, read back the thread.
-
@retnikt The IDE cannot help you when you accidentially redefine a variable because it has no idea whether you meant to declare a new variable or just assign a new value to the already existing one. It can't show you an error because it isn't one. Except it is
-
@irene That's funny because I don't have this problem in any other proper language
-
@irene That's the same argument PHP devs use to excuse their language. Look, just because you *can* work with a mediocre language and make it work doesn't mean that you *should*. For every argument I give against Python the only thing you ever say is "Well, it's your fault" or "That's just how it's designed to be". I know. I still don't like it because I know better languages that don't have these problems. If my code is good in Java why should it suddenly be bad in Python? I'm using everything they give me, it's just not enough
-
@irene Freedom, eh? Yeah the freedom to have both slow and buggy programs, that's what ducktyping gives.
-
@irene well that's the point of it. To save the programmer havig to declare and type a variable and just vomit any shit into the editor. It's the epitome of sloppiness.
-
@irene Python is "freedom" just like a non functioning society is "freedom". Or the "freedom" of interpretation a story from a five year old gives you compared to an expert author. Non-sophistication isn't freedom in my book
Related Rants
Variable assignment as declaration is stupid. Looking at you, Python 😑
You can never be sure whether you accidentally overwrite a previous value and you have to fuck around with global because it doesn't know what's an assignment to a global var and what's a declaration. It's just not as satisfying as doing it explicitly and only leads to errors
rant
python
declaration
variable
assignment