#pedagogy
1 messages · Page 11 of 1
JavaScript actually uses protocols as well, to some extent.
- iterator/iterable protocol
toJSONtoString
C++ concepts and type traits also let you do this (at compile time).
Template functions in C++ in general are duck typed.
does someone know anything to learn the basics of python because im a new one in the coding world?
You should ask in #esoteric-python , this one is about teaching in genwral
@buoyant tinsel that's... not the right channel 🙂
@violet ore amogorkon meant #python-discussion
Wtf.. sorry, fucking hate my mobile
Channel completion messes up
I'm so sorry, esoteric python is the last place to learn the basics shame
That would be a good sketch comedy, a young person trying to learn python by only reading #esoteric-python 😄
oh oke sorry my bad
Making sure nobody else can learn python is a great way to achieve job security
Sometimes on my mobile I get micro lag, causing me to click on random buttons etc, sometimes I almost end up sending PMs to complete strangers because of it
i'll be honest.
thats actually what i did.
when i was first learning python, i was annoyed by how long it was taking me to learn the advanced stuff. so i read loads of #esoteric-python. it was actually really helpful- it made me understand the most obscure parts of the language and how it works to a much fuller extent.
to be fair, i did read normal python resources too. but if you want to learn the complicated parts, #esoteric-python is the best channel.
High everyone
Is anyone here interested in getting involved on working on a project
Preferably of you can use django
@vale grail this channel is about teaching. Maybe #python-discussion would be better?
Okay, thanks
If this channel is about teaching, then how do I learn about windows command prompt and directories and all of that for beginners
this channel is for discussion about teaching, you could ask in an off-topic channel since your question is not about python
im making a menu driven program for shop management using python-mysql i have created a function for new account creation but i want the program to show data of existing user like login thing or something how to make that ?
thanks
Is this the right channel to ask for a list of known 4 year colleges/universities that teach CS using Python instead of Java/C++?
try #career-advice
Anyone know about web servers
#web-development please respect channel topics
Ok
I think my question is right in between the two. To clarify, this channel is for teachers/content creators developing curriculum?
it's for discussion about how to teach CS
Soo... not what to teach in CS? Just how?
Both
What's your question?
Yes
I'm starting to think the channel name needs a change
I proposed this channel with this name, leaving it open to discussion if another name should be selected. It was actually unanimous that this name would be the least likely to attract off-topic content.
Soo... not what to teach in CS? Just how?
This raises an interesting discussion topic
Topic: My theory of computation course discussed finite automata, push-down automata (PDAs), and turing machines. I think the course would have been a lot more pointed if PDAs were omitted entirely. Did anyone else take a course that was specifically about theory of computation? What did you think?
It also wasn't clear after taking the course how quantum computers would impact computation theory. I came away thinking that they were just high-performance computers that use physics shit.
and I the "does P == NP?" question was poorly explained. I didn't like that course 😠
How to teach CS or how to teach Python?
Somewhat related but not quite the same.
I think there is a Python focus since this is a Python server. In a sense, CS topics come in from time to time, but there is a growth of teaching python without teaching underlying fundamentals.
Now I believe everyone has their opinion on the need for fundamentals, but the market is just reacting to the need for programmers
I'm not sure if it's clear how quantum computers would impact computation theory. The only thing I believe is that superposition can be abused in a sense for 1 level of exponentiation, but other than that I'm not too sure. I should say I only know from pop sci rather than a proper course though
@echo iron that question is off-topic for this channel. Refer to the resources page on our website (link in a recent post on #announcements)
I did, what's wrong with PDAs? Wdym by pointed?
both
finite automata and regular languages are relevant to regular expressions. And then Turing machines are the underpinning of what is computable. I don't really think PDAs are that important except to convey that there are models of computation more powerful than finite automata, but not the best known model.
hey im new to python i was wondering do i have to have a UI to make the app work can i just make a shortcut that uses that specific script?
aren't quite a few parsers PDAs?
yeah
this seems like a question for a help channel, ask with more details in one. You can read more about them in #❓|how-to-get-help
i think FA -> PDA -> TM is a natural conceptual path that also provides some context to the surprising conclusion that there's nothing above Turing machines
regular expressions for tokens, PDA for an AST, and a turing machine for the actual evaluation is the flow the course we have takes
I suppose. In the course that I took, half the time was spent on FAs and PDAs, and by that point it wasn't clear to me what the point of it all was and where the course was going
Though lakmatiol's point about PDAs is news to me. So I guess this just speaks to the failure of that course.
that sounds like more of a curriculum/professor problem (my professor for this was great), although i think it's very easy to make very theoretical work seem unmotivated
to be fair, formal turing machines are mostly useless, you can just use a real programming language instead, whereas knowing FA/PDA is practically usable for parsing, since that's what most grammars describe
probably worth mentioning that i was a math student, so totally happy learning about something with no apparent use
quantum computing is far, far more complicated than anything that isn't complicated
the question of what can be done with quantum computers is complicated
I was thinking...
It's better to teach creating UI by Python UI Frameworks or teach basics of web dev and connecting to Python?
Hmm...
This second approach requires more knowledge
It does, though it's also more useful in the real world.
Please check the channel description before participating in a channel for the first time. Thanks!
My apologies 😦
Topic: What are ways to teach difficult concepts that are fun for students? What's an example of a difficult concept, and a fun lesson/example that teaches it?
bonus if you can think of an example that isn't some aspect of OOP.
rename channel to oop discussion when
I suppose that data design & ""advanced"" usage of dictionaries+lists / json through the usage of REST APIs? (specially more complex APIs, returning not just a single dictionary, but rather alternating between lists and dictionaries at least two times or so)
trying to wrap your head around heavily nested data structures is always a ~~not-so-~~good time for beginners
Heavily nested data srructures are also not fun for a pro
You're basically asking for the next todo-list, website or discord bot
Well, let's say it: android app
Mobile app with python
That's hard
It shouldn't be hard though
So that's where a good portion of the focus should go, imo
Also has nothing to do with OOP specifically, just incidentally
Writing a Discord bot might be a fun way to learn about asyncio.
eh... not really imo
the library just hides it all under the hood, you don't even have to start it yourself via asyncio.run() or alike - that's like saying that using Flask is a good way to learn about threading.
You only notice it when it makes a difference, but in that case it would be better to just ignore the discord part and focus on what is making a difference for you to need to use async stuff yourself
What would be a good project to learn asyncio then?
well... I learned about it scraping data from multiple URLs at the same time (with explicit permission from the website owner), in which I had to use aiohttp + asyncio.gather(), but that is a bit of an unusual project
I don't think starting asyncio is a very important aspect of asyncio, also.
Though I guess you don't generally need to use asyncio in a very complex way, unless your bot does asynchronous I/O in itself, like calling APIs or something.
Are questions about PEP8 welcome here?
Depends on the library. Yes discord.py fought a lot with asyncio, and there's like the ext.tasks subpackage but I think that overall it could be a great way to learn.
I am not sure what other practical application I might be looking for though
I find it a bit unlikely for anyone to use a library that is not a fork of discord.py, and implementing a library that interacts with the discord API yourself is not going to be fun - specially for someone starting out
idk about hikari or w.e. it's called though
edit; it looks like it hides asyncio stuff under the hood too
It's still a pretty good practice to learn about blocking the event loop, using await and async def as well as the occasional task you'll most likely run into.
Although I do somewhat agree with you, many libraries hide too much of the event loop.
I mean, yeah, on the rare occasions in which someone's using an actual database or try to use requests / aiohttp you'll learn about it, but a lot of the time you won't even learn it in any detail other than "blocking heartbeat = bad"
I'm repeatedly baffled by complete newbies who want to start learning python by building a discord bot
I have no idea where they got that idea, but at least it's a good drive to get into all sorts of programming concepts
Building a mobile app would be even more useful for most people.. something like a sports tracker
But I guess we 'oldbies' need to put a lot more effort into making that much more approachable
Probably the internet lol. Yeah I agree but I have tried android dev myself and I have been programming for years and yet find it tedious.
I don't want to believe it's the same mess as last time I tried, I'm hopeful there has been some developments to make it easier now
Building an app isn't easy either. The standard 'hello world' type of building a todo-list webapp is from what I know, not that simple too. I suppose it is a good tutorial though. I also do not recommend apps via Python, as my experience was with Kivy, but if you know of a good framework (I don't consider Kivy 'good'), please let me know too
Maybe something with qt?
But qt isn't exactly beginner friendly, from what I've seen
Dunno
Tkinter maybe I have used it myself but it is a bit tedious too. UI is a bit difficult for Python other languages have UI designers
Text user interfaces or TUI best bet for beginners
It may lack the polish of a GUI or a web app but you can do alot with a text only interface with file handling and even perhaps database access.
If text is fine then argparse probably works
I learned to program first with text interfaces and pixel based GUI in the late 80s and early 90s with GWBasic, QBasic, Pascal, C, C++. It was fun and quite approachable for beginners
Many a complicated sprite based games have been coded in basic
Some even use peek and poke to do memory location read and write and bload and bsave for loading and saving to whole chunks of memory locations
The computers back then were slow so it was necessary to resort to such tricks
Also did inline asm in C and Pascal lol
I think Pygane is a good entry for this generation or ursina
Game programming is inherently motivating especially for kids
me too
well, I actually used threading because async wasn’t super a thing then, but same idea, kinda
I was thinking along the lines of lesson plans for specific concepts, not projects. Though on that note, it's pretty well known within the staff that discord bots tend to be much more challenging than novices were prepared for.
A difficult example could be decorators and closures, and I suppose a fun way to teach it would just be that since it's a function that wraps another and gives more functionality and the like to the original function... students could use wrapping paper?
idk that was just the first thing to come to mind haha
hm for concurrency, since it's the illusion that multiple things are running at the same time when in reality it's one by one.. something interactive could be like giving say two cookies, and asking people to find the most efficient way to finish both
most people can't eat it at the exact same time, but one bite from each will be a lot more efficient than finishing one and starting the next one
And feel free to correct me if my idea of concurrency is wrong
Hmm, that's not quite how I would paint up event loops in Python.
Chewing and swallowing represents the I/O. This gets faster if multiple people are eating because when one is chewing the rest can take a bite.
Threads is if everybody gets 1 second to bite, chew, and swallow the cookie with a timer - passing the cookie around as necessary. When your 1 second stops you can't keep chewing or finish taking the bite. Although that's not really a perfect model
I wouldn't use that analogy. A person rather is like a core and the IO is more like trying to write an essay and working on maths homework
You can either focus on one task, finish and then finish the other
That wouldn't necessarily be I/O though
Hmm.. sure yeah
If you get another person to help with one task, you get multiprocessibg
But it also shows that you can't throw many more people at those tasks to speed them up and actually ar
are wasting time handing paper and pencil around
async in python would be like 'finish a sentence or calculation, then switch'
Instead of 'switch every 5 seconds, exactly'
I disagree, async is cooperative that's yielding when there's IO (when you need to wait). Switching each sentence is not equivalent to what async does.
I think you can say switching like that is cooperative because maths is waiting for the fullstop of the sentence, writing is waiting for some 'qed' etc
9 women, 1 baby in 1 month
But in an asyncio application, there are specific points at which a switch to another coroutine can occur (only places where there is an await or an async for or async with), as opposed to a multithreaded application, where a context switch to another thread can happen at absolutely any point, even in the middle of executing a single Python bytecode instruction
In that light, yes the end of a sentence is a nice place to cooperatively switch - but not how I think about async. In an async program you wouldn't yield at the end of a sentence because I don't see that as any form of waiting
Sure, the analogy isn't perfect.
https://fastapi.tiangolo.com/async/ this one is fun and good
FastAPI framework, high performance, easy to learn, fast to code, ready for production
i always like the analogy of making coffee and checking reddit, talking to coworkers, and washing your hands, all while the coffee is brewing
that's concurrency, even though you're not really "doing" two things at once
although washing hands + talking to coworkers can be parallelized, in that you can literally do both at once
but the others you can't really do simultaneously, you can just "schedule" them by switching among them
i guess you can check reddit and talk to your coworkers, but that's rude 🙂
or do some stuff like switching while in one task, so use reddit and then while using reddit talk to your coworkers via reddit, although if they know your reddit....
Huh?
"nine women can't have a baby in a month" is a humorous way to point out that tasks aren't infinitely parallelizable.
Oh, right
Now that makes sense. I was wondering what women and a baby have to do with passing papers and pencils and homework
you can get a baby a month after their jit warms up for about 9 months /s
Premature babies do happen so not exactly 9 months
In my opinion, f-strings are the only approach to string formatting that should be presented to beginners. I think this is a circumstance where presenting them with options is too confusing (why is there more than one way to do it? ||is this actually perl?||) for how early in ones education the question arises. What do you think?
(and not that anyone is going to argue in favor of it, but chained string concatenations with + are code gore. I saw someone yesterday whos instructor was making them do it like that and now I'm upset about it all over again.)
I generally think that it is better to present all reasonable options, but stick to using one - in part since they might encounter others later and be confused over it.
It's not like format() is much more complex, and they may have to resort to searching for format()'s mini-syntax when working with f-strings anyway
I would prefer teaching .format because
- It can do everything f-strings can ||(ok, except
=)|| - It builds on already existing concepts: strings and method calls. No new syntax needed
Maybe you could even teach how to built your own simplified version of format (not when teaching it, but some time in the future).
I see what you're saying about method calls being one of the basics that beginners are familiar with, though I try to avoid teaching simplifying things for beginners in ways that conflict with best practices.
string concatenation should be taught, but definitely shouldn't be used for formatting
% formatting and anything referencing it can burn for all I care for though
it's the only way you can do string formatting for bytes 😛
some people disagree that f-strings are best practice
sobolevn has something to say https://github.com/wemake-services/wemake-python-styleguide/issues/32#issuecomment-402088356.
I personally think that f-strings make it easy to put complex expressions inside of an f-string. And they can become gradually more complex over time.
I would be fine to sticking to f-strings in a team if there was a linter rule (enforced in CI) disallowing complex expressions inside of them.
"Complex expression" meaning that only these are allowed:
- name lookup (
f"Hello, {name}!"✅ ) - attribute lookup (
f"Hello, {user.name}!"✅), but not too deep (f"Hello, {session.user.address.street.name}"❌) - (maybe) index lookup with a constant (
f"Hello, {user['name']}!"❓), but I'm not sure, because this is putting a string inside of a string, and also forces to use a different quotation style
I think starting with concatenation is a must. It's a necessary evil even thought it will quickly be replaced with other formatting
It forces beginners to understand that different data types behave in different ways
I personally use format 90% of the time, but largely because I'm jumping between py 2.7 and later versions. That being said, I like the benefits that .format offers with argument unpacking, or repeating arguments (not that those are necessarily beginner friendly)
filepath = r'creatures\{0}\game_files\{0}_moveset'.format(asset_name) as a practical example
For a beginner trying things out without guidance i think string concatenation is easier to discover since less additional syntax is required. Eventually they should move to format or f-strings once they dig deeper or notice the messy nature of string concats
I learned Python on my own and that was the sequence
and one of the better ones
I think it's true in some aspects of programming as well.
for example, ten architects can't design a system in 1/10 the time that it would take one architect
some companies do not aclnowledge
even for multiple developers, there will be lots of churn, conflicts, stepping on each other's toes, and reverted code, if multiple developers (let alone 10) are trying to work on (or especially refactor) the same file.
that's been my experience, anyway.
I've also heard that if one developer can do a task in two days, then two developers can get it done in a week.
that's closer to the truth 😄
Too many cooks....
Actually yes
I have a date slot in string (12hrs) format eg - "2:45 PM" and a time period to when this slot ends say 15 (mins). So time slots starts at "2: 45 PM" and ends in 15 mins. I want to show the ending time in the same format as time string in 12hrs format.
Example - Slot: "2: 45 PM", ends: 15
endingSlot will be "3: 00 PM"
Idea
Either remove the
programming-from the channel name,
or
not only remove theprogramming-from the channel name but also rename it to something likeepistemologyor so and have the explanation in the sub-title.
currently when people enter the server, this is the top most channel that has the word programming ||(a word that most people will immediately recognize and focus on amidst the chili, kiwi, something-pep and the weird off-topic names)|| in it and also probably to a lesser impact a word that can be misunderstood as teaching happens here.
The word pedagogy is also cut-off to pedago on my desktop at least.
I think these two things ( more the programming-) funnel many people looking for help, immediately into this channel.
/Idea
cs-pedagogy?
I think "pedagogy" expresses the purpose of the channel very well, but "programming" in front of it does funnel in some people who don't read further
cs is a wider term than programming, but it's not as much of a buzzword, at least imo
People who will not read stuff will keep not reading stuff IMO.
We have had people asking tkinter questions in #internals-and-peps
But yeah, CS seems kinda better
We can't prevent it from happening, but we can potentially reduce the frequency of that happening, while also covering a slightly broader range of topics that may not involve programming directly, but are closely related to it
The only way to prevent it is to move this section of channels below all the other Python topic channels in the list. We've had this discussion many times in the career channel.
That will need some research, experimentation and data. Which might be more effort than just occasionally telling people (who don't bother reading the channel description) to move
Could stand to be a bit stricter than that, why would people care if there's no punishment, just people telling them to move
We could just move the channels way down in the list and cut out most of the noise. I don't think this discord has a very obvious "landing pad" for new users, especially since the method of asking for help is quite counterintuitive (although I understand it's necessary since the discord is so big).
What sort of punishment thou....i dont think any is practical some are probably in a hurry so they ask in any thread they see... maybe have a point system for members and rewards for accumulating points and deductions for asking in wrong channels or worse
China has one lol the social credit system
I think punishments are silly, and imagine having to get the mods' attention every time someone drops in here.
Warnings and auto cleanup of messages
If you move these channels down some other channel will take their place, there needs to be a stick along with the carrot, some sort of punishment for people agreeing to the rules without reading them and then ignoring them
They'll end up in #algos-and-data-structs , it already happens a bit. I mean there's no magic bullet that will stop people from posting off topic. Cleaning up messages requires a mod's intervention. This is what already happens when possible.
Maybe just have the rando-help messages deleted her, it would at least make it more readable.
We are already talking over each other and having five conversations at the same time because of the medium we are using ||(Fuck I hate discord, who thought this was superior vs an bulletin board with Threads and stuff? I think I am old...)|| more messages in between does not make it easier. A single help request will automatically lead to 1-3 go here for help-messages.
Finally I can move this to #community-meta if wanted and feel free to delete my messages or tell me to delete my messages, as I seem to not be able to chose the right channel either and kind of doing off-topic ,for this channel, here also 😄
Cleaning up messages doesnt need mod intervention, for example #black-formatter people have message management perms apparently and theyre not mods
And yea we should move this to meta
Why did this turn into a meta discussion about the channel name? That belongs in #community-meta. Please resume on topic discussion; do not even acknowledge this message.
How much of a language's standard library do you think should be taught to students, and how much of it should they be left to discover on their own?
(Assuming they have already picked up the core concepts of programming (control flow, loops, etc))
i dont know about "taught" but i would definitely appreciate being made aware of itertools, functools, collections and a few others back when i was learning
ie once you teach dicts, you could go over a couple common problems solved with dictionaries and how defaultdict or Counter fit in there
I think only the important libraries that are used a lot compared to others should be taught, like datetime for example
anecdote incoming
java was (is) the language my school taught me and the only thing we ever used from its stdlib was a Scanner class, and that was just for reading stdin
we weren't taught about any of the collections for example - i discovered that java has lists and sets and hashmaps and stuff like that only after i picked up python by myself and wondered if java had them too. because i didnt know about lists, i wrote quite a few programs where i would basically copy over the contents of an array to a new array larger/smaller by 1 every time something was inserted/deleted
i think i agree that you should at least be made aware that tools like these exist, even if you're not taught about them in detail
There are a few more I'd add to the 'things you should've heard of'-list
...that's the first time in a looong while I remembered you can use help() with no args, trying to find the list of all modules
random and math are the only ones that really make sense to actively teach imo, but mentioning functools/itertools/collections and telling them where to find the rest should be fine
Namedtuples, deque, heapq, functool decorators, itertools combinations, pprint, statistics
Those are very situational tools, but you should know you have them at your disposal
I'd leave deque and statistics out
and I do not even know what heapq is so probably that one too
see? 
are these queues significantly faster than just using lists?
Heapq and deque are very basic datastructures you can implement in other ways, but it's nice to have them
heapq has a pretty limited use imo, you should be made aware of it, but not actively taught; iter/functools, though, may need a deeper explanation, as they are immensely useful
[for beginners]
Yes, depending on the situation
Heapq is mostly used for priority queues
With efficient sorting in place (logN, iirc)
I do think that pprint and even repr are underused.
I think itertools is pretty important. A lot of stuff in there people will end up implementing by hand, inefficiently, if they don't know it exists.
yeah, there are some fairly useful things there with regards to combinatorics, though a lot of it should just be a for loop.
collections and itertools for sure. though now I'm debating in my mind if beginners should learn os.path or pathlib first.
I'd say pathlib, with a stray mention of os.path
it's logn to insert a new element
right, because it's sorting the heap in place, but O(1) to get the max/min out
It's the ds you want if you want exactly this behavior
it's log n to get the max/min out because it has to reorder after popping
You don't have to pop
it's a queue how are you gonna get the rest out then
If you just want to see the min/max at a given moment you can just look at the first cell
you don't need a heap for that
you can do that in constant space with a normal variable
The point here is that the ds is dynamic
So removal and addition is logn but it's always sorted when you need to read it
but if you only need to know what the max is, you don't need a heap
At any given moment, not just once
sure, each time you get a new element, update the max if you need to
if new > max: max = new
Not sure I understand. When you remove an element in this way you won't know what the previous max was
but you said you didn't need to remove anything
also, the Scanner class is the bane of my existence. It's like they couldn't have made file IO more frustrating.
collections.deque is interesting if you've learned all the "linear node" data structures (linked lists, stacks, queues, etc), because you realize that the reason the stdlib only has deque is that deque can fulfill the role of all of them.
is functools really that interesting
i've only need @nocturne jetty and partial
fuck
sorry Cache
functools.wraps is useful (if not essential) for decorators
hm true
fair enough, but I don't think that they'd see these data structures while learning Python usually?
||Apologizing is weakness.|| I like functools.reduce (and I wish map and filter were part of functools), but it's not something I'd cover until a course about programming paradigms.
I think there're a lot of useful things in the stdlib, but very little that is actually necessary when learning to program
inb4 taking what is "necessary to learn to program" to the absurd conclusion that we should all write in Brianfuck.
heh
but I agree in that the core skill of programming is formalizing your thoughts, and you can do that in any language, without necessarily using everything it makes available.
If you use everything it makes available... We all have that colleague
heapq is used for priority queues iirc so it's useful to teach when teachingabout algos
IMO "Priority queue" is a huge misnomer
it's not a queue in the colloquial sense, because it doesn't respect insertion order
That would largely depend on your definition of "queue", I guess. "Queue" tends to be used to refer to a FIFO queue specifically, but it makes sense to me to generalize it to "A container that is able to receive an arbitrary amount of arbitrary items and order them in a very specific way" (after all, IRL queues aren't always FIFO either, a fair amount of them have special rules in place that complicate the logic or even eradicate the FIFO element completely)
I will admit that I do not know the "official" (ig) definition of "queue", this is based exclusively on the experience I had learning programming
Treating a queue as "something that orders its contents" makes a priority queue the default, and a fifo/lifo queue a more narrow variation that uses the insertion time to prioritize values
tl;dr, my empirical understanding of "queue" in general (not only in regards to programming) is "something that defines consumption order for a bunch of items"; a traditional fifo queue is just a variation that prioritizes values based on their insertion time, and a traditional priority queue is one that orders based on values themselves
mathematically it makes sense to call stacks and queues two special cases of priority queue, but the way stacks and queues are usually taught is closely tied to their implementation, with a focus on which operations they support in constant time
for this it doesn't make sense to generalize them like that (nor does it make sense to call a priority queue a type of queue, although by then students probably aren't in too much danger of getting confused)
Is there a genuine use case for hashmaps in python? If so, what, and why?
Have you ever used a dictionary or a set?
Yes
Dictionaries are implemented as hash maps.
Ohh my bad, I thought there was a literal type called hashmap lol
By the way, this is a channel for discussing how to teach Python and programming in general. This is not a help channel. If you have a normal Python question, you should see #❓|how-to-get-help and claim a help channel.
Yeah, I know. I figured there could be an actual discussion around this but I'm kind of stupid, sryy
Do you all think it's okay to lie about something to avoid confusion? Like for example, in my Python class the teacher said "exceptions are keywords" because the class didn't know what classes were yet
I'm okay with lying about some stuff, but that seems a little too far
Yeah I agree, I was going to point it out but I didn't want to correct the teacher haha
I'd just say "This is actually a class, something we'll talk about later on. Don't worry about it, it'll all make sense later"
why not just say "it's a class like a list or whatever we've talked about before"
The order in which information is presented should strategically avoid "just accept this for now" situations. Though I'm not sure why the instructor had to lie. "Exceptions are objects".
How do you always avoid that? Many things are defined circularly in my experience, completely avoiding that seems difficult.
I don't know that you can always avoid it. Can you think of another example?
You don't need to have learned the class keyword to have learned about types. I think it's pretty easy to explain that a ValueError is a type, just like int or str is a type.
I'd much prefer half truths over lies. You might need to explain the exception hierarchy to someone who hasn't learned the concept of subclassing yet, but you can hand-wave it away by showing them the exception hierarchy from the docs - https://docs.python.org/3/library/exceptions.html?highlight=valueerror#exception-hierarchy - and saying that you can use the name of any of the types as a shorthand for the list of all the types under it on the tree
Uhh, most are related to classes that I can think of off the top of my head
well, what's the first one?
i always hated the "it'll make sense later" in school. i think it's less frustrating to get a tool or some directions at hand "if you want to dig deeper"
in this case maybe type() and a link to the docs about exception hierarchy
Oooh, from looking at another server I read someone claim that "Assembly is easier to wrap your head around". What do you guys think about teaching people assembly first to get into programming?
The argument would be that it's a natural next step from those code games were you have to say like "move forward", "rotate to the right", "move forward", "move forward".
The point isn't to learn full Assembly, but rather to get into writing imperative code for the computer.
It does everything you say, and nothing more or less.
Teaching simple math operations in Assembly as a first step, then once the class understands how to write instructions to the computer you can move on.
Another big argument for teaching Assembly is how simple the syntax is, there's nothing to it.
strongly against, the reason those code games work for beginners is that they're essentially a DSL for something they care about: making a little guy move around the screen
whereas assembly is a DSL for changing what number a register holds
define DSL?
I think making beginners do simple math operations with assembly is a way to make most of them quit before they can do something they care about
domain specific language
It's not meant to be a big chapter, but having a lesson or two just for understanding what instructions happen and get into the habit of writing imperative instructions
I think assembly is too far removed from anything a beginner would do for it to have any value for them, but I can appreciate wanting to have beginners start by writing very imperative code.
As a lesson in "the computer will run the instructions you give it and won't wonder why, or figure out what you meant if they're wrong".
It could help understand how a computer works tying into previous lessons about the different parts of the computer and how "it works in 0s and 1s"
This very much. I played around with Logo as a kid and that's exactly what it is, making a little guy move around the screen with simple instructions. It's very much not like assembly. I don't think assembly is useful until you start learning computer science at a serious level.
I get that Assembly itself will transfer to little knowledge about how modern programming works, so I agree with that
That would be the application, computer science courses.
I wasn't thinking like "Hello, welcome to Python Discord please write this 10-line Assembly"
😅
I'm someone with a strong math background who is motivated by puzzles and writing the code itself more than what it does, so I should be in the target audience for learning assembly, but even I found it incredibly boring
Yeah definitely depends on how you structure the lesson
I would oppose say a homework in Assembly, or deeper reading.
The vision I see is like an interactive lecture where the teacher is standing at the front and asking the class questions and going through it with them.
Like a more serious example of this:
https://youtu.be/cDA3_5982h8
Have you guys seen it before?
Exact Instructions Challenge PB&J edition
Another Challenge with Johnna and Evan: https://www.youtube.com/watch?v=sLaVM6af-RE&t=121s
We asked the kids to write instructions for a simple task but left out that we were going to be following their instructions EXACTLY as written. Great lesson for communication and a fun practice in patience!
Plea...
(edited to the real author's video for correct credits)
To learn assembly you need a strong knowledge of hardware, which you should develop by learning high level logic first
Why not have the class play one of those games, instead? It would achieve the same goal of illustrating deterministic composable instructions, without being so dreadfully dull as learning assembly
I was about to make the same point, one of my friends took an intro class at CMU and they did exactly that
I fail to see how you could possibly make assembly interesting to beginners. you can only do low level and only vaguely sensible IO operations. There are better tools for teaching imperative programming where you can see the effects beyond just "look at how registers change values".
Hmm, right, the point is more-so to illustrate that computers do indeed work like that and the game they played previously is realistic
So yes I think you should have students play those games as well
Not sure if it adds much
the problem here is just how complex a modern CPU is. Assembly doesnt actually get evaluated from top to bottom linearily, one instruction after another, you have pipelining, registry renaming, transpilation, ...
Another inspiration I had was this channel:
https://youtube.com/c/BenEater
Subscribe to see tutorial-style videos about electronics, computer architecture, networking, and various other technical subjects. If you want to see more on a particular subject, leave a comment and I'll try my best to add more.
If you'd like to support my work, please do!
https://www.patreon.com/beneater
https://paypal.me/beneater
https://cas...
Right, can't you just use the simple parts though? Like perhsps just use a much older version of assembly?
you could probably use some older CPU, IK 6502 assembly is fairly accessible, but why teach assembly if you cant even run it.
What may be more interesting in this regard is giving the student an FPGA and a xilinx ISE license and having them write their own instruction set that way. But that is quite difficult, though I know a few people who managed simple instruction sets after only a semester of VHDL
https://www.peterhigginson.co.uk/LMC/ if you know you know
I think England's CS exam boards could learn a lot from looking at this channel
didn't do this in A-levels but I did in GCSE
This looks like a nightmare. I say this because I'm supposed to take assembly for a CS transfer degree. But I guess after all the Calc and Physics it'll start to make sense.
I think the ARMLite version is much better (https://www.peterhigginson.co.uk/ARMlite/), has more registers than just "the almighty accumulator", including a status register. Also has a bunch more instructions. LMC is a bit oversimplified imo
sort of off topic though haha
Do you mean lcm? That's the assembly I learned
LMC stands for little man computer
Can anyone suggest me how to learn python by doing projects?
hi, this channel is about how to teach programming, #python-discussion is a better channel for your questions
!projects
Kindling Projects
The Kindling projects page on Ned Batchelder's website contains a list of projects and ideas programmers can tackle to build their skills and knowledge.
If you have any questions about that, #python-discussion or a help channel ( #❓|how-to-get-help ) is the place to go.
on the topic we had earlier about teaching parts that their overall concept hasn't been introduced yet,
would you all say it's fine to say teach about @classmethod and @staticmethod before people know the concept of decorators?
eg in my python class we started learning about OOP so we touched on classmethod and staticmethod but we hadn't learned about decorators yet
Yea we go quite fast tbh, went from the concept of classes to classmethods and staticmethods in <1 week
though we had an assignment to incorporate all three types of methods (methods, classmethods, staticmethods) in a plausible example which was hard for most people because staticmethods really don't have much use compared to classmethods
if it isn't fine, where would the line be drawn? like should descriptors be taught first before classmethods (and instance methods) because they both implement the descriptor protocol
giving a general gist of what decorators do (take in a class/function, sprinkle magic dust on it and return a function/class) might be a good idea
descriptors are probably overkill
agreed, all we were told in our class was just "this is a decorator, don't worry about it we'll come back to it later" 😵💫
though ngl, i wish once the class as a whole got to a more advanced point in OOP, so towards the end of an OOP unit, they'd teach about descriptors and how they play a role in instance methods, class methods, etc.
for the longest time I thought that instance methods were just black magic
in my class?
yeah
something along the lines of "this is just a function in the class's scope and isn't bound to a class or an instance"
agreed, i really can't think of many good uses of staticmethods off the top of my head
at least classmethods have uses, like an asynchronous constructor
in the past i thought staticmethods were useful grouping functions together instead of having everything global
then i tried to decorate them..
now i'm avoiding them like the plague
did you have to find the attribute that holds the function within the staticmethod to even attempt to decorate them
i'm guessing you had to make a whole class that implemented the descriptor protocol + whatever you wanted to add just to decorate it o_O
there's that pipe package on github i love to add pipes in python, right?
you can decorate any function with @pipes and you can do stuff i like foo >> map >> print etc
the way it works, it modifies the ast...
now try that with staticmethods
i nearly cried when i had to completely refactor everything
(and not just for this decorator)
though you could just use modules for this right?
This reminds me of another topic too; should Python classes teach OOP design?
tbh, i had trouble getting the order right with those decorators
because once you know what OOP is, the hard part is knowing how to use it properly
and not overuse it / underuse it
is it ```py
@decorator
@staticmethod
def foo():...
or is it
```py
@staticmethod
@decorator
def foo(): ...
so.. i wouldn't even try to teach that
yea it can get confusing, and the explanation from the surface on decorators can get confusing too
"a function that wraps another function and returns a function that replaces the original function"
"which can return another function if your function is a function in a function"
What is OOP? 🙂
ah wait, reading back i meant more along the lines of "OOP concepts"
We've been getting a lot of questions in #data-science-and-ml about jupyter notebooks vs pycharm, which are itself based on a misunderstanding about the relationship between the editor and the interpreter. How can we help beginners overcome this misunderstanding?
I would say skip @staticmethod, as it's generally just a source for headaches. But I think @classmethod is absolutely essential for OOP concepts, and doesn't really require you to know what decorators are. I have yet to actually write a decorator myself.
i think it's frequently a good idea to lie by omission
e.g. "What is a decorator?" should be answered with something along the lines of "It's a function that takes a function and returns a function."
The fact that decorators can be any callable shouldn't be brought up unless the asker already has experience with OOP and python's data model
or that it doesn't have to return a function
Tutorial often lump two things together: 1) higher order functions; 2) the decorator syntax (with @).
I think it's a big mistake. I've seen quite a few people here get confused as a result of this.
The first part of the tutorial (which should not mention the @ syntax at all) should teach higher-order functions and passing a function as an argument. Some good examples would be:
- event handlers, where you pass in a function as an event listener
- reimplementing
map,filter,sorted,min,max - finally, closures:
- start with something simple, like anadderfunction which is just+, but curried. This will teach about closures
- then move on to functions which take a function as an argument and return another function
Now that the person understands how higher-order functions work, @-syntax can be explained.
I agree.
are we speaking about some specific (kind of) tutorial, or just which order things should be taught?
I very much agree with that. The @ syntax is so much more complicated to grasp to start off.
Not because the syntax is bad, but simply because it gives the impression that the only way to use decorators is with the syntactic sugar.
That's a misconception I had for a long time.
Also, side note, but I really like tutorials that have you reimplement something that already exists (in e.g. the standard library) in order to comprehend what it actually is better, it's very helpful (once you know the basics of the language, of course).
I'm not sure that that's a lie as much as it is a loose usage of terminology. Methods are just functions that are namespaced in a class, but their type isn't a subclass of the function type.
I haven't seen much of that with Python (not that I've gone through a lot of tutorials for it), but I encountered that in an OCaml book and it made the "black magic" of things like map much less-magicky and more approachable.
A decorator isn't a function that accepts a function and returns a function, it's a callable that accepts a callable and can return anything.
You're not wrong 
i didnt mean to get to into the weeds on decorators specifically, i was just saying that there's a type of lie that you use to hide complexity that i think is good teaching practice
!otn a the weeds of decorators
:ok_hand: Added the-weeds-of-decorators to the names list.
!e ```py
@print
class HelloWorld: ...
@pure heron :white_check_mark: Your eval job has completed with return code 0.
<class '__main__.HelloWorld'>
!e
@print
@hex
@len
@dir
class HelloWorld: ...
@silent goblet :white_check_mark: Your eval job has completed with return code 0.
0x1a
This channel is for discussing how to teach programming. If you would like to talk about learning it, you can ask in #python-discussion.
the most practical thing i frequently reimplement is a timer decorator, which also could nicely fit in a tutorial
Lol same
there's one other very interesting aspect of higher-order functions that are often overlooked are closures
where you have a kind of initiation phase and a work phase
i've used that in https://github.com/amogorkon/fuzzylogic/blob/master/src/fuzzylogic/functions.py excessively to precalculate values
that way you factor out some heavy calculation you'd have to do every time, calculate it once for a set of parameters and have minimal repeated work later#
Good for optimization .. i precalc when I can
i think one of the most if not the most confusing aspect of stacking @decorators is the reversed order
everything in python is evaluated from top to bottom.. except..
that's also what i hate about the pipes package
this one https://pypi.org/project/pipe/
i don't like it because the order in which things are evaluated requires you to jump back and forth with your eyes
same with decorator syntax - you're reading from top to bottom, but to understand the order of evaluation, you need to first read to the bottom, then back up and then down again
well that applies to things like
f(
g(
h(x)
)
)
too
yeah
which is why i prefer https://github.com/robinhilliard/pipes ^^
with that you can do ```py
x
h
g
f
Hey
observation: i feel like i've sometimes seen beginners writing code like this py x = '5' # take input or whatever int(x) # convert it to an integer print(x + 1) # it's an integer now
aside from badly written type conversions this also happens with str.replace
any ideas on how to do a good job at explaining the difference between changing a value (like you would have to for that code to make sense), and constructing a new related value (what it's actually doing)?
both of them are technically the same
just that the latter is probably a subclass of the former
um, no they're not
if you construct a new value the original one is still there
if you mutate something the original is gone now
we have an article https://www.pythondiscord.com/pages/guides/python-guides/mutability/
but not sure how good of an explanation this is
it also just randomly introduces garbage collection for no reason...
just ignore it probably
oh wait do you mean they don't assign?
doing py x = '5' int(x) print(x + 1) doesn't work
!e py x = '5' int(x) print(x + 1)
@orchid thistle :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 3, in <module>
003 | TypeError: can only concatenate str (not "int") to str
yes that's basically "no assignment"
"if you don't assign like this: x = value, nothing will change for x."
i dont think that's enough, you have to introduce mutability/immutability
"how come list.append works without that then?"
yes, exactly
you need to make the distinction of operating on an object and building a new object, basically templating
i couldn't find the right word
operating on an object vs. from an object?
we had that mutability/immutability topic before
back then we had trouble finding a good example and struggled with tuples vs lists
maybe int(x) is a good one
I don't think it's accurate to say it's because of mutability. You have the sorted function which works on mutable objects, but the value needs to be assigned somewhere
It really is just knowing which functions work in-place and which don't
in-place can describe it all i think
#python-discussion message fun example that is related
yup, happened to me, too
always annoyed me
they could return the same object
then it would be possible to chain those calls
fair point
i still think itd be appropriate to introduce mutability right then
like, "if you know an object is immutable then its not possible for it to have in-place functions. if it's mutable, it may or may not be in-place"
yeah, me too. you don't even need to call it "mutable" but rather "works in place" or "changes the object" vs. "makes a new object based on the input"
Maybe the issue is how int() is taught (well, for this example). It's usually taught as "converting" something into an integer, almost like in lower languages where you "convert" something (although that's a different process).
If you instead say that int() will create an integer from the input (instead of converting the input to an integer) it'll probably be easier to understand that you need to assign int()'s return value.
yeah, we need to be careful about the phrasing. maybe we can even use the precise term "constructor" for int() etc. even though it looks like a function
that's where python's std type convention being lowercase is problematic
I try to remember to say "creates an integer" or "gets an integer from the string"
I don't know that being precise about "convert" vs "creates from" matters when discussing immutable types, though I can see it becoming necessary when you start switching between container types.
if you explain things like int using the terms that you would use when teaching the students def, you can lay the groundwork for that future lesson without them realizing it. "When you pass a string to int, it returns the integer corresponding to that string"
I absolutely agree with that. Python doesn't have "type conversion" or "type coercion", and I think it's harmful to explain it a a separate feature
just teach that int and str are normal functions, like abs or input or print
Yeah it's a bit shocking that you can pass extra arguments to int such as base
@sage jasper Yes
Imo yes
what's an accurate usage of the word "cast" in python?
typing.cast, although that's just a coincidence
Casting is an implicit operation in C
"casting" refers to reinterpreting a value of one type (like uint64_t) as another (like double), or asserting a more specific type (e.g. if you have a type Animal, you can "cast" it to Cat. If it is not actually a cat, well, it depends on what language and particular feature you use)
this term is sometimes incorrectly used to name callable such as int or str
yeah I've noticed that
it's probably just inherited down from teachers who used to teach other langs
I've also heard "casting" a lot when referring to SQL
also movies 🙂
though in SQL it's a legitimate function name, right? I think
yes, SQL has a cast() function.
I don't think I ever use the word "cast" when teaching Python. At least, not consciously 🙂
I try to go with something like "You're getting that error because you tried to do arithmetic on a string. You need an int instead, so you need to call the int function to get an int from your string."
this channel is about how to teach programming, and we don't allow offers for paid work on our server
Hey can someone pleasee help me with code for ascii art in python. It would be great help🙏
@weak mortar ^
unless their solution is so terrible as to be unworkable, I would help them get it over the finish line and then ask whether they would like to see "how I would do it", or "a better way to do it"
and then explain how that way works too of course
probably get more attendance if they change the date
boolean expressions is an interesting point
would you show truth tables etc. to a newbie?
its one of the first things we covered in our cs class
does it help or do you think it's confusing?
i think its quite helpful
having a condition like x != 1 or x != 2 is a pretty common mistake
I show people truth tables without explaining what truth tables are or calling them "truth tables". Just a slide that says something like:
a and b is True if both a as well as b are True.
If a is | When b is | a and b is
False | False | False
False | True | False
True | False | False
True | True | True
That is, I give a prose explanation of how the operator behaves, and then use the truth table to illustrate what the prose explanation is trying to say, without ever calling it a "truth table" or explaining how to read it
what is the difference between CAST() and CONVERT() in sql
the syntax is pretty weird:
CAST(expr AS type)
well not being an imperative language, I guess they (standards bodies) can structure SQL's syntax however they like. I'd hate to imagine how horrible it is to parse. especially a dialect that allows arbitrary statements, loops, etc. yikes.
Hey I am currently reading "Automate the boring stuff wit python" but I want to at some point learn how to do something with machine learning. What do you think a good next book to read would be?
you should ask in #data-science-and-ml , that topic is more appropriate there
@fair steppe This channel is for discussion about teaching programming, not learning it. If you need help, #python-discussion or a help channel (#❓|how-to-get-help) would be a better place. Additionally, copying your code into Discord is a lot more helpful than an image.
@buoyant tinsel will do thanks!
why not use truth tables at that point?
because it is seen as some kind of new, scary concept
For you, who already knows that
introducing a new distinct concept always comes with a cost
mmmh
okay, maybe the symbols for and/or/not are weird
but going from that table to
a | b | a and b
F | F | F
F | T | F
T | F | F
T | T | T
is not introducing anything new
It is a truth table, but the issue is people like to overcomplicate things in their heads. A good chunk of people would understand truth tables intuitively, but if you told them beforehand that it's a truth table (and, therefore, a new concept), they'd perceive them as a significantly more complex subject and get a mental block, because "cs/math/etc is hard, therefore this will also be hard"
Showing something first and only then mentioning that this was the entirety of the dreaded new concept is a really clever way of going around this issue that I myself have used quite a bunch in the past
You're basically saying "That wasn't so hard, now was it? And that's truth tables for ya"
makes sense
maybe just presenting it one line at a time would be enough to make it digestible
brilliant 
Exactly this, @oak breach - it is a truth table, but I don't call it one or introduce truth tables as a concept when teaching beginners because they understand what it's trying to illustrate without being told (and expected to remember) that that's called a "truth table"
do beginners even know the term "truth table" before learning about them?
"Let's make a table where we mark down what happens when A and B are true or false"
i think older or adult beginners would have heard of truth tables from high school math classes
that's like the p and q stuff right 😂
Yeah it's hard to have a discussion about pedagogy without first defining the audience.
It really depends on the audience, yeah. Some people are fine with new terms and concepts, and some it feels like actively refuse to understand anything once you make them aware that it's a new concept, labeling it as inaccessible and complicated, even if it's not
From personal experience, you could see understanding fade away from my groupmates' eyes the moment someone mentioned pointers in their explanation, though they were perfectly capable of figuring things out when analogies or even just different words for "pointer" were used
Understanding the audience you're talking to is probably the most important part of teaching in general, besides the actual curriculum ofc
i agree in general, just that i dont think "truth table" sounds like technical jargon or something
unlike, idk, "breadth first search on an unweighted directed graph"
IMO, the thing is not the way it sounds but rather the mere fact that it's a new concept in an unfamiliar field
This alone can be the reason for a mental block, because people anticipate complexity and difficulty from such things
i guess
Hii
Flipping this around on you: what do you see as the advantage of using the term "truth table" the first time you show students a truth table?
the more terms you're familiar with the easier it is to follow conversations
conversations outside class i mean, among more experienced friends, on the internet, etc
The more terms you have to remember, also. Beginners are already swamped by information, so I try pretty hard to target my teaching to just what's most relevant for them to be able to start writing useful programs and learning on their own
Knowing what and does is much more important than knowing that the table that explains what and does is called a truth table
i don't disagree, but i also think its important to know the names for concepts
I think it's a good visual aid to expand on learning, or clarifying confusion for individuals who might have a harder time understanding than others
eg how would you google it if you got stuck
Wouldn't you Google "python and operator" instead of "and truth table"?
i guess i dont understand the big deal about truth tables, to me this seems like one of the easiest, least-scary concepts out there
why is it so important to avoid "truth table"?
ive definitely googled for truth table generators to sanity check whether my condition is right
I think it's important to avoid introducing any unnecessary concepts. I think limiting the number of concepts that you teach makes it easier for students to learn. Teaching something that they don't need to know - even if it's just "by the way, this is called a truth table" - distracts them from the things they do need to know
hmm idk, if a CS student had a bug with some nested if-blocks or something and I told them to write out a truth table, i would expect them to know what I'm talking about
I'd probably start calling them "truth tables" at the point where multiple operations are involved, but I don't do it when teaching the basic boolean operators
then i am in agreement
that goes back to the "audience" part. I don't think any college CS student will have trouble with calling it a truth table
That's fair. I've also never tried teaching "computer science" to anyone, I've only taught "introduction to software development in Python"
My audience was people who want to try out coding and see what it's about and whether they want to learn more.
my teaching experience is zilch 🙃
I don't know about anyone else, but I didn't until last week. It's not something I've ever seen in a google search.
When I was learning about truth tables, they weren't really hard to grasp
I agree with farmart here because teaching the concept which seems hard but which is in actuality quite easy, then saying that concept was the one that seemed hard but was quite easy is a good way to go about it
@fallen heron hi, can u help me with a code?
@cinder marten
hey there
this channel is for talking about how to teach people programming
yes thats what
it's not for actually giving programming help
@violet nimbushello, please don't ping random people, if you want help, read #❓|how-to-get-help
ok
What this channel?
For the discussion on the methods and practices of teaching.
Ok I like it
i feel like sometimes beginners focus too much on strings and/or the various types of string representations of objects, and then end up asking "how do i extract this information from the repr of an object" when they have the object right there and the information they want is just an attribute
or more generally questions that are phrased in terms of representations
like "how do i remove b'' around something" or "[('96',)] how do i get rid of everything except 96"
i think that and the confusion between printing and returning are direct consequences of all beginner programs being a few lines followed by printing something
This channel is for discussing the teaching of Python and of programming in general. Not for requesting help :) see #❓|how-to-get-help for that
try #data-science-and-ml - since it's about speec recognition and AI (I assume)
I very much enjoyed truth tables. They really map well to logic gates and state machines
Hi highly experienced programmers, I was wondering how would you guys go about teaching the logical aspect of programming to someone
What do you mean by logical aspects?
Like logical operators, or in general
Maybe teach flowcharts if you mean programming logic first independent of implementation or UML
:incoming_envelope: :ok_hand: applied mute to @cloud compass until <t:1644912021:f> (9 minutes and 59 seconds) (reason: duplicates rule: sent 4 duplicated messages in 10s).
logical could also be algorithms
there are some nice games that teach algorithms playfully
truth tables.. i remember one exam with a task involving 3 variables combined with different operations.. wasn't the most fun task
i think the most interesting and practical in every day life aspect of truth tables is conclusion and negation of conclusion
but it's some way to get there
and if you really want to get out there to expand people's mind - non-binary or fuzzy logic 🙂
fuzzy logic really captured me when i first learned about it in CS
that's why i really wanted a nice fuzzy logic lib for python, took me years to finish it (mostly) now
I mean the general logic that any programmer should have
the thought process to solving problems
applies to anything in life really not just programming
I feel as a beginner this aspect of programming is never really touched in tutorials even thought it seems to be really important but then again I don't think its something that can just be learned maybe comes with experience
oh thats interesting
The scientific method can help....how to approach problems and frame them in a way in that is systematic and rigorous as well as allowing to frame an hypothesis using our intuition about a problem then systematically testing it and in the end establishing a binary either proven or disproven...think of a program as an hypothesis to a problem...
i feel like programming is closer to maths than science
specifically, like, logic-y stuff
to me it feels like the main logic problems i encounter are:
- failing to break down a task ("how do i read a list of integers from a file and print the sum of the maximum and the minimum")
- making up stuff that doesn't exist (returning a variable, calling
inputand then assuming the input has been stored ininput, etc.)
yeah
breaking down a task into smaller ones in a way that makes sense is also an issue for me
for me programming is way more liberating than maths
in maths you're trying to simplify and solve things, in programming you can just let the machine do stuff and you see what's happening
"maths" as in actual maths (the study of abstract objects) or the absolute mess that schools make of it?
i remember a while ago i had a practical problem and i tried to find a math formula. the simplest approach was to figure out a python program that produced numbers step by step, then i looked it up in the OEIS
if you enjoy (actual) math, it's nice if you have time and like to wrestle with the intellectual problem, but if you stumble over a problem in the wild (as in while tinkering with graphics in an app etc) it's just about getting a solution real quick and easy
Yes why I suggested the science analogy or model
It is empircal problem solving
And it starts with a problem and a hypothesis ...program that we need to test empirically leading to a binary pass or fail
i don't know.. i'm just more of an explorer type of guy. i prefer to experiment and see what's happening
Experimentation is part of Science
true
Then we have the rigor of the compiler
Like peer review - code review
Then publication - git
Then collaboration - OSS
actually, we programmers are further in that regard than scientists, according to some scientists ^^
Citing references - using code modules by others
Yes
Literature review - looking for modules to reference
can't recall where i read it but i've seen some scientists complaining how code reviews and using git, reporting and fixing issues is so engrained into software engineering culture compared to how papers need to be flawless and how publishing something not flawless is viewed as bad science instead embracing reporting and fixing issues
Lol i need to see that
Share it here could further the discussion but dont sweat it if you cant
sorry, i can't find it anymore. i think it was on my mobile (firefox clear without history) 😦
Yeah Science is supposedly self correcting like how we do code reviews, bug reporting and fixing...the issue is the stakes are higher for scientist reputation wise if they come up with a result that is disproven later.
But the true Scientist should welcome being disproven
As devs we are constantly disproven by unit tests, testers or compilers
It makes us humble
well, on freenode irc someone once complained about having been tasked by their boss to replicate some ML paper. the scientist had posted some of their code on github, but it wasn't reproducable, so the guy tried to get in touch with the scientist via github, and their reply was something like "meh, just try harder, i published this 3 years ago and moved on since"
i've been in similar situations, too, with unreproducable papers and no way or inclination to get support
Ah lol not helpful and probably not valid or useful
but the scientist could claim to have released a paper
we think of science as something ephemeral, transcending people and cultures, but we forget that scientists are just people too
yeah, like us devs.. who don't get paid for support and thenhalf the internet comes crashing down because one guy doesn't give a shit anymore
In science all it takes is a single valid and replicable experimental result to overthrow an established theory...why they keep testing relativity
while this all seems relatively offtopic in this channel, there is the question of what values and cultural approach we should be focusing on while teaching
Ah yeah sometimes that is bob the dev that left us with legacy code that we need to refactor or rewrite...or some open source java logging package with unknown vulnerabilities
Ok let us close this
no, you raised a good and important point
the values we focus on while teaching also determine how we teach
if we really want to take the scientific method as guide to our teaching, we need to include peer review etc
Love for the truth and honesty and humility is essential...also letting go of ego if you are faced with negative code or peer review... emotional maturity
It is from mistakes that we learn and grow
It is the same in science
could we take TDD as an approach to teaching?
even guido couldn't wrap his head around it when he first came across, according to some mailing posts
Lol first time i heard of that
really? that i can dig up again, i hope ^^
Ah not if you are too busy but ok if you can
It isnt too many times that Guido is befuddled
It shows he is human like us
ah, i found it 😄
@cosmic aspen
that's the discussion
Nice thanks
hello
hi
help me pls
this is a channel about how to teach programming. you can try to get help in #python-discussion or #❓|how-to-get-help
i find that a bit surprising, and frankly i think the language around "property-based testing" obscures what hypothesis does: it generates example data
but it turns out that generating example data is really useful for property-based testing
the idea of testing "invariant properties" i agree is subtle and imo is a completely different paradigm for thinking about software testing
but at the same time it's not actually that different in principle from what people do normally. the "paradigm shift" lies in the process of explicitly identifying and isolating testable invariant properties
basically it's a formalization of how most people probably intend to write tests subconsciously, but the formality leads to a totally different way of thinking about testing... not sure if that makes any sense
i think there is something pedagogical here... but i don't quite know what 😆
well, read the mailing posts 😉 it wasn't property-based testing in principle but how it works (heuristics etc) under the hood that befuddled him (and we arrived here because of my suggestion to make TDD part of the teaching/learning process)
Assign the result of input to a variable and use that
Also this isnt a help channel, just realised, see #❓|how-to-get-help and #python-discussion
Maybe it's an exmaple for bad teaching 🤣
'Input' is a function that 'returns' a value,
Where are you learning from?
Aha,
This iilustrates 2 concepts i always keep in mind:
- Many beginners lack fundamental understanding of the programming details -like here they need to understand
inputis a function. - As a guide/teacher we need to understand if a student lacks understanding or just made a mistake
well, there's another important point here - that python allows overwriting of functions without complaining
if you did input = input("foo")
and another point - that function names are variables like any other
which would be a good time to make sure they got the reserved keywords down
or should they just be left as a "learn at your own risk"
Every feature of the language is useful for something.
Asking whether something should be taught in a "Python class" without mentioning what sort of level or background is kinda hard to answer.
I just purged a bunch of off-topic comments. Please keep this channel on-topic. If someone goes off-topic, please do not follow that vein of conversation, even if well-intentioned. Well, maybe I misunderstood what the underlying goal of the messages were. I'll reintroduce the topic later with credit/apologies to the OP.
message before this got deleted (unintentional behavior with the purge command):
"Should metaclasses be taught in a Python class?"
maybe in an advanced python course? but I'm not sure if one needs python courses that go that deep into the language. by the time you're in a position to understand what metaclasses do, you probably have the know-how to learn the rest of the Python spec on your own.
but that would be in a course about advanced Python usage, which I think are rare. Courses that are specifically about Python are usually (a) introduction to programming courses and (b) taught by a Java developer who doesn't know/secretly hates Python.
learn at your own risk? 
Like the joke about being able to shoot your own foot in a progranming language... more power more risk...look at C
Lol it appears Python isnt mentioned in the page above but Perl is...it is old but still a fun read
Java : You locate the Gun class, but discover that the Bullet class is abstract, so you extend it and write the missing part of the implementation. Then you implement the ShootAble interface for your foot, and recompile the Foot class. The interface lets the bullet call the doDamage method on the Foot , so the Foot can damage itself in the most effective way. Now you run the program, and call the doShoot method on the instance of the Gun class. First the Gun creates an instance of Bullet , which calls the doFire method on the Gun . The Gun calls the hit(Bullet) method on the Foot , and the instance of Bullet is passed to the Foot . But this causes an IllegalHitByBullet exception to be thrown, and you die.
For the java prof that secretly hates Python lol
!otn a IllegalHitByBulletException
:ok_hand: Added 𝖨llegal𝖧it𝖡y𝖡ullet𝖤xception to the names list.
Is it fair to say that the goal of OOP was to more intuitively manage state, and that caricatures of OOP weirdness are based on OOP use cases that create more state than is necessary?
I think if you are learning OOP, then abstract classes and interfaces are pretty important. Since Python enforces the abstract class concept via metaclasses, you need the vaguest understanding of what a metaclass is. But admittedly not that much.
I would say the main goal of OOP is separation of concerns and manipulating dependency structures to achieve that. Giving a class sole responsibility of its internal state is a means to an end. The goal is to break complex systems down into understandable parts.
you can also have separation of concerns and management of complexity with effective function-making (purpose of each function is intuitive, the right amount of complexity is abstracted away to make things easy to follow, etc), at least until you can't get away from having state.
Of course you can. I think it's best not to be married to one programming paradigm. Use OOP, procedural, or functional wherever they make the most sense.
(And yeah, I've implemented stateful algorithms in functional languages and it's a pain and confusing to follow. But functional languages are very elegant for expressing other things.)
Hey, don't know if it's the right discussion channel, but I want to ask you a question about learning python. At what point you've had your break point, where starting from it, you started to understand more easily everyother thing, that you've been learning about python and you could implement your knowledge more easily or started to create some kind of simple projects of your own? Thank you for your answers.
i don't think that there is really a step. In my opinion and experience of learning (and i'm a kind of learning addict), the curve is quite smooth
The thing that you may do is learning other languages, especially languages that are known to change the way you see programming (in my opinion, they are the only ones worth to learn). A language that i really love is APL, and it really changes the way you see programming. Another language that, i think, is really important to learn is LISP (and it can actually be useful for some projects, while APL is not).
Finally, you don't really see the big steps you passed at the moment you pass them. In my experience, i really realize that i passed a step like a month after or so.
But really, keep in mind that this is my personal experience, so it has the value of a personal experience.
thank you for your answers. I'm only learning Python for a few weeks, but as I'm learning, I still don't see what I can create by the knowledge I have right now. Still trying to find the break point, to have more passion, to pursue the learning and keep going with python. Maybe, after certain amount of time, I should try other coding languages, just to see what goes with me. Anyway, your answers are very appreciated!
I wouldn't say there's a specific point, but definitely after a couple of months you'll be learning less stuff and a lot more comfortable
However Python is such a broad ecosystem with lots of applications and use cases as soon as you switch domains it can almost feel like you're a beginner again
E.g. I spend most of my time on APIs at work and have almost 2 years experience with Python, but when I dabble in other stuff like ML at the weekend it feels almost like a different language
Also some packages definitely still seem like black magic to me when I browse the source code, e.g. Pydantic
sometimes i find it easier to learn when i’m trying to do a project as compared to just learning “by the book” (or tutorial etc etc).
what i’ll do is have a project i want to do, and just start doing it. one example:
i wanted to make a reddit scraper bot that i could say a subreddit, it scrapes titles and stores to a text file.
well what do you need for that?
- you need something to connect to reddit (an API call)
- you need something to process the text (text handling)
- you need something to tell you what the text is / output it to a file / tell the bot where to scrape (file handling / console input and output)
it can seem like a lot to look at it all at once, but then you can dive into the little pieces. start with the easiest one to you. for me, that’s usually reading and writing from a text file. so i’ll hardcode a sample string into the program and find a way to save that string to a text file. it might take me a day or a week to figure out but once i can figure it out once, i can use it forever
then maybe you look at connecting to an API.
my best tip for learning things in the beginning is to go to Google or Youtube and find a video tutorial walking you through. it’ll help you a lot to hear people talking about coding. as you start to understand things more you can add stackOverflow / other text based coding forums into the search.
there are so many great resources explaining how to connect a bot with PRAW (reddit API) , and you only need to consume videos until you get something that works.
remember, you’re doing this to learn, NOT to be the best programmer ever. if your code is ugly, at least you have code. make it prettier / faster / more efficient on the next build, and over time you’ll improve. ducttape code is fine, you can always improve it with a rewrite when you have hindsight to help
anyways, once you get the API setup and have reading and writing to files working, all you have to do is call the right functions with the API to get the data what you want. Youtube videos are your best friend
You can figure out the commands that get titles, comments, etc and then store it in some kind of data structure. you can use a dictionary or a list or whatever you’re comfortable with. remember, duct tape is fine! you’ll learn more stuff that you can put together later.
After you do the scrape (and store it to the data structure), you can loop through and save it to your file with a loop.
at this point you have a basic Reddit scrape bot set up that may or may not work correctly (duct tape is fine when you’re learning but it can leave you with… quirks once you put a few duct tape pieces together), and you’ve just learned a ton of things that you can now take with you to your next project
tldr
i think the thing that helped me the most was just doing projects and learning how different “pieces” of python work. then play around with the different pieces and just make whatever you think is cool. you’ll learn so much more doing projects you find interesting
Thank you everybody for your inputs. With it, I can build up different perspectives of learning and will definetly try it out. It's great to be apart of a helpful community.
learn-by-doing is often the most effective way. when you encounter an issue organically and arrive at the solution with minimal guidance, it's going to stick a lot better than if you had read or been lectured to about the relevant concepts.
that's one of the nice things about programming. anyone with a computer can practice as much as they'd like.
well that's kind of a different thing... i wouldn't be surprised if the internals & the "shrinkage" algorithm were complicated. imo it's disingenuous to claim that guido "couldn't wrap his head around it" imo.
but yes, i think the pedagogical conclusion is: we should teach testing early (maybe not specifically strict TDD), and the language around testing should be the language of "invariants" and "properties", not ad-hoc "making sure it works"
this happens at many points in the learning process. exactly "where and when" i think will be different for each student
understanding lexical scope and how name binding works i think is a big one for a lot of people though
another one is understanding that "everything is bytes" and that data types are just a matter of interpretation
Topic: how can one effectively teach the difference between an object and variables that refer to it? I've encountered people who mistake multiple variables pointing to the same object as being "shallow copies", when that's not quite it. I think there's also some debate about whether or not "variable" should even be part of the vocabulary when talking about Python, and using the term "name" instead.
show them the talk by Ned on the topic.
show me the talk by Ned on the topic.
"Speaker: Ned Batchelder
The behavior of names and values in Python can be confusing. Like many parts of Python, it has an underlying simplicity that can be hard to discern, especially if you are used to other programming languages. Here I'll explain how it all works, and present some facts and myths along the way. Call-by-reference? Call-by-v...
Variable should not be used in python imo. It's all binding names to objects
I'm inclined to agree, but I think "variable" is so widely used in programmer parlance that we can't get away from it. (and I say this as a list vs array crusader.)
I had never heard of the term "shallow copy" until a university course in Python (back when Python 2 was new, lol). And as you say, the term isn't even correct. We should be talking about "names" or "symbols" and "binding". Probably with some diagrams with little arrows. People who learned lower level languages will recognize them as pointers.
Well list and array and very different imo
But I learned C first where arrays are predefined in size and type or at the very least type
Python list is not a list structure, but "array" is not quite accurate either. (But no worries, a C++ "vector" is certainly not a vector either! We seem to be lacking in good language to describe compound data structures).
Python list is not a list structure
wdym?
It's not a linked list. It's an array of pointers.
i dont think "list" = "linked list"
i always try to avoid saying "variable" precisely because I think it's confusing, and it makes it very hard to make the object/name distinction
I mean, we are talking pedagogy here. It is helpful not to use too similar words for very different concepts. I think Python's choice of "list" is quite unfortunate. But I'm not quite sure of a good substitute.
do you think its worth mentioning that other languages don't always work the same way when it comes to assignments and names and references
only if they have experience with other languages
hmm
i remember being a beginner and it wasnt even clear how references, assignments, etc could work differently in different languages
i think its better to understand one language first
In general talking about the many things a new concept is not, is a terrible idea.
and scopes
@kind nebulahello, read #❓|how-to-get-help , this is not the channel for python help
I use the word variable when teaching Python. Not all names are variables, so using "name" is less precise and doesn't help learners to better understand the names/values distinction. I know Ned uses the word "variable" when teaching as well.
e.g. given py x = 420 y = [x] there are at least 2 names for 420 - x and y[0]
One of those names (x) is a variable, the other (y[0]) is not (though y is)
inb4 nedbat's name youtube talk
No, you're not 😉
I'd say a name is any reference to an object (some of which aren't even accessible or visible from Python), whereas a variable is a name that exists in the global or local or non-local scope
a = 5 makes the variable a refer to the value 5.
a.b = 5 makes the attribute b of the object referred to by variable a refer to the value 5.
Both a and a.b are names, but a.b is not a variable.
What other way around? You would have said a.b is a variable, but a is not, though both are names?
That both are variables, but a.b is not a name
But i can be convinced otherwise
In this ast for a = 4 and a.b = 4, only 'a' is referred to as a name in both cases https://paste.pythondiscord.com/ifemivarah.txt?noredirect
The language reference talks about "global variables", "local variables", and "free variables".
a = Foo() # a is a name for an instance of Foo
c = [a] # c[0] is now a reference to the same instance of Foo, but not a name for it
a.b = 5 # 5 is now an attribute of the Foo instance, with b as the attribute name
this is just my usage
I'm not sure how to effectively distinguish between whatever you call the thing after the . and the object being referred to.
I'd use "name" and "reference" interchangeably.
I think most languages with support for OOP require you to specify a specific set of attributes/instance variables than an instance of a class can have. Python does not.
"fields" too
static languages certainly do
to me, "instance variable" suggests that other instances are guaranteed to have an analogous value. but that's not true.
I don't remember if PHP does 🤔
also smalltalk?
> internet perl
is that what python is?
yep
ah
Regardless, I think "don't say variable" is silly, especially given that the docs use the word "variable" all over the place. I don't think avoiding the word "variable" helps beginners understand the concept of multiple references to a single value at all, and that's what proponents of "don't say variable" seem to think it would help with
I think "name" is a more accessible word for "reference", so that you can say that y[0] is "another name for" some object, instead of "a reference to" some object.
I don't police the language of people who already know what they're talking about (or anyone really); I use "name" instead of "variable" with beginners because "name" carries with it helpful preconceptions about how names work whereas "variable" carries with it unhelpful preconceptions about how variables work. So it helps beginners develop an intuition about how they work without forcing them to stop and think about it explicitly.
I don't really care about attributes or other references because that can come later.
I also don't really care what the docs say because the beginners aren't reading the docs, and I'm far from convinced that they're pedagogically optimal.
That's an interesting point that I don't think I've heard anyone articulate in the scope of the names vs variables discussion before: that variables in a programming language behave very differently from variables within a math equation
lol there's a very long conversation between Ned and I about it somewhere around here
"variables are names or labels attached to pieces of data" is always how i say it
good to introduce the "binding" jargon too
"data D is bound to name N in scope S"
I started with a language that uses let and const for variables (JS), and that kind of thing is how I think about it. A name is any identifier, whereas a variable is something that would be let or const. (of course, I could explain the specific rules, and I wouldn't ever teach variables in Python and explain it like that, but I think that suffices for the purposes of this conversation)
isn't a constant necessarily not a variable?
my intro to java course was emphatic about constants not being variables, but didn't offer a term that refers to either.
I've always thought of the name "variable" as decoupled from whether the value can vary (sorry "variable," but I don't care what you mean), but maybe that's not true.
well, "able to vary" is what variable literally means, at least following a strict interpretation of its component morphemes.
I understand that's what the word means, but for one reason or another I've never thought of it like that in programming. (not saying you're wrong, that's just how I think of it)
I suppose the term "immutable variables" is paradoxical then.
yeah, i kinda agree with dawn here. even if they're constants i still call them variables 🥴
I generally do as well.
every day, the programmer technolect strays further from god's light.
saying constant vs variable is too much effort
I'll specifically say "constant" if the distinction is relevant, but it rarely is - const-ness is just an extra piece of information attached to the variable (that it can't be reassigned), and that piece of metadata is usually irrelevant to whatever I want to say about the variable
If only we could go back and make programmer terminology and math terminology non-overlapping.
note that when solving a math equation, a variable doesn't vary
that perception is also the result of a loose application of terminology. a letter representing a number, where the number doesn't change, is a "parameter".
so if you have y = mx + b, y and x are variables, and m and b are parameters.
which then doesn't line up with how "parameter" is used in programming.
The x in 2x + 5 = 3x - 1 is the same value as the x in 2x + 6 = 3x and the same value as the x in 6 = x
sure, but are any of these statements intended to represent all possible (x, y) values for a certain line?
(is what I meant by "when solving a math equation, a variable doesn't vary")
nope - I was explaining my previous statement, not addressing yours.
> not addressing my statement

I lack the math expertise to have any opinion on your comment 🙂
none of those x's have a value
||this is sort of relevant to my earlier point, i swear||
all of those x's have the value 6, that's why the equality holds
whether or not the equation holds is an open question in some contexts
on its own the equation is merely a theorem
from that equation you can apply formal rules to obtain a different statement: x = 6
but my point is that the "variable" in all of these is static in a way that variables in programming are not
it's just a part of a timeless statement, whereas programming variables are references to data
(in most programming languages)
but also in a way that's different from static variables in languages that have those 😁
lol yes the incestuous terminology is inescapable
!otn a incestuous terminology is inescapable
:ok_hand: Added incestuous-terminology-is-inescapable to the names list.
describing formal systems using a language that humans speak is very difficult
at least, if you don't want to sound like a lawyer every time you open your mouth 🙂
or worse, a logician
or just..yknow..a nerd
i should probably mention that there are other philosophical theories of mathematics, but in a rare moment for me, this one is probably the closest to how mathematicians actually do math
which is relevant because on some level that isn't necessarily conscious, this is how math-literate students think about variables when doing math
TIL I'm not math-literate 
lol im guessing the way you actually do math would align with it though
we were taught they're called symbolic constants
Amateurs, non-changeables
@arctic marlin @median yew @still brook @candid jay this channel is for discussion about teaching programming, but you can grab a help channel in #❓|how-to-get-help
What are good lesson plans/project to tech others
depends on the subject
What is this about?
Please share a channel link for Django projects and for Q&A
is it just me or do people sometimes ask questions that are weirdly focused on specific features of python
"how do i do X using an if statement"
a huge part of that might be due to the way universities teach Python
^ they might be limited to a certain feature in order to learn how to use it
yep, sounds like a "you must now learn if statements!!!!" assignment. which is fine for beginners, I guess, but it's important that people eventually focus on the solution rather than the approach.
In making lesson plans you start with the learning objective.... write the material to address that objective...write the mechanism to check if that learning objective is met...eg the rubrik...test, quiz, project, recitation, reports...define how to measure outcome...then actually teach the class...that may lead actually to the feature list approach since it is easy to evaluate mastery of a topic in isolation before moving on to the next then hopefully synthesizing it all with a capstone project.
in another topic:
How do you generally teach Threading / Concurrency?
Most of the time I just recommend reading Real Python's An Intro to Threading in Python, specially if they don't know what threading is at all, but idk if that's a bit too "rftm"
teaching multithreading is hard in python because you can't do "real" multithreading in python
Doesn't that make it easier?
in the long run, not exactly
There's less race conditions someone has to understand
because if they try to apply what they learned in python multithreading to other languages, they would have to reteach themselves multithreading
I mean, in other languages you need to teach someone that i++ can work incorrectly
Ah, I am approaching this from someone not knowing threading or any form of programming other than what they've lesrtn so far
from my experience, the easiest way to help beginners learn multithreading is to apply it to a business application
which would be by using a progress bar as one thread and a time-consuming process as the other thread
Even then, isn't easier? Python's threading is just normal threading but safer. You just have to tell someone that "Hey, in other languages this simple operation can fail but Python has locking so this is safe".
true
The one thing I've actually seen people have a lot of issues is what is blocking event loops and how it works
Threading is usually pretty intuitive for someone once they understand that multiple things can happen at once.
that doesn't really make any sense. even if you don't have parallelism, you still have locks, mutexes, etc to learn in python
the GIL only helps reference counting, everything not threadsafe is still not threadsafe, e.g. changing global state
hey, this channel is for how to teach, instead of actually teaching/helping. see #❓|how-to-get-help or #python-discussion
in Python, += can do the wrong thing.
it's not really any different.
there are some things that can't be interrupted in CPython, but as a general rule it's not documented which things can't be interrupted, and anyway it's an implementation detail that can change between versions - so, you're forced to code as though anything can be interrupted.
I don't see the connection between iadd and anything being interruptable
+= can be interrupted - it's possible for two threads A and B that are both executing i += 1 to do
A loads the current value of i
B loads the current value of i
A adds 1 to the value it loaded
B adds 1 to the value it loaded
A stores the value it just computed to i
B stores the value it just computed to i
with the result that i was only incremented by 1 instead of 2 after both threads finished
perhaps I misunderstand what is meant by interrupted in this context.
that a context switch can occur in the middle of the operation
idk what a context switch is
a running thread can be deactivated (by the kernel) to allow other threads to make progress. It's possible for a thread that's running i += 1 to get deactivated in between loading the current value of i and before storing the value 1 greater than that back into i. If it does, then another thread can become active and modify i while the first thread is paused - and if it does, the first thread will store the wrong thing when it's resumed.
that's terrible!
enter async 👀
async basically fixes the problem of not knowing when a context switch happens, because you control it with the await keyword
I hate waiting.
in practice, it's not really much of a problem that context switches can occur at any time. When you manipulate shared state, you need locks, or you need to use thread-safe objects (like queue.Queue) to synchronize multiple threads
and in that sense (circling back to the channel topic) teaching multithreading in Python is no different than teaching multithreading in any other language - you need to explain what a race condition is, you need to explain things like the dining philosopher's problem to illustrate deadlocks and livelocks, you need to teach mutexes and condition variables, and then you tell people that they should almost always just use queue.Queue as the only way two threads communicate with each other and everything will work out and they don't need to think about it very hard
and maybe threading.Event, though they need to think a little harder to use that one in a way that can't deadlock.
or, maybe a better way to say it - it's a huge problem that context switches can occur at any time, but it's essentially a solved problem. There are well known tools for synchronizing multiple threads with one another in a safe way, and as long as you use those tools, and use them correctly, much of that complexity is managed for you.
Just fyi you have to teach essentially this same thing in Python as well: https://verdagon.dev/blog/python-data-races
honestly I've found the Rust book to be a great introduction to concurrency, parallelism, threading, etc. and the practical challenges associated with writing parallel/concurrent code
!d threading.Lock
class threading.Lock```
The class implementing primitive lock objects. Once a thread has acquired a lock, subsequent attempts to acquire it block, until it is released; any thread may release it.
Note that `Lock` is actually a factory function which returns an instance of the most efficient version of the concrete Lock class that is supported by the platform.
is using a thread-safe data structure preferred over explicit locks ?
yes
Explicit locks are much more difficult to use correctly and safely than thread safe data structures. It's much easier to misuse a threading.Lock in a way that results in a deadlock or a race condition than to misuse a queue.Queue in such a way
I have yet to use py queue.Queue
not only is it way harder to screw up, it also looks way nicer than having with lock: everywhere
Welcome to #programming-concurrency
(for the record, I'm not too worried about straying off topic as long as it stays in an "advanced discussion"-like domain.)
a more nuanced answer, actually: I don't think the lesson is "prefer thread-safe data structures over explicit locks", so much as "prefer to use existing, well tested components as building blocks wherever possible". The authors of queue.Queue went to a lot of effort to figure out every possible edge case a queue can have and handle them. Likewise for something like concurrent.futures.ThreadPoolExecutor.
The reason you should use a thread-safe data structure wherever possible is the same reason that you shouldn't implement your own HTTP client using the raw socket API: someone else already did it, and they removed many bugs over many years, and the final product is almost certainly better than what you'd get if you wrote it yourself from scratch. If you try to do your own HTTP messaging, you'll likely have bugs that requests or httpx don't have. If you try to do your own message passing system to communicate between threads, you'll likely have bugs that queue doesn't have.
Now, the one way in which threading is somewhat unique is that it's really, really hard to get right, and the bugs can be really, really subtle - which is all the more reason why you should prefer to reuse existing and well debugged library components over attempting to use low level primitives yourself.
So didn't know where to put this but, I have been looking for some physical computing books, programming, networking, databases, etc. Just cause I prefer them over ebooks as I just can't seem to get grabbed by them. Does anyone where/what I should be looking for? UK Waterstones was a bit disappointing
Just for learning, reading and referencing for uni
prefer to use existing, well tested components as building blocks wherever possible
My latest discovery is how complicatedcontextlib.contextmanageractually is.
https://github.com/python/cpython/blob/main/Lib/contextlib.py#L141-L187
So many edge cases I would've never thought of. And even the CPython developers haven't thought of them at first - they were discovered after the first version ofcontextlib:
https://github.com/python/cpython/blob/f669436189dd44a841caa9ab1ad97a3f7662bf58/Lib/contextlib.py
this is an excellent book https://www.oreilly.com/library/view/designing-data-intensive-applications/9781491903063/
Never heard of them? Is that a US thing? Sorry should have said UK
Oh nvm they are UK
if you had to teach high schoolers programming, what topics would you try to cover? and which topics are "nice to get to if theres time"
depends on the time frame
and the audience - is it all the students? or just the ones who are interested in programming?
the latter
what about a year?
ideally, id like to incorporate a few small projects as i feel like thats where the magic happens but ofc you need to get to that point
An approach that was used by the course I took when I was a beginner worked well for me; they gave a bunch of practice tasks separated into groups, and one of the groups would involve tasks that build on top of each other and/or contribute to the same project from lesson to lesson
This way we got both immediate practice for newly covered topics and started making projects relatively soon
I'm showing (teaching?) someone interested in programming Python and I don't have much experience. I'm used to linux/macOS environment (I spend a lot of time in the terminal), but this person is used to windows. I don't have any experience developing on windows.
I've installed python for them on windows through the official website and I've recommended vscode + automate stuff with python for tutorial
the book I've recommended is using MU editor
there wasn't time to install it yet
should I install it when I have the chance and go with my recommendations, or is there a better way on windows?
@weak mortar one of the more difficult parts of learning programming as a Windows user is that most online resources show command line stuff with bash, whereas PowerShell is the most capable command line for Windows.
The Python that comes with Windows has a lot of permissions weirdness, so it's best to download and install one from the Python website.
I usually encourage beginners to use a simple text editor like notepad++ or sublime, and then move to an IDE once they have an understanding of virtual environments and how to install stuff.
The reason being that when IDE-natives come here asking for help with installing a dependency, it's often very difficult to help them.
they usually don't understand why a package that they've installed can't be imported (because the IDE is running the program with a different environment), or how to install something to the right environment, etc.
I recommended vscode (without plugins), because I know from my coworkers it's up to par. As for venvs and how to install stuff, I want for them to avoid this and focus on only learning programming. I thought that was the right call. Maybe I'm wrong?
I know installing stuff can be a pain and I don't want this person (complete beginner) to deal with this at the moment
depends on what your goals are, I guess. I work on the data science side of things, and you basically can't do any data science (even for purely educational purposes) without installing the libraries in Python's data science stack.
no, this is a complete beginner that wants to learn the basics of programming atm
thonny is good and recommended for beginners
it's a step up from idle but not so overwhelming and complicated as vs code
i'd definitely say that you're right to avoid messing with venvs at the beginning, but make sure you have them using --user for pip install at least
I've never heard about thonny before
as for pip install, that's forbidden for the moment :)
no need atm
is vs code considered complicate for complete beginners? I don't mean the IDE - https://visualstudio.microsoft.com/
from what I hear it's similar to sublime without plugins
yeah, i am talking about vs code the editor
it's "simple" until they need to actually configure something
then, like sublime, it's no longer simple
i guess you can start them on vs code too, but thonny might be simpler to work with (and has some good python-specific tools that you'd otherwise have to install as vs code plugins)
my personal bias is that we shouldn't encourage the vs code hegemony anyway, it's bad for the ecosystem and it's bad if people start to get the idea that "programming = vs code" (which of course is what microsoft wants)
I hear you
I understand, but my only goal here is to help someone learn programming and I don't think it's fair to this person for me to inject my opinion in this way at this moment in learning
aren't you necessarily injecting your opinion when you make decisions about what they should learn and in what order? I think that's just part of teaching.
I am, but my advice here would be - it's better to use y instead of x, because of greater good, but for now I'd use x because it would be easier on you
:)
I've never thought about this until I've read your comment. the above is my conclusion atm, but I will be thinking about this
well like i said, as an educator i would prefer to start a student on thonny
it's more of an IDE than an "editor", but it works without all the complexity of a full-size IDE like pycharm
so you get lots of nice graphical-based features
there's nothing wrong with vs code though so fair
I agree with your point about encouraging people to use vscode
my question now is which of the two: thonny or vscode is better for a beginner python programmer
you mention that thonny has more python specific features/tools than vscode without plugins
yeah, that's why my suggestion is thonny
my suggestion was vscode without plugins specifically
this person has no personal preferences yet, no favorite color scheme, etc. so give them a program that works and is featureful out of the box with no extra config
admittedly im not sure what is now a plugin vs built into vs code. so if it comes with a debugger etc in the standard package then the difference is smaller
ah one thonny deficiency: there's no "run current line" hotkey or button
I've recommended no plugins for vscode so it would be used as a normal editor. I wanted them to learn without the crutch of plugins
hm, so you want them to use the command line to run programs? are they going to be using the repl?
I was thinking I don't want them to use cmd, so it would be easier on them
ok
but I'm not sure what's the best way
thonny has a lot of cool stuff built in: an object inspector, a dedicated window to show the last stack trace, a file browser, an "outline" viewer with classes and functions, even advanced stuff like a syntax tree browser and a heap inspector
i'd say it's actually a good general-purpose python ide too
but maybe not as powerful as vs code, and not "extensible" with plugins
you said you're an educator? you teach python beginners?
no, sorry i didn't mean it like that
i meant "from the perspective of educating"
i have taught individuals programming but never professionally
ah, ok
if anything i think the lack of a "run current line/function" is a bit of a dealbreaker for a classroom setting
this is my second time and honestly, I'm having trouble putting myself in the shoes of complete beginner :)
it's probably a good habit to "run entire file", but it makes the process less interactive
my memory of being a beginner is that i mostly just did what i was told w/ respect to tools
and that i understood what basically nothing did
so it was important to have tools that made it easy to do the easy things, and kept complicated things out of the way until i learned about what they did
i learned python on idle