« first day (3023 days earlier)      last day (2149 days later) » 

these are exceptions and it's locked for a reason
\o cbg
I think this example demonstrates that a rec post is possible, but it has to meet a high standard in order to justify its existence
But isn't that the point? There should be a canonical answer for learning to program? I guess it's only if the particular tag suffers from a ton of 'give me ze codez' questions?
It has to be very thorough, and it has to fill a specific pressing need, and you have to engage in hand-to-hand combat with naysayers on Meta for a week
16:04
unix.SE's q on Kali was always particularly funny to me.
But they're a bit irregular in their community culture
And yeah, there are accompanying meta discussions on all of them.
While still very broad, "how do regexes work?" has a narrower focus than "How do I learn to program?" so the former has a better chance of naysayers saying "yeah alright, this is actually something that can be covered without insane effort"
I guess you can always point people to the actual tag wiki
But canonical answers on typing, and other basic language constructs, seems like it might be worth having. I suppose they probably already exist but aren't wikified.
It's a little awkward that the questions that the community considers valuable doesn't always reflect the standards that we ostensibly decided on. This has happened often enough that they had to create a template warning users that they shouldn't be tricked into thinking that all highly voted posts are good posts
i.e. how What is the best comment in source code you have ever encountered? [closed] says "This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here."
I always read the comments for that reason. I've seen a lot of "This answer isn't the best. See @username"
Plus, answers get outdated, so I always look at the edited and asked on date.
Oh, you were talking about questions.
Still.
16:39
Exception up = new Exception("Something is really wrong.");
throw up;  //ha ha
Fairly certain I've seen raise hell in Python before
That thread is hilarious. And I think I've read it before.
Hmm, is augmented assignment compatible with indexed assignment? ex. if (a[0] := b):?
I think targets can only be valid identifiers
>>> x = (a := 3)
>>> x = (a[0] := 3)
  File "<stdin>", line 1
SyntaxError: cannot use named assignment with subscript
Yeah alright.
16:47
Hey now!
I suppose a[0] = (x := 3) FTFY
$ python3.7
Python 3.7.0 (default, Jun 29 2018, 00:16:57)
>>> {]
  File "<stdin>", line 1
    {]
     ^
SyntaxError: invalid syntax

$ ./python
Python 3.8.0a0 (heads/master:62c35a8a8f, Jan 25 2019, 12:00:45)
>>> {]
  File "<stdin>", line 1
SyntaxError: closing parenthesis ']' does not match opening parenthesis '{'
Mm, more specific syntax errors.
Wow. That's an awesome debug improvement.
I guess making the parser smart enough to parse that crap meant that they might as well boost these other things :|
16:48
Those are arguably better improvements than a new syntax.
If I donate money to the python foundation, can I earmark it for "getting the syntax error arrow to point to the right place when I forget a parenthesis"?
Yes, I know it's NP hard or whatever.
It doesn't seem impossible to add "did you forget a parenthesis?" to a syntax error iff it occurs in a statement that is apparently spread over more than one line, and the program contains an unequal number of left and right paren tokens
But maybe it's tricky to check for the presence of newlines at that stage of parsing, as they may have been filtered out already.
17:16
@AndrasDeak but it doesn't highlight properly
@malan they're not equivalent!
17:39
Should I assume that a.b := c is also a syntax error? How about (d) := e?
b := c alone is a syntax error...
I mean, in a context where b := c would not be a syntax error
>>> x = (b := 3)
>>> x = ((b) := 3)
>>> x = (a.b := 3)
  File "<stdin>", line 1
SyntaxError: cannot use named assignment with attribute
Superflous parens allowed 👀 👀 👀
Tentatively filing under "syntactically valid, not because it is useful in any imaginable scenario, but because it would be more work to forbid it"
>>> x = (a.b := 3)
  File "<stdin>", line 1
SyntaxError: cannot use named assignment with attribute
>>> x = ((b,c) := 3)
  File "<stdin>", line 1
SyntaxError: cannot use named assignment with tuple
>>> x = (lambda:'foo' := 3)
  File "<stdin>", line 1
SyntaxError: cannot use named assignment with lambda
>>> x = ((lambda:'foo')() := 3)
  File "<stdin>", line 1
SyntaxError: cannot use named assignment with function call
so much work...
17:47
Dare I ask about x = ((b,c) := (3,4))
no way, should be the tuple one
(it is)
Yeah, I suppose it's not conceptually different from x = ((b,c) := 3). The parser probably doesn't care about the type of the RHS at this point in time
@AnttiHaapala What's the real difference? Both variables come out with the same result, no?
I don't think I heard of the term "named assignment" before I saw these error messages. The PEP mentions "assignment expressions" and "named expressions", but not "named assignment".
I'm a little unclear why the PEP has two terms to begin with.
Today's a really big news day in like everything.
Python, Roger Stone, etc. etc.
Always funny how things co-occur.
wim
wim
17:58
@Kevin no, because that would actually be useful.
@AndrasDeak Is there any reason to do this at all anyway? Like what's the difference between this and x = a[0] = 3?
I've decided I don't even need an arrow, I just want Warning: program contains 17 "(" and 16")" tokens at the start of program execution
I generally just use vim's syntax indenting. If I open a new line after any : statement and it doesn't automatically indent, there's a parenthesis, brace, bracket, etc. msising.
If you have a mismatched number of parenthesis, you need more than a warning haha
Well, they'll get a SyntaxError 0.1 milliseconds after that, so it's an error in the sense that you'll see it shortly before your program crashes.
I guess I consider it a warning because I expect it to occur during the first pass of tokenization of the file. It would be bad if execution halted there -- we want this warning and the proper SyntaxError message -- so it makes sense to classify it as non-showstopping at that point
18:09
Would it really simplify debugging if you're already getting the new debugging message?
>>> {]
  File "<stdin>", line 1
SyntaxError: closing parenthesis ']' does not match opening parenthesis '{'
Seems like it will work on multiple lines, won't it?
if (x == y
   }:
seems like it would work in that case.
Well I'm imagining incorrect programs that look more like:
a = abs(1
b = 2
There won't be a "mismatched parenthesis" error, because there's no closing paren at all
I can't imagine that the general case won't be included if the specific case isn't. It seems to me like people would prefer that to the specific case.
Mismatch parenthesis might not give you the exact place in that case, but at least you'll know what you're looking for? Or will it just be InvalidSyntax still.
I'd think not.
@malan note that I'm the one who started calling it "asspression" so if you ask me "why would you use an asspression here?" my answer will be "you wouldn't"
@malan it's more about nexted cases
Okay. Calling it asspression is hilarious. But what the heck does "it's ore about nexted cases" mean?
print(list(map(lambda x:{x, x+1, x+2}, [1, 3, 5])), end=' ')
18:22
In my experience, "user forgot to close parentheses" is a much more common error than "user closed parentheses with the wrong kind of parenthesis"
@malan edited the typo
if you start having complicated expressions you might not notice that you swapped a ] and a )
Ah, I get it. I thought it was a pun!
Andras, in your future-Python-REPL, what happens if you run Kevin's code
a = abs(1
b = 2
Lol, in iPython I can't even execute it.
My expectation is that the error message would be the same as it has been for a while, i.e.
>>> a = abs(1
... b = 2
  File "<stdin>", line 2
    b = 2
    ^
SyntaxError: invalid syntax
How do you execute it in the repl? I jsut wrote it into a file and executed it.
18:32
::disappointment::
@malan copy-paste
@malan oh, there were two typos. *sigh*
Idk, I just infini-return without ever executing
I don't use iPython, so I can't comment on what it's doing
my regular python repl is the same
nvm
If I type it in in both, I infini-return. If I copy-paste, ipython infini-returns, python-repl executes.
Somehow, I know ipython is better for this, but it annoys me.
> Research has shown that the majority of the Python startup time is dominated by I/O because of the complexity of Python’s import paths and the number of libraries within a typical installation.
Interesting.
Ipython even auto-indents that, expecting a function call
a=abs(1, b=2) is valid syntax
18:38
In [1]: a = abs(1, b=2)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-57c684914bab> in <module>
----> 1 a = abs(1, b=2)

TypeError: abs() takes no keyword arguments
So, syntax wise, sure, but abs doesn't care
It's a keyword assignment. Duh. Wow. How could I forget that?
If by "infini-return" you mean "I can just keep pressing Enter and nothing ever happens, other than more newlines appearing", I would expect that to happen if the first line ended with a comma, for example:
>>> a = abs(1,
... b = 2
...
...
...
...
...
You are correct sir.
Oh. I missed the comma, sorry
18:40
But copy-paste tricks the repl
But it's curious to me that you're getting that behavior even without the comma
Idk but I am
In [5]: a = abs(1
   ...: b = 2
   ...:
   ...:
   ...:
   ...:
   ...:
@malan repl is meh. Empty lines execute blocks when pasted.
You mean when there's a newline in the clipboard and you paste it and the jerk executes before you had the chance to clean it up?
yeah. I hate that. In the shell especially.
can confim ipython
@malan when there's, say, a class definition that has empty lines between methods
that's why I always use ipython
18:42
My biggest reason for using iPython is the whole tab thing. I can't tab in python.
I can, if you mean tab completion
Nvm. Works now. Some installs have caused me problems.
No, i mean initial tabbing.
Like indenting
Ew, that injects tabs. Don't do that.
rhubarb for now
So you just space space space?
rbrb
Here is footage of my REPL raising a SyntaxError right away. i.sstatic.net/H9MAA.gif
18:44
Yup, and space
I prefer spaces, for obvious reasons, but in the repl, if it doesn't autoindent I don't want to press space 4 times.
In vim, expandtab!
@Kevin Interesting, so ipython is the inferior in this case.
Unpopular opinion: tabs are fine if you don't mix them with spaces.
Pitchforks.
# now becomes in PEP505
fruit = val.fruit?.name()
I like that syntax. It's cheeky.
// will use.
list_of_things = get_values()  # could be ``list`` or None
first = list_of_things?[0]
So unbelievably convenient, right there.
Cooler than :=
I use ?. in C# every once in a while. Sure beats doing eight null-check conditionals.
Heck yes.
I get that error all. the. time.
Is it normal to almost always use one expression or the other despite the different meaning? E.g., I nearly always use a.pop(2) almost never del a[2]. This seems like it might be a bad habit.
18:57
It is written "There should be one-- and preferably only one --obvious way to do it", so if you're choosing arbitrarily between two identical approaches, then it's the language that's failing you, and not the other way around
Nice way for me to say "Bad Python, bad."
It's just generally a lot simpler to write
a = b.pop(2)
than
a = b[2]
del b[2]
One might argue that pop and indexed del are semantically different and that pop should be used only when you care about the return value, and del otherwise, but frankly I'm just not fond of indexed del in any context
and if I don't need the value, I don't see any reason to not have the return, I just ignore it.
So you're in my boat.
Cabbage
Is there an efficiency difference?
19:01
What Kevin said. If you don't need the value you're deleting, then don't use pop.
Well, what Kevin really said was, arguably that, but he doesn't seem to care...
I think I once looked it up and the two follow very similar code paths. Performance should be pretty similar.
So there's no real valid reason save "It's Python. Do it the right way, jerk."
@malan Microscopic. pop without assignment still returns the popped object, and then throws it away.
Right, so if there's no efficiency issue, and ultimately there's no breakage, I don't see why I shouldn't b.pop(2) instead of del b[2].
It's not any less readable.
19:04
It's mostly a matter of style.
I don't like Python 2.7 syntax. I can't write print 'hello, world! so I generally avoid non-parenthetical methods like del
I guess I should be using b.remove(2).
Oh, wait, no totally different.
If you're doing some kind of stack or queue manipulation, with pops all over the place, then it would be ok to use an unassigned pop rather than a del. IMHO
You mean if you're already using it in the context, have at it, but if it's a one-off, be proper?
But otherwise, if a reader sees a "naked" pop, they have to pause & think if it's intentional, or if you accidentally forgot the assignment.
@malan Yep.
Lol. Your typo at first made me thing "Uh oh, word I don't know. Gotta google."
19:09
Sorry, I'm still waking up. :)
I'm 30, grew up with computers, and still can't get used to the fact that on the Internet you can talk to people on the other side of the world like it's no big deal.
I assume you're aware that it's more efficient to pop (or del) from the end of the list than earlier list items. Of course, sometimes you just have to pop internal stuff, but if you can reorganise the logic to keep pops or dels as close to the RHS of the list as possible, it will be more efficient.
I'm back from source diving. Ultimately, both indexed del and pop call list_ass_slice. Del has a more circuitous route, but pop has to deal with the overhead inherent to all Python function objects, so it's hard to say which is faster.
@malan :) I'm on the east coast of Australia. It's 6:15AM, summer time.
`del a[0]` compiles to DELETE_SUBSCR
https://github.com/python/cpython/blob/f1ec3cefad4639797c37eaa8c074830188fa0a44/Python/ceval.c#L1648
which calls PyObject_DelItem
https://github.com/python/cpython/blob/621cebe81b1e6c8de10425955bf532d31ee4df42/Objects/abstract.c#L220
which calls PySequence_DelItem
https://github.com/python/cpython/blob/621cebe81b1e6c8de10425955bf532d31ee4df42/Objects/abstract.c#L1747
which calls sq_ass_item, which is implemented in the list type by list_ass_item
https://github.com/python/cpython/blob/621cebe81b1e6c8de10425955bf532d31ee4df42/Objects/listobject.c#L790
19:17
@Kevin I expected a difference because pop can only pop a single item. OTOH, it is a stack-based virtual machine.
@PM2Ring My first thought when you said you were just waking up was "Service industry? It's the middle of the afternoon!" Then I clicked your name and checked your location and was like: Oh, duh.
list_pop_impl returns without calling ass_slice if you're popping the last element of the list. I suspect that del does not have a similar shortcut, so it may be preferable to use pop() in that specific case
@PM2Ring I did know that, but I'm almost never actually coding for efficiency, so I don't really bother worrying about it. I code for efficiency only when something is slow.
wim
wim
del works with slices
That's pretty cool. And makes me a convert.
@Kevin Also, the method is called list_ass_slice? I'm assuming assignment, but... I mean, c'mon...
wim
wim
19:24
it also will hook correctly into datamodel __delitem__, which pop would not.
Tell me the programmer didn't giggle the whole time he was writing it.
wim
wim
On a practical level, pop is more for when you want to consume the item. i.e. you want it returned, and you'd like it also removed as a convenience/side-effect
@wim This is if I have a particular object that I want to do some cleanup with if it's deleted from a list?
wim
wim
I can't help but read these new names in an American accent
dayyyyaammmm that's a list_ass_item you got there!
@malan Fair enough. I like to use the more efficient technique, when I'm aware of the difference, unless it makes the code less readable.
@wim But is it a list-ass item, or a list ass-item? Ref: XKCD Hyphen.
19:33
@malan true that
@malan that's Ruby...
And of course, if you are using a list to implement a stack or queue, you should probably be using a deque instead.
@PM2Ring TBH I mostly do the same when I'm conscious of it, but some things I don't think about (e.g., list efficiency). I was taught to program in Java by an electrical engineer C coder who seemed to know some really obtuse efficiency factoids that have always stuck with me. But it's very hit or miss. I definitely know about list efficiency because I've implemented sorting algorithms, etc., in tutorials, but I rarely think about it.
@AndrasDeak And starting in 3.8, Python!
@wim my favourite cpython internal, list_ass_slice
@PM2Ring You just reminded me of a script that I should optimize in this regard.
> Status: Deferred
19:37
:-(
::disappointment::
I'm confused. It was deferred until 3.8, but now their referenced quote from the PEP isn't there, at least that I can find it.
Status: yeeted to Q4 2019
That sucks. I want those more than I want :=
What does yeet mean
Roughly "throw with great force"
Is it too late to vote? I really want none-aware operators.
They don't want our votes
19:52
Only members of the Dark Council get to vote
If you're not a glowing red monolith, you need not apply
@piRSquared Well put, thank you for that. Yes, I almost half expect that kind of knee-jerk reaction every now and then. Closing the question seemed to make sense to me, so I wanted to check whether it made sense to others as well. I thought about whether it would have made sense even if I hadn't answered that other question, and it did.
@Kevin what anime is this from?
Evangelion.
oho... I haven't got to those yet. Do you recommend the original or the remakes?
When ever I hear of the Python council I think of the Ephor
I found Rebuild to be higher quality visuals-wise but they haven't covered all the material so you might be inclined to watch an earlier incarnation if you want the whole story
The original is still good on its own merits
wim
wim
19:58
PEP 505 looks less bad than assex but really don't want either of them
what is the end goal of these PEPs just offering slightly different ways to do something? are we trying to deprecate for-loops and if-statements from the language?
The steering council will answer your query in 6-8 weeks
It's all for the sake of improving Python's score on Code Golf
With assex, I can inline recursive lambdas without using a Y-combinator. Such power.
I think one of the most ironic things about Python is how expansive their standard library is but how limited their basic syntax is. Like, no switch statement, but I can serialize objects with three different modules.
... At least, I assume (f := lambda x: 1 if x < 2 else f(x-1)+f(x-2))(5)` is legal syntax
I can check post haste supper
20:04
Lets not forget, getopt, optparse, and argparse.
One of my favourite things in Python is the philosophy of "There should only be one obvious way to do it". So it dissapoints me when people want to add stuff that undermines that. Unless there's a really good reason, like with string formatting. And I'm not happy that we now have at least 4 different ways to do that.
I have a feeling that it might run into scoping problems if I pass that lambda into a place where f isn't accessible, but I'm not likely to have a lot of scopes anyway since I'm code golfing. We have file-level scope and list comp scope and that's it.
wim
wim
wow, TIL getopt exists
@Kevin recursive lambdas, yay. Those are a hoot in MATLAB stackoverflow.com/questions/32237198/…
On second thought it probably forms a closure like you'd want it to
20:09
I don't want any of this
@PM2Ring I feel like the limitations are generally just the result of Guido's taste, and not at all well thought out. I've always thought switches were incredibly useful, and do not at all get why they shouldn't exist, except that Guido doesn't like them. pydanny.com/why-doesnt-python-have-switch-case.html
stackoverflow.com/questions/46701063/… claims it would just be syntactic sugar, but do the workarounds have fallthrough statements?
wim
wim
huh, I have an answer there
Heh, yeah. So I ask you: how do you simulate the fall through of a traditional switch?
Code reduplication would be my guess.
Also

> or old-fashioned polymorphism dispatch to objects with differing implementations for the same method).

Is a terrible explanation for what he's describing.
wim
wim
do you mean like
case 1:
  thing 1
case 2:
  thing 2
  break
default:
  thing 3
20:16
Right.
case 1 executes both 1 and 2.
wim
wim
yes, I'm aware
Lol, sorry. Of course you do, you wrote it.
as would if/elif/else? What's the missing part?
But it wouldn't. Once if/elif/else hits a matching conditional, the branch is done.
Oh wait, so a case can execute multiple cases?
20:17
Yes.
wim
wim
sometimes. depends on the language
I think in golang they don't fall thru like that
right
That seems like a massive limitation to me. I always liked the fallthrough. Once I understood it.
And they follow in order of cases?
wim
wim
yeah
if 1 or 2:
    if 1:
        thing_1()
    thing_2()
else:
    thing_3()
"But what if 1 is actually an expression which is very expensive to execute?" you ask. Hey, I've got a great idea...
if (x:=1) or 2:
    if x:
        thing_1()
    thing_2()
else:
    thing_3()
20:19
I mean, I guess you could argue that traditional case fallthrough is hard to debug, but Pythonistas argue everything is hard to debug.
wim
wim
I don't know ... I mean I guess I don't ever write weird nested code like that in the first place
Ok, got it. Thanks. I'm not immediately aware of where I could use such a construct instead of if... and or but I get the concept now
A lot of C people hate fall-through cases. When I was writing C I often used them, but I'd always comment them to make it obvious that it was intentional. I do understand they can make the code harder to analyse, but hey, optimizations tend to do that.
wim
wim
and I've probably seen more buggy switch statements in C than non-buggy ones
people forget the break, or worse they just don't know that it's falling through
Don't even talk to me if your language can't implement duff's device
wim
wim
20:21
somewhat a misfeature
1.) yes, and they often have to debug the problem, but they're always aware that it's a common problem and need to check it.
2.) if you don't *know* about the feature, you haven't properly learned the language.
Right, so I've gained an understanding that "falling through" means a condition that goes unchecked, but actually it can mean a "lower" (specified later) case that gets triggered? And does more than what was intended, rather than nothing at all.
@Kevin Duff's device is one of the most fascinating pieces of code arcana I've ever read.
The most powerful switch I've ever used is in the POV-Ray language. It handles drop-through, and ranged cases. And maybe a few other things I can't recall ATM. :)
wim
wim
shrugs never having the need to use it in 10+ years of professional software engineering in Python, I think I could safely say I don't need it in the language.
20:23
if you talk so much about broken switch statements you might summon a bad implementation of it into 3.9
@roganjosh not triggered, but also executed. In the above example, if case 1 is triggered, case 2 is also executed.
Once the case executes, all the following code executes until you reach a break.
wim
wim
the best argument I can think of is that it would make me feel like I've gone back to the 90's writing switch / case in Python and give me a kind of cheap retro thrill
@malan right, so a Python analogy would be hitting an elif and also executing the if and that would be "falling through" vs getting to the end of an if/elif chain and not triggering a single one of the conditions?
My suspicion is that switch cases with controllable fallthrough are a lot more useful if you're implementing TCP/IP from the ground up, and not so useful if you're writing a login page for your Flask app.
I just feel like most arguments against new convenience features in Python are slightly hypocritical. Okay, the switch statement would "just be syntactic sugar". Well, what the heck is a for-each loop but syntactic sugar for a traditional for loop? Furthermore, what is a traditional for loop except syntactic sugar for a while loop with an incrementer at the end?
20:26
"falling through" if it wasn't intentional to get past the first if
wim
wim
well, you wrote yourself you liked the fallthrough "Once I understood it."
I missed switch & assignment expressions a lot when I first started with Python, but decided that Guido was wise to eliminate them, since they are a major source of bugs in C. So I'm not happy that we've now back-pedalled re assexps.
Lol. Got me by my words.
wim
wim
that, and all the buggy switches around, suggests such a feature violates principle of least surprise
@roganjosh Right. Give me a second and I'll code a pastebin.
wim
wim
20:27
"Pythonic" means different things to different people, but a big part of it is just "clear and obvious" to me.
case 1:
  // executes only in case 1
case 2:
  // executes in case 1 and 2
  break
default:
  thing 3
wim
wim
def myswitch():
   if 1:
      thing 1
   if 2:
      thing 2
      return
   thing 3
Haha. Nice.
@malan appreciated but don't feel you need to go to the effort of trying to explain. You guys have made it clear to me that my understanding of fall through is flawed so I will research. Thanks guys.
IIRC, Ada implements ranges in switch case as well
20:32
@wim I get it. And I'm not a super experienced Pythonista (literally 6 months). But I enjoy that I can just think and code in Python 90% of the time, where, sometimes, I run against a case where I have to stop and think okay, well, that's not valid in Python, I need some alternative construct. Simplest example is switch. I've gotten around it.
It's not even that big of a deal. And truth be told, I code just fine without assex and none-aware operators. But I don't think they'll ruin code legibility and they'll be a boon to my productivity because multiple lines get collapsed into something simpler.
@malan Python's for-each style loop isn't just syntactic sugar, though. We don't have traditional for loops. Our for loops encourage you to iterate directly over sequences instead of futzing around with indices that you don't need half the time (and can use enumerate when you do need them). This leads to simpler code that's easier to read & understand, once you're used to the paradigm.
but they are just syntactical sugar for a while ;)
Lambdas are something I've never felt to be all that useful. I understand some people have use for them, but I've never had a personal use for them.
Not for lack of trying to learn.
lambdas are strictly speaking superfluous
python is syntactic sugar for C
At least, CPython :P
20:34
@PM2Ring I like the for-each style loop. But Python has a fuzzy half-interpretation of "we're all responsible users" and this is a great case. Why can't I modify the list as I iterate?
If I'm a responsible user, than I shouldn't be prevented from doing something because of side effects. I should just be responsible! That's the argument regarding private class variables.
@malan but you can?
Only if I do for i, val in enumerate(ls):
Why can't I access the var directly in a for-each loop?
^ That isn't "can't"
@malan if you are modifying destructively, you can iterate in reverse as @wim once explained to me
If you wanted for x in seq: x *= 2 to mutate all the elements of seq, I think that would require a substantial retooling of Python's memory model.
20:36
I would love to be able to do this:
for item in ls:
    item += 1
Which you could do much more easily and much faster in numpy
@Kevin I can understand that. If it's implementation spec. I get that. But often the reason for these corner-cases is "To make code more readable"
@malan iterables don't typically work with += 1
@AndrasDeak haha, PEBCAK. Fixing
@malan the new version works
it does what it's supposed to
20:38
It increments the whole list? I remember cases like that just iterating with no side effects. The list stays the same.
ints are immutable
try with a list of lists and item += [3]
>>> seq = [[], [], []]
>>> for item in seq:
...     item.append(1)
...
>>> seq
[[1], [1], [1]]
wim
wim
you seem to need to read the "other languages have variables, python has names" thing.
If we want to change assignments so that they mutate the value of the object bound to the name, then it's going to impact a lot more than for loops
@wim Link. Because clearly I do and this will help me understand Python design choices.
20:41
I don't actually see how that language could be as accessible as Python
wim
wim
just thinking of the local namespace as a dict removes all surprises from Python
I can't be sure, but if I had to start on my job with C, I don't know whether I'd have built anything or had an interest in programming
Jun 9 '18 at 5:14, by PM 2Ring
May 14 at 6:35, by PM 2Ring
Mar 21 '17 at 8:27, by PM 2Ring
@Drizzy In the mean time, here are a couple of articles that explain a very important difference between Python and most other languages. Other languages have "variables", Python has "names", and Facts and myths about Python names and values, which was written by SO veteran Ned Batchelder.
@wim This is interesting. I've been programming Python with a terrible mental model.
the chain continues AD :D
20:44
First link dead. Reading the second.
wim
wim
the for-loop is just a "moving nametag"
wow it's becoming like the n-dimensional kevin thing.
Let's see if the Wayback Machine has a copy... Yep. web.archive.org/web/20180411011411/http://python.net/~goodger/…
I'm going to print these and read them tonight.
I will mention one thing I'm generally annoyed by.
I want i++
wim
wim
you probably won't want it after you read those.
Lol. Okay.
wim
wim
20:49
because you will realise it's a type of assignment statement, and it doesn't look anything like an assignment statement.
As long as I am unable to remember what i + i++ + i does, I don't want it in any language I use
I'd just shoot the programmer, not the language.
I do have trouble with ++i vs i++, though it's more a memory issue and not a conceptual issue.
wim
wim
++i is valid python
What does it mean?
wim
wim
depends what type(i).__pos__ says it should mean.
20:51
@Kevin Thanks. I wonder what happened to python.net. It just disappeared sometime last year. So all the links to Other languages have "variables", Python has "names" I've posted all over the place are now useless. :(
And those lines of code must really be irritating. I wonder if the other 20 you'd also be writing in C to do the reverse irritate you
Time to purchase the domain and rehost that single page
Hahaha.
wim
wim
so ++i reads like fairly normal python to anyone familiar with the datamodel. but i++ does not compute ... it's confusing like ... wait everything is an object ... i++ is i plus the + object?
i++i is ok though!
ack, I think i'm making Python sound more confusing than it really is here...
Both articles printed.
20:58
@wim Exactly! I picked that up pretty quickly, due to my experience with PostScript. Although in PostScript the syntax is more transparent that you're binding a name to an object in a dictionary, or retrieving an object from a dictionary. It's actually more versatile than Python. You start with a default dict, but it's considered good style to open a fresh one.
I am eternally mildly irritated that a += b is not just syntactic sugar for a = a + b
And you can have as many dicts as you want, either named or anonymous, and they sit on a stack.
There are a hundred use cases for why this is terribly useful, and yet...

« first day (3023 days earlier)      last day (2149 days later) »