« first day (3076 days earlier)      last day (1871 days later) » 
00:00 - 18:0018:00 - 00:00

wim
6:00 PM
trying to imagine a world where SQLAlchemy doesn't work with the best database backend, but is still a thing ... nope, does not compute
 
@Dodge You can also use it to write generic DB access that's agnostic to back-end storage engine. E.g. develop in SQLite, deploy in staging to Postgres, deploy to production on Oracle.
 
huh, never used SQLAlchemy. had the option to use it once when building something with flask, but i opted for the comfort of sqlite at the time since i had used that before.
Curious. Would modifying sqlite based code to SQLAlchemy add some overhead? Would it even be worth it?
 
In the DAO/ORM ecosystem, SA has pretty much won. (Vs. competition like SQLObject, Elixir on top of SO, …)
 
Who wants to go back in time with me and prevent Oracle from being founded? Safety not guaranteed.
 
wim
you can't opt for sqlite instead of SQLAlchemy they are different things
 
6:01 PM
Actually, you totally can.
SQLite via DB-API, SQLAlchemy connecting to anything via its API, including SQLite.
 
Awesome!! And to reiterate the process: Learn just enough SQLAlchemy to allow me to insert my scraped weather parameters into the db every night and then access said parameters as I've been doing through a django view... does that sound right?
 
if SQLAlchemy is model agonstic, i assume i can link an SQLite db at the backend of it?
 
wim
no
if you're using Django, use the django orm. forget sqlalchemy.
 
@ParitoshSingh Yup, as mentioned, you can write your DB API interactions such that your own application is entirely agnostic to back-end storage.
 
wim
and if you're using django, don't let anything else write to your db except your django app.
 
6:03 PM
and I can use the django orm in a stand alone script
 
wim
no
go through the django app
 
well how to i set a chronjob that activates a view to grab data
 
wim
use an API served by django
 
Django's ORM has… repeatedly demonstrated pathological cases to me. JOINs that are guaranteed to never complete before the heat death of the universe and such. ;P
 
@amcgregor nifty, i'll keep it in mind, perhaps if we ever face a similar situation in the future.
 
6:04 PM
Basically, any time you successfully write a complex query, immediately EXPLAIN it to see where the ORM has gone wrong, and tune. ;P
 
wim
multiple apps using the same db opens up a huge can of worms you don't want to open
 
^
When in Rome, do as the Romans do.
Thats why, i left rome for flask. :P
 
That's why I looked at Flask, went, "still too fat," and wrote a framework a third its size. ;P
 
I am comfortable with Django so that is where I want to be... I just thought I would have to do something that's separate because it must get the daily values automatically, whilst I slumber
 
wim
so you write a view that serves those data you want to get daily
 
6:06 PM
(Like, who thought it was a good idea to tightly bind a generic application framework to extremely specific tools like Jinja2 for templates, or bundling an ORM in Django's case…)
 
I do think though, from a maintenance point of view, especially when you need to do work that perhaps someone else may maintain, its a really bad idea writing "ghetto" solutions that break the traditional route and subvert expectations.
 
wim
and then you write code that requests that url daily
what's the problem?
 
None.. I can do that. the only automatic way to execute code at a given time every day that I know is with chrontab
 
@amcgregor Frankly, for those who dont "need" something else, the convenience can definitely be felt. And for those who need something very specific, they probably know what they're doing and can go even more minimalist.
 
wim
@amcgregor It evidently was a good idea because the monolithic approach (i.e. Django) is arguably still the most successful Python web framework
 
6:08 PM
Django is definitely a successful framework, and many people/companies vouch for it. I think the use case dictates if its a good fit or not.
 
@amcgregor the tight structure of Django is great for people like me who do not know what they are doing... I jumped out of an airplane long ago and have been building my parachute since
 
@ParitoshSingh "More" minimalist. I counter that with: django.template (by itself; no other part of the framework) rendering a 1000-row, 10-column table a total of two times per second vs. just shy of 40,000/second.
"Tight structure." Tight… like a tiger? ;^P
 
Aye, i was thinking of essentially your work when making that statement. :P
At the same time though, i recognize, that for many problems ive worked on in the past, i never needed to generate a table faster than 1 second. And i can see people in similar positions.
 
wim
@Dodge that is fine. I assume you're just misspelling cron.
 
From past projects that have imploded directly due to Django scalability issues, a parachute built with Django will accelerate you faster towards the ground. >:P
When I was giving presentations at conferences, it was the opening joke, "Raise your hand if you've built a blog with Django." (most hands go up) "Now keep your hand up if you've built anything else with it." (all but two hands go down)
 
6:12 PM
yeah, ok thankyou @wim @ParitoshSingh @amcgregor
 
wim
you know Instagram is running on Django, right?
 
@ParitoshSingh I generate hundred-megabyte RSS feeds containing thousands of complete job offer descriptions and application information. If this were built with Django.template, or Jinja2, or even mako (which it formerly was), it would not scale. Individual feed generations would take > 30 seconds, time out, and nobody would get anything.
 
wim
when you see anything with even 1/10 that scale of traffic running on some hipster framework let me know
 
Now the RSS feed's TTFB is instantaneous, they don't time out, and not one takes longer than 5 seconds. ;P
 
@amcgregor Nifty. That's precisely it though, the usecase should dictate the tools, not the other way around.
(though if the tool is TOO ugly, i may have to make an exception for it. sorry PHP, i am just not into you)
 
wim
6:16 PM
I call bs on your "past projects that have imploded directly due to Django scalability issues"
I've seen many times people blaming the framework when the real problem was they had a bogus schema or didn't know how to make sure the queries were sensible
 
@wim RIP matchfwd.com after getting Life Hacker'd and Hackernews'd the same week. Specifically tied to Django↔︎Celery interactions, excessively complex unoptimized DB queries as generated by the ORM, and Redis congestion.
 
wim
sure, using Django ORM allows you to write queries that won't scale if you're not careful. But it's your responsibility to have some understanding of SQL and make sure you've got a well designed schema
 
We had Redis and Celery nodes with >100 LAs that were still processing work units… somehow. It'd be a cold day in heck if I could connect to one of the nodes, but the work units were still flowing… >:D
@wim Not my queries. Celery's queries.
 
wim
so we've gone from "directly due to Django scalability issues" to "Celery's queries" ?
hmm.
 
Yes, Django ORM producing technically correct, but insane queries to facilitate Celery's use of that ORM.
(Pro tip: don't enable statistical collection in Celery if you think you're about to become popular.) Reinventing the wheel ourselves to write a new task worker RPC-like system to avoid that scaling problem, it was nearly trivial to construct a distributed task and announcement queue then reliably fire off 1.9 million DRPC requests per second through it… 6 years ago. (5.7m inserts/second accounting for announcement messages.)
Later expanded to utilize the Futures API, providing a DistributedExecutor, and extended to support distribution of chained generators.
… and in no way tied to any web framework. Like the Gods intended reusable utility libraries to be. ;^^^P
 
6:32 PM
@wim so when you say "use an API served by Django," can you think of any examples so I can see what that looks like?
 
wim
just vanilla wsgi request/response stuff. so in the case of Django you would have a route in urls.py, pointing to a view in yourapp/yourviews.py or wherever
and in the script called by cron you can import requests or urllib or whatever and get the data from the url setup in your webapp
the important point is that the Django app "owns" the db, and is the single point of entry for data going in/out of the db. your script will not have credentials for the db, it will have credentials for the Django app (usually token auth).
 
ohhhhh..... I get it now ok ok . thanks!
Im out.. y'all have a good one
 
wim
ciao!
 
Enjoy!
 
Cya!
I was reading up on some things because of the discussion here. Ended up here, not exactly related. But docs.python.org/2/howto/webservers.html has no python 3 version apparently?
 
6:38 PM
Yikes, so many Wiki-like places to update… :scribbles a note:
 
wim
@ParitoshSingh huh, never seen it before. Guess core devs rightly decided the official docs was not the right place for such an article.
 
Its a super useful article though, and ties very well with python. As a reader myself, i am only concerned if its up to date for python 3 or not, and would not mind seeing this in python 3 docs, official or not.
Curious, why would you reckon it shouldn't be included? Is it primarily because it has to tie into external resources?
 
@ParitoshSingh When in doubt, read the spec. PEP-333 being the original WSGI under Python 2, 3333 expanding that to cover Python 3 concerns.
If that wiki page does a better job explaining some concepts, I'd highly recommend submitting clarifications for the PEP, if possible.
 
Ah, ive seen that before. I've read that but it was a bit beyond me. Very useful though no doubt. But it talks about the interface itself as per my understanding (awesome!), which is not sufficiently abstracted enough for someone looking to just get up and running.
Its the latter portion that the howto link seems to address, talking about the options out there, and how they tie into the bigger picture, though perhaps at a higher level.
 
The reason I quipped about Wiki-like places, is that I distinctly recall adding my own to a Moin wiki listing of web frameworks somewhere. Too many separated locations for this type of reference material. T_T
 
6:48 PM
Yeah, thats definitely true.
Actually, aside, i am super impressed with python docs in that regards. Once you get used to looking things up there, its got a lot of things you would ever need to know
Some real solid work went into developing the python docs
 
I don't trust any internet-facing modules to remain consistent between Python 2 and 3, both in composition (e.g. urllib.urlopen is now at urllib.request.urlopen) and idiomatic usage (e.g. if it was ever cool and trendy to use cgi, it isn't now)
 
One of the 1-day lightning code challenges I participated in I built an aggregator of Intersphinx indexes, with rapid jump-to-symbol a la PHP.net/<symbol> lookup. localhost/ThreadPool → immediate jump to the ThreadPoolExecutor API reference. (Or add other projects to the index like SQLAlchemy, or Django, or…)
 
wim
@ParitoshSingh coz it's not about the language itself, it's about something the language can be used for ("application"). if you have a webapp howto, next you're gonna need a data science howto, and then where to stop?
plus articles like this have a habit of going out of date as nobody could be bothered to maintain them indefinitely
 
@wim Yeah, thats pretty fair.
 
7:09 PM
hi all what is for _ syntax in python ? I try to google but no-outcome ?def staircase(n, X):
cache = [0 for _ in range(n + 1)]
cache[0] = 1
for i in range(1, n + 1):
cache[i] += sum(cache[i - x] for x in X if i - x >= 0)
return cache[n]
 
_ is a common name for a throwaway variable
 
ok thx.
 
(it also has slightly special meaning in an interactive shell, but that's irrelevant here)
in a proper python script _ is just a valid name
 
I was just reading a code style guide suggesting using '__' instead of just '_', to avoid collision with '_' for interpreter semantics and also where it is used as a shorthand for gettext()
 
"shorthand for gettext", I've seen that somewhere. Isn't that some third-party gimmick?
 
7:12 PM
now you're going to make me look it up...
 
neither of those arguments strike me as particularly convincing
 
Better idea: use a better alias for gettext than _
 
when you're using _ right it will never clash with the interactive shell, and ^
 
Here it is - Hitchhiker's Guide to Python: Many Python style guides recommend the use of a single underscore “_” for throwaway variables rather than the double underscore “__” recommended here. The issue is that “_” is commonly used as an alias for the gettext() function, and is also used at the interactive prompt to hold the value of the last operation.
 
Can confirm, _ is broadly the "singular translated string" function. (With L_ being the lazily resolved form, __ handling plurals, and further single-letter prefixes for various translation duties.)
 
7:16 PM
Ugh, the documentation suggests using _ = gettext.gettext
 
Sam
@AndrasDeak follow up from earlier regarding the multiple function returns in the stack trace... is it bad if by my design I end up with hundreds of hanging function waits in the trace?
 
(N_umber, D_ecimal, P_ercentage, C_urrency, …)
 
@Sam "hanging function waits"?
Do you just mean recursion that's a few hundred calls deep?
 
Sam
Not sure on what to call them but the items in the image i posted earlier
 
you're fine but when you start nearing 1000 depth you'll get a RecursionError
 
Sam
7:19 PM
probably not far off that tbf
 
yup, then you have to consider rewriting your algorithm to iterative rather than recursive
$ python3.7 -c 'f = lambda: f(); f()'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 1, in <lambda>
  File "<string>", line 1, in <lambda>
  File "<string>", line 1, in <lambda>
  [Previous line repeated 995 more times]
RecursionError: maximum recursion depth exceeded
 
Sam
ah that sucks
 
you could increase the maximum recursion depth but that's generally considered bad form (and unsafe, because the limit is there so you don't blow your stack)
Why are you even looking at stack traces?
 
Sometimes applications just need to recurse a lot.
As long as there is some limit, then runaway/infinite recursion will eventually hit it
 
Sam
when i was stepping through my code in the debugger it kept bouncing between recursive calls when it should have been returning from the function.. That's when i started looking at it
 
7:23 PM
so make sure you don't have a bug that's giving you an infinite recursion
 
At work we do torture-testing on file system manipulation, with very deep directory trees - 1000 limit just isn't enough
 
or just bad design that leads to too many calls
@PaulMcG sure, but I'd expect an application like that to involve a good, educated guess, rather than "let's set the recursion depth to 10k and get it over with"
 
/me kicking dirt, looking at shoes...
 
Sam
could be a poor design on my part.. but im just going to go with the flow until i refine it later. Just need to get something running for now. Hopefully within the recursive limits
 
random tidbit
if you are doing recursive stuff that requires a lot of depth, avoid generator expr*/list comprehensions
 
7:26 PM
i know
 
because they rely on stacks to implement non leaky scoping
 
i got this dynamic programming solution
def staircase(n, X):
    cache = [0 for _ in range(n + 1)]
    cache[0] = 1
    for i in range(1, n + 1):
        cache[i] += sum(cache[i - x] for x in X if i - x >= 0)
    return cache[n]
I cant figure out how it works it says its much better
O(N*|X|) insteand of O(|X|**N)
 
Please use fixed font for code
(Press Ctrl-K)
 
def staircase(n, X):
    cache = defaultdict(lambda: 0)
    cache[0] = 1

    for i in range(1, n + 1):
        cache[i] += sum(cache[i - x] for x in X if i - x >= 0)

    return cache[n]
I'm always a fan of defaultdict for this type of use.
 
cache = [0 for _ in range(n + 1)] might be more clearly written cache = [0] * (n+1)
 
7:31 PM
so, context? what does X have/represent?
 
I love defaultdict too, but this is just a straight up list - I don't see where the defaultdict goodness applies here
 
the main thing though, is that values in cache are being reused to calculate values for catche[i] and so on.
thats probably why its better. the other part of the puzzle that you didnt provide probably is re-calculating everything
 
N is stair number,X is a set e.g.X=[1,3,7]
It counting how many ways it can get to stair Number X using the set X
 
@Mookayama stair number n*?
 
@PaulMcG It eliminates the need to pre-calculate the entire possible list of available choices in this particular case and allocate the entire list. I didn't do that here, but you can totally break out of that for loop after the nth element. In the original, there are two complete iterations of the elements, which can be a warning sign.
 
7:34 PM
e.g stair=4, set =[1,2]
1+1+1+1,1+2+1,2+1+1....
 
(The list comprehension calculation would block just to produce a bunch of zeroes. Don't block and allocate, just assume any index you access will be zero on first access.)
 
huh, its a nifty problem, neat solution too.
 
i cant figure out the dynamic programming one
it takes me a while just to figure out the recursion one
 
So, first things first, are you okay with the idea that this is O(N*X)?
 
not sure
and why the recursion one is O(N**X)
 
7:39 PM
take the recursive solution first, apply it to a simple case, such as stair = 4, set = [1, 2]. Then, make stairs = 5, and repeat the same thing in your mind
you'll notice that, you can either do everything from scratch, or potentially reuse the calculations you had, up until stairs = 4 from the previous calculation
That's where you get into the idea of caches and whatnot. But first perhaps i'd say, just get an intuitive idea of why "reusing" results can help.
Do you notice the core concept at work here? If not, just think of stairs = 6, and so on. See if you can't spot the pattern developing automatically.
 
Ultimately, I'd explicitly not take this approach, given the obvious pattern. This is like counting your jelly beans by taking them out of the bag one at a time, when you could get the count in a single operation by measuring displacement. In this case, it's not too dissimilar to superuser.com/questions/129511/… with a slight variation. It should be entirely possible to calculate directly.
 
afternoon cabbage
 
oh okay i kinda get it. its thinking reverse. let say how many ways I can get to step4 if i start from step3/step2/step1/step0
 
bingo
 
7:52 PM
this is neat haha there is the second time i see this approach
 
the idea is, saving those results makes life simple. the "thinking in reverse" is basically recursion, and saving is basically the cache combination
 
Anyone ever use Achilles number on a project
 
I'm still perversely proud of the "call stack emulator" I wrote last month that uses a list of coroutines to simulate an environment with no maximum recursion depth
 
… isn't that a core hallmark of continuation-style programming? The (near) complete elimination of that stack concern? (Ref: Stackless Python as one example implementation.)
 
99% of the time you should just make your function iterative but sometimes you just gotta iterate your binary tree the way you want
 
8:01 PM
umm the stack makes recursion elegant
 
Let's see... "In computer science and computer programming, a continuation is an abstract representation of the control state of a computer program. A continuation reifies the program control state, i.e. the continuation is a data structure that represents the computational process at a given point in the process's execution"
 
Baum and JFF are the two new moderators
6
 
Yeah, that kind of sounds like what I'm doing there. I reified the call stack into a list that's accessible by the code.
 
It seems Josh Caswell is the runner-up
 
yup
too bad, I'd have loved to see Makoto become a mod
 
8:04 PM
Every time I contort my mind into a corkscrew long enough to do something fun with generators, I automatically assume that I've created an ad-hoc, informally-specified, bug-ridden, slow implementation of half of a feature that functional programmers came up with in 1950
 
Baum was overdue IMO. Was surprised he didn't make it last time
 
yup, yup
very happy to see him elected
 
I think this is the first time I voted for someone who actually ended up winning
 
@Kevin I got that reference =D
 
@Rick can you give some example on what is a powerful number?
 
8:10 PM
Honestly, I was expecting a larger landslide for Baum
 
I told y'all that anything can happen in the finals
 
yeah, much to your displeasure :p
 
Wow, Makoto dropped out much earlier than I expected
 
same here
 
@rick nevermind its in wikipedia
 
@Mookayama not all powerful numbers are Achilles numbers keep that in mind.
 
8:34 PM
Cbg
 
cbg
 
Anyone have suggested answers/canon regarding using list comprehension as a way to execute a function/functions?
 
what does cbg mean, is that insider lingo for wazup
 
Means "cabbage."
 
yup
 
8:36 PM
@Rick Salad — see the room description link.
 
@AlexanderReynolds i am guessing the answer being, dont do it?
 
Lol, yeah presumably
 
O, well cbg to all
 
I mean the obvious thing is unnecessary memory overhead to store the list of values if they are just procedures
 
procedures?
Oh, as in function that returns None?
not a typical name in python I think
 
8:39 PM
i think the term you're looking for in that case specifically is "side effects"
 
Yeah same difference. I just really like the word procedure to describe functions with side effects that don't return anything.
 
I don't think we have a canon entry for that
 
Functions with side effects can still return stuff too. Of course this is meaningless in Python anyways since all functions return something. But w/e
 
@AlexanderReynolds I only know the word because I happen to know that fortran subroutines are the same thing. "Procedure" rings turbo pascal bells.
 
Right. I actually like that separation from Pascal.
Anyways! Just wondering if there's any particular reasons to avoid it aside from the obvious.
 
8:41 PM
It's considered bad form to create a list comp for side effects, only to throw away the list.
 
if you need to make a list, make a list. i dont think theres anything else as such. its just when you dont need a list at the end of it, that its bad
 
Same thing as printing in a list comp: list comps are not shorthand for a loop.
 
Yeah of course, just wondering if there's anything stronger than "bad form" and "unnecessary memory overhead"
 
What else would there be? Voice of God?
 
nope, thats pretty much it.
 
8:43 PM
Stronger than a stylistic/semantic and a performance reason? :P
 
Lol fair enough
A stronger reason could be "it breaks in this case"
 
nah, it's one-to-one interchangeable* with a for loop I think, so it should be safe
maybe something about scopes...
 
unless its a really big list, i dont see much issue with it.
 
To me it's similar to calling functions in a lambda.
 
you can use a lambda to curry a function and it could be idiomatic
Unless I misunderstood what you were saying there.
 
I'll check later, if that's good we could canon it
 
Is there a way to get '\x8b'.decode(...) to work in pythoff? Where I don't know what ... needs to be
 
I haven't spotted any footguns yet but it should be sufficient to use as a close vote
 
Would I have to do ('\xc2'+'\x8b').decode() to get it right? Cause '\x8b'.encode() in Python3 produces b'\xc2\x8b'
 
@WayneWerner Kinda confused what you're trying to do... what do you expect to get from '\x8b'.decode(...)?
 
8:56 PM
the same thing I get from b'\x8b', tbh. Working in a Python2/3 codebase... but I have a sneaking suspicion that encoding is all fouled up throughout here -_-
 
sounds like not-fun
 
Are there incompatibilities between py2/3 in regards to encoding/decoding? As long as you don't call str.encode or unicode.decode, nothing should go wrong, right?
 
recbg
 
@WayneWerner I still don't get it. '\x8b'.decode() in py2 does the exact same thing as b'\x8b'.decode() in py3
 
9:29 PM
I think he wants u'\x8b'...
 
@Aran-Fey There were certain "utility encodings" that disappeared for a while, but they were eventually added back, I believe.
 
>>> '\x8b'.decode('latin1')
u'\x8b'
 
sounds like a good opportunity for a mojibake ;)
 
Might be worth running through github.com/LuminosoInsight/python-ftfy#readme
(FTFY. It Fixes Text For You.)
 
10:07 PM
@roganjosh that one is pretty good! thanks
@roganjosh was actually for a response to a question on /r/learnpython
 
It's one of those things that would be hard to demo properly to a new user because it ultimately comes down to "we don't do that" rather than "look at everything exploding"
Then again, maybe there's a nice simple demo of everything exploding :) Off the top of my head, I couldn't think of one tbh so that might be the best Q/A I can find on the topic
I'm having a bit of a brain fart on how to research this. If I use .loc on a DF with multiple conditions, and I think the first condition will be vectorized and would trim down the search of the second condition, can I expect that to happen, or will both conditions be applied to the whole DF?
df.loc[(df['country'].isnull())
       & (df['state'].str.upper().isin(states)), 'country'] = 'us'
 
there's no magic
it does what it says on the box
(df['country'].isnull()) & (df['state'].str.upper().isin(states)) <- that's a logical array Series
assuming I understand your question
 
So really what I should be doing is pull df['country'].isnull() out of that and make it a sub-dataframe before doing the other conditional search
By sub-dataframe, I mean assign it to a new name
 
Yup, that would make a difference. I don't think logical_and can short-circuit, unless pandas magic.
I don't know whether you can mutate the original dataframe that way, though.
if they were numpy arrays then you wouldn't be able to.
 
Ah poop, you're right
No, I'd speed up the search but then I'd have a mess trying to put it back into the original DF
 
10:21 PM
Middle-ground: inds = cond1; inds[cond1] &= cond2[cond1]; df.loc[inds]
 
Then it comes down to whether assignment to the original DF is worth it, and for an SO answer I think I'll stick with the not-deeply-optimised-on-a-hunch answer
 
Re: comprehensions & side-effects, I was pretty happy with what I cooked up:
Considering that l = [i for i in range(5)] is equivalent to
l = []
for i in range(5):
    l.append(i)
 
and list(range(5)) ;)
 
then [f(i) for i in range(5)] is equivalent to
l = []
for i in range(5):
    l.append(f(i))
del l
which is obviously not how you would do it. So, don't write code that is equivalent to it.
 
That only makes sense if f() returns nothing, otherwise it's perfectly valid.
 
10:25 PM
note the del l
 
I mean, barring the del l
 
well thats a different discussion, obviously :)
 
a = [print('hello') for x in range(5)]
 
bad code, baaad! ^
 
"how many non-Pythonic things can you spot?!"
back of the cereal box games.
 
10:27 PM
needs more walrus operators
 
Yeah, but the point is that you can then print(a) and show a list of None
 
why is that a point
lol
 
It's not a good point, but a point none the less ;)
 
Maybe I'm missing something here. I thought we were talking about list comprehensions for side effects?
 
We are. Not for return values.
purely procedures, not assigned back.
obviously a = [f(i) for i in range(5)] is valid/useful
 
10:29 PM
print returns None. It's a good example of a garbage list comprehension. There's nothing wrong with [f(x) for x in range(10)] if f() returns something
 
okay im not sure why we're all confusedly kinda arguing, we all know how this works and we all agree anyways
lol
 
I was trying to give you an example to show to a learner that shows that list comprehensions for side effects was bad
 
Avocado
 
print() is a very obvious side effect they can see, and it leaves them with a list of None
 
10:30 PM
but what it really leaves them is "this quick way to print without having to write a loop" ;)
 
yes yes. indeed.
what are y'alls thoughts on functions with side-effects anyways? do you try to separate out functions that have side effects so that your functions either only mutate or return something but not both?
 
@AndrasDeak "list comprehension" and "without a loop". Even though my intro to Python was not too long ago, I don't know what is triggering this thought process :)
 
newlines are way too much trouble
 
So many people wanting to cram so much into one line :/
 
@AlexanderReynolds my thought is "Stop trying to make procedures happen. They're not going to happen" :P
 
10:33 PM
@AndrasDeak lol
alright FINE
EDITED IT
HAPPY NOW?
 
YES THANK YOU
 
GR8
WATERMELON
 
@AlexanderReynolds Why are either of those a side-effect?
The point of the list comp is to build a list. What difference does your example make here?
 
The person was using a list comp to run functions. Not actually build a list.
The functions thus didnt return anything useful, they just had side-effects.
But my question above was just broadly speaking, nothing to do with list comps.
Some people have strong opinions, for e.g. "a method should either mutate state, or return a value, but not both"
 
The way you stated that question though doesn't make sense to me
a = ['1', 'hello', '2', 'something']

b = [int(x) if x.isdigit() else x for x in a]
Sometimes I call a function, sometimes I do something else. At the end of the day, I get the list I want. Side effects never come into it
 
10:38 PM
Yes, because those functions return something.
 
hence his point about "procedures", i.e. functions that return None
 
The line is really "don't use list comprehensions for side effects". Neither of your cases covered that
Then surely the answer is "we don't use them"?
 
I'm not talking about list comprehensions anymore.
 
The del l covered the "side effect" part. You only delete the list if you don't care for the contents.
 
If you want examples of what I meant, let's take a look at a list. You have indexing, which is a pure function that just returns an item. You have mutating methods, like .append() which returns None but modifies the list in-place. Then you also have methods that do both, like .pop(), which both mutates the list and returns an element.
 
10:50 PM
And I have used .pop a sum total of zero times. Maybe it's good for consuming a queue, I just don't have any of them.
 
Semantically speaking, the point of pop is to grab an element. I can totally imagine a filtered listcomp that pops items off a stack or something.
 
But wouldn't this also come under the modifying a list while iterating no-no?
 
I've occasionally used a listcomp for running functions (or methods)
like...
 
@roganjosh you're not looping over the stack in my scenario
 
[knight.answer_question() for knight in party]
but that's usually shorthand - when I'm writing proper code I'll just do it on two lines
for knight in party:
    knight.answer_question()
 
10:56 PM
current_order = [pancakes.pop() for person in guests if person.table == this_table], something like that
 
@WayneWerner you still get a list of knight objects with their state changed
 
Oh sure, I'm just not doing anything useful with it
 
note that this is contrived and I've never done something like this but I can imagine it being useful
@roganjosh assuming the method doesn't return None
 
(that also assumes that party is a list or that answer_question() returns the knight)
 
All of this is just reminding me of Theresa May before Brexit even existed
Um, well not the bit from The Office, but the interview :)
 
00:00 - 18:0018:00 - 00:00

« first day (3076 days earlier)      last day (1871 days later) »