|
Dominoes posted:Speaking of which:
|
# ? Dec 7, 2014 02:55 |
|
|
# ? May 20, 2024 23:29 |
|
seiken posted:
I see explicit proper scoping here; x starts off in a global scope, and then you create a function that declares a variable "x" in a local scope. Since x now belongs to a local scope, trying to print that variable before assigning it throws an error. If you don't push a variable "x" into the local scope, then Python knows that you're still talking about the global x. If you want the function to use the global x, then you can use the "global" keyword for that, which tells the function that x belongs to a different scope. Totally reasonable, and definitely not broken Maybe what you expected was for Python to interpret line by line instead of interpreting the entire function block before running it?
|
# ? Dec 7, 2014 03:05 |
|
The hosed up thing in that python example is the name used in the list comprehension leaking out to the code outside of it. Everything else seems fine.
|
# ? Dec 7, 2014 03:10 |
|
QuarkJets posted:Maybe what you expected was for Python to interpret line by line instead of interpreting the entire function block before running it? no, I expected Python to do what it does, because I know exactly how it works. It's still obtuse for name lookup semantics to change based on assignments arbitrarily far after the lookup. I mean it's a reasonable decision given that you've already made the mistake of conflating variable assignment and declaration, but that doesn't mean it's not poo poo. And you ignored the name leaking out of the comprehension because of the lack of any sort of block scoping seiken fucked around with this message at 03:21 on Dec 7, 2014 |
# ? Dec 7, 2014 03:18 |
|
Jabor posted:The hosed up thing in that python example is the name used in the list comprehension leaking out to the code outside of it. Everything else seems fine. Why is that a problem? A list comprehension is basically just a type of for loop, so it's the same behavior that you'd get from any other language with for loops
|
# ? Dec 7, 2014 03:20 |
|
QuarkJets posted:Why is that a problem? A list comprehension is basically just a type of for loop, so it's the same behavior that you'd get from any other language with for loops Every sane language with for loops gives them their own lexical scope. vvvv since your post doesn't make sense in response to mine, this is what I mean by "arbitrarily" Python code:
seiken fucked around with this message at 03:29 on Dec 7, 2014 |
# ? Dec 7, 2014 03:22 |
|
^^^ So you're saying that C, C++, and Java, all of which would produce identical behavior, are insane?seiken posted:no, I expected Python to do what it does, because I know exactly how it works. It's still obtuse for name lookup semantics to change based on assignments arbitrarily far after the lookup. I mean it's a reasonable decision given that you've already made the mistake of conflating variable assignment and declaration, but that doesn't mean it's not poo poo. And you ignored the name leaking out of the comprehension because of the lack of any sort of non-function scoping It's not arbitrary, though. When you declare a variable within a new scope, you're implicitly assigning that variable name within that scope to the new scope.
|
# ? Dec 7, 2014 03:25 |
|
IEC++ code:
|
# ? Dec 7, 2014 03:29 |
|
QuarkJets posted:^^^ So you're saying that C, C++, and Java, all of which would produce identical behavior, are insane? Have you ever actually used any of them? None of them work like that C++ code:
code:
|
# ? Dec 7, 2014 03:31 |
|
seiken posted:Have you ever actually used any of them? None of them work like that Yes, I have. Have you? Copy-pasting that code and compiling it, it prints 10. I just did it, using the g++ (GCC) 4.4.7 compiler. e: Admittedly, I've never tried doing this in Java, but in C++ it's permitted QuarkJets fucked around with this message at 03:41 on Dec 7, 2014 |
# ? Dec 7, 2014 03:39 |
With g++ 4.8.1 I get:code:
Joda fucked around with this message at 03:51 on Dec 7, 2014 |
|
# ? Dec 7, 2014 03:47 |
|
QuarkJets posted:Yes, I have. Have you? Copy-pasting that code and compiling it, it prints 10. I just did it, using the g++ (GCC) 4.4.7 compiler. That is non-standard behavior and I'm surprised any version of g++ does it, given how much poo poo Microsoft caught for providing the same extension.
|
# ? Dec 7, 2014 03:48 |
|
QuarkJets posted:Yes, I have. Have you? Copy-pasting that code and compiling it, it prints 10. I just did it, using the g++ (GCC) 4.4.7 compiler. Not in anything standards-compliant it's not. GCC may ignore parts of the spec when you don't explicitly tell it to do it right, but using that behaviour to argue that something's allowed by the language is wrong.
|
# ? Dec 7, 2014 03:48 |
|
QuarkJets posted:Yes, I have. Have you? Copy-pasting that code and compiling it, it prints 10. I just did it, using the g++ (GCC) 4.4.7 compiler. uhhhhh code:
code:
https://gcc.gnu.org/onlinedocs/gcc-4.0.4/gcc/C_002b_002b-Dialect-Options.html#index-fpermissive-140 posted:Downgrade some diagnostics about nonconformant code from errors to warnings. Thus, using -fpermissive will allow some nonconforming code to compile. Coffee Mugshot fucked around with this message at 03:51 on Dec 7, 2014 |
# ? Dec 7, 2014 03:48 |
|
Joda posted:
When I started at this company I got put on a project with a guy who used -fpermissive and I had to spend a good solid week going through his stuff and fixing it up to compile without it, and on clang++. Don't use -fpermissive.
|
# ? Dec 7, 2014 03:51 |
|
QuarkJets posted:Yes, I have. Have you? Copy-pasting that code and compiling it, it prints 10. I just did it, using the g++ (GCC) 4.4.7 compiler. Wait what the hell are you doing on 4.4.7, that's closing in on three years old.
|
# ? Dec 7, 2014 03:55 |
|
QuarkJets posted:e: Admittedly, I've never tried doing this in Java code:
code:
|
# ? Dec 7, 2014 03:57 |
|
Let me personally assure you that gcc has never and will never accept that nonconformant code without error.
|
# ? Dec 7, 2014 03:59 |
|
Thermopyle posted:Maybe Python has stockholmed me, but that seems perfectly reasonable to me. Yeah, Python has stockholmed me. I'm just so used to that behavior it just seems normal.
|
# ? Dec 7, 2014 04:01 |
|
Also note that this is only even an issue for the specific case of a variable declared in the loop preamble - if the code wasC++ code:
Then not even GCC with -fpermissive or any buggy version of MSVC will accept it
|
# ? Dec 7, 2014 04:11 |
|
Voted Worst Mom posted:Let me personally assure you that gcc has never and will never accept that nonconformant code without error. Are you really sure that something like 2.7 or somesuch prehistoric version didn't? ;-)
|
# ? Dec 7, 2014 04:35 |
|
If you're writing scripts to automate some mundane task, feel free to use Python- if it's only a few dozen lines you could use any language under the sun and it wouldn't matter. Don't use it to teach beginners. It's a hodgepodge of half-baked ideas and corner cases. Students come away with confusion, weak mental models and bad habits. I think many developers who learned Python as a third or fourth language and found it easy to pick up fail to objectively evaluate its complexity from the perspective of someone who has no prior experience. While I'm in a ranting mood, let's take a look at Python's stated aesthetic principles. import this posted:Explicit is better than implicit.
import this posted:Sparse is better than dense. import this posted:Readability counts. import this posted:Special cases aren't special enough to break the rules. Python code:
import this posted:Errors should never pass silently. import this posted:There should be one-- and preferably only one --obvious way to do it. Python code:
import this posted:If the implementation is hard to explain, it's a bad idea. import this posted:Namespaces are one honking great idea -- let's do more of those! Internet Janitor fucked around with this message at 17:43 on Dec 7, 2014 |
# ? Dec 7, 2014 05:09 |
|
Recovered python addict chiming in. I recently was attempting to explain some python constructs to a programming newbie at work who is trying to get better so she can be a more valuable employee and all that fun jazz. I was able to cover a lot of ground in simple terms, just describing core types, iterables and for loops, all that jazz, but when it came time to explain classes is when I started to feel really embarrassed about python. Trying to explain python classes to programming newbies is the worst if you think about it "okay, so, in a lot other languages when you define a method in a class they will implicitly slip in a 'this' that you'll refer to talk to your own instance, but python is weird and when you have a class instance with methods you need to put 'self' at the beginning of your method, it also wont resolve what variables you're trying to reference, you will always need to rely on 'self' for anything" it is clunky and awful to teach, because you dont want them to think all programming languages are doing the quirky things it does. a lot of pythonesque things are easy to conceptualize and describe -- to other programmers, for beginners it's a nightmare to teach and be taught.
|
# ? Dec 7, 2014 05:42 |
As someone who has never actually used or even looked at Python before, am I understanding it correctly that there is no clear syntactical difference between variable declaration, definition and assignment?
|
|
# ? Dec 7, 2014 07:27 |
|
Internet Janitor posted:Why does Python have over a dozen possible string literal variants when nearly every other mainstream language gets by with 1 or 2? An 'r' means that backslashes are treated like a normal part of the string instead of an escape character, 'b' is an array of bytes and is used mainly for interfacing with non-python or legacy code that doesn't use unicode. The "problem" is mostly cleared up by using Python 3, and the two modifier characters don't mean there are a "dozen string constructors". And dealing with unicode in Python is no more difficult(and generally easier) than in most other languages. Mido posted:"okay, so, in a lot other languages when you define a method in a class they will implicitly slip in a 'this' that you'll refer to talk to your own instance, but python is weird and when you have a class instance with methods you need to put 'self' at the beginning of your method, it also wont resolve what variables you're trying to reference, you will always need to rely on 'self' for anything" "Methods are just functions, except when you call a method Python automatically passes as an additional argument the instance from which it's being called. Remember that when writing the parameter list for methods." You've got it backwards, it's implicit self languages like Java that complicate things by special-casing methods, which is possible because they're less dynamic and you can't add a method to a class at runtime as you can in Python. Python's got ugly bits, but I don't think the two examples given make it a bad language for teaching. Especially relative to other language choices, I'm still not clear what languages are being proposed as a replacement.
|
# ? Dec 7, 2014 07:42 |
|
Mido posted:Recovered python addict chiming in. I don't see why this behavior is bad. It seems like it would be helpful for beginners to understand that they're accessing something specific to that object instance instead of something that exists outside the object. It's just making the scoping of class instances explicit rather than implicit. You can make the case they're not following through on a lot of their design goals, but requiring 'self' when referring to data or methods belonging to the class instance doesn't seem like it violates any of their design goals. It doesn't even strike me as particularly annoying. ErIog fucked around with this message at 08:10 on Dec 7, 2014 |
# ? Dec 7, 2014 08:04 |
|
Internet Janitor posted:While I'm in a ranting mood, let's take a look at Python's stated aesthetic principles. "I do not understand Python's features and syntax well enough, thus I should mock it"
|
# ? Dec 7, 2014 08:08 |
|
Joda posted:As someone who has never actually used or even looked at Python before, am I understanding it correctly that there is no clear syntactical difference between variable declaration, definition and assignment? Yes. You create a variable x in a function by assigning to x somewhere in that function. If x is declared in a function, all references to x resolve to the local variable, even if they occur lexically prior to the first assignment. This rule means that you can't just assign to a global variable from inside a function; you have to suppress the local variable by declaring that x is a global name, and then assignments will actually affect the global variable.
|
# ? Dec 7, 2014 10:26 |
|
Lumpy posted:Assuming java script: pseudorandom name posted:Well, the proper way is: Sedro posted:FYI those are just style warnings in your IDE. It's also suggesting you add semicolons. Dominoes fucked around with this message at 10:42 on Dec 7, 2014 |
# ? Dec 7, 2014 10:31 |
|
Voted Worst Mom posted:Let me personally assure you that gcc has never and will never accept that nonconformant code without error. Let me quote from the original, pre-standard, Annotated C++ Reference Manual (Ellis & Stroustrup): quote:6.5.3 The for Statement It goes on to comment: quote:[...] the same name cannot be used to control two for loops in the same scope. Every C++ compiler behaved this way before the standard came out.
|
# ? Dec 7, 2014 10:40 |
|
Joda posted:But if you're gonna be a developer I assume you're not just gonna take a single programming course? Don't all CS, software engineering or software development B.Sc./M.Sc. programmes have algorithms and data structures (or some equivalent thereof) as a core course? I know that understanding how a CPU is wired (at least in terms of a basic integer unit) and how it interprets instructions is only consistently core for software engineering, but I thought everyone doing some variation of an academic degree had to take algorithms/datastructures at some point? Yes - if you're going to be a developer. If you're not - then I don't think you're going to touch these subjects. During my studies (IT at the department of Mathematics and Computer Sciences) these things were also mandatory - I don't know if it's the same elsewhere (I'd assume so), but for example, in UK, I worked with people that knew the language, but not much beside it. At my uni we began with a year full of mathematics - differential equations, linear algebra, discrete mathematics etc. To this day I don't know if these helped me, or if I just lost a year. Sure - I can gloat that, at that time, I knew how to calculate different types of probabilities or determine what is a group / core in a given set. Then we went through applications of mathematical subjects in Maple / Mathematica, with introduction to algorithms with Ada, and alongside, theoretical subjects like construction of compilers. C/C++ begun on my fourth semester, if I remember correctly, with data structures alongside that.
|
# ? Dec 7, 2014 11:44 |
|
Suspicious Dish posted:"I do not understand Python's features and syntax well enough, thus I should mock it" "I cannot rebut reasonable criticism of my pet programming language"
|
# ? Dec 7, 2014 13:26 |
|
Thermopyle posted:Yeah, Python has stockholmed me. I'm just so used to that behavior it just seems normal.
|
# ? Dec 7, 2014 13:41 |
|
guys, guys, this language that I am intimately familiar with behaves the way I expect, so clearly what it does is natural and logical and anyone who thinks it's flawed or inconsistent simply doesn't get it
|
# ? Dec 7, 2014 14:28 |
|
Speaking of which, Python should fix the datetime module (Look at arrow), and include requests as the standard http module. Uncontroversial?
|
# ? Dec 7, 2014 14:45 |
|
Why does this man have a phobia of scrolling?
|
# ? Dec 7, 2014 15:08 |
|
NFX posted:Why does this man have a phobia of scrolling? Sitting alone in front of a computer screen all day for twenty years does weird things to a persons brain.
|
# ? Dec 7, 2014 15:18 |
|
Suspicious Dish posted:"I do not understand Python's features and syntax well enough, thus I should mock it" I'm completely familiar with its features and syntax (and I know InternetJanitor is as well). It's an inconsistent, backwards mess of a language that doesn't align in any way with its stated goals. What Python is good at is being a slightly less terrible bash, for couple-hundred line scripts. It's only managed to sneak under the radar of universally reviled languages because its awfulness is a bit more subtle than PHP or Javascript, but it's no less systemic. (and nobody has written a really good blog post a la "fractal of bad design")
|
# ? Dec 7, 2014 15:20 |
|
seiken posted:
|
# ? Dec 7, 2014 15:22 |
|
|
# ? May 20, 2024 23:29 |
|
seiken posted:
This isn't even remotely true
|
# ? Dec 7, 2014 16:10 |