General statistics
List of Youtube channels
Youtube commenter search
Distinguished comments
About
Lawrence D’Oliveiro
ArjanCodes
comments
Comments by "Lawrence D’Oliveiro" (@lawrencedoliveiro9104) on "ArjanCodes" channel.
Previous
3
Next
...
All
1228
1
There is a common and very old way of doing asynchronous calls without special language syntax, and that is to use callbacks. The drawback with this is it breaks up the logic of your handler into multiple separate pieces, rather than being able to write it all in one block.
1
Python’s asyncio event loop supports both ways of working. It is instructive to compare the two. I did this with a “rocket launcher” example which you can find in the archives of our local Python user group here:
1
https://
1
git
1
hub.
1
com
1
/HamPUG/meetings
1
/tree/master
1
/2017/2017-05-08
1
/ldo-generators
1
-coroutines-asyncio
1
Here’s another tip: use a two-dimensional layout to make the structure of complex expressions clearer. Example: if ( not isinstance(cmds, (list, tuple)) or not all(isinstance(elt, (list, tuple)) and len(elt) == 2 for elt in cmds) or not all ( isinstance(elt[0], str) and elt[0] in valid_cmds and isinstance(elt[1], (list, tuple)) and len(elt[1]) == len(steps) for elt in cmds ) ) : raise TypeError("cmds must be sequence of («cmd», «args_seq»).") #end if
1
@christoferberruzchungata2722 It’s already in a function.
1
If you want to see that snippet in context, have a look here https://
1
/ldo/aleqsei , in the method Context.Rib.motion().
1
com
1
git
1
hub
1
By all means, show us the actual code you would write, and we can compare them.
1
So you didn’t actually understand what the code was doing before trying to “improve” it?
1
I find it’s an easy way to scare away the armchair programmers, by asking them to actually write some code.
1
I try to design my cleanup code to never throw an error. So for example if a connection was never opened, then the connection-closing logic should automatically become a noop in this case. That helps to keep things simple.
1
Just avoid wildcard imports, and you’ll be fine.
1
@TylerLarson I hope you’re not trying to offer up YouTube as an example of “perfect” code ...
1
@TylerLarson None of which is relevant to the point. And that is, providing a point you can search for, to find the origin of a name. A from-import statement works fine for that, so long as it’s not a wildcard import.
1
Impedance mismatch between static-oriented IDE and dynamic language. So sad.
1
12:20 By the way, forgetting the “await” in front of “asyncio.sleep()” is a mistake I have made a few times. How about you?
1
Microsoft Windows trouble?
1
If you avoid deploying mission-critical systems on Windows, that reduces your embarrassment exposure.
1
I have created worker threads to turn blocking calls into non-blocking.
1
3.7 is obsolete. Why do you feel the need to do the extra work?
1
How would you handle a level break? Here’s a fairly simple two-column example, which lists the moons for each planet on a separate line. The planet name only appears for the first moon, and the last one is followed by a count line for that planet. out⋅write("<TABLE>\n") out⋅write("<TR><TH>Planet</TH><TH>Moon</TH></TR>\n") items_iter = db_iter \ ( db, "select planets⋅name, moons⋅name" " from planets left join moons on planets⋅id = moons⋅parent" " order by planets⋅name, moons⋅name" ) cur_planet = None while True : item = next(items_iter, None) if item == None or cur_planet != None and item[0] != cur_planet : if cur_planet != None : out⋅write \ ( "<TR><TD><I>Count:</I></TD><TD>%d</TD></TR>\n" % count ) cur_planet = None ♯end if if item == None : break ♯end if out⋅write("<TR><TD>") if cur_planet == None : ♯ first moon for next planet cur_planet = item[0] count = 0 out⋅write("<B>" + html⋅escape(item[0]) + "</B>") else : ♯ second or subsequent moon, don’t repeat planet name out⋅write(" ") ♯end if out⋅write("</TD><TD>") if item[1] != None : ♯ there is a moon out⋅write(html⋅escape(item[1])) count += 1 else : ♯ that’s no moon out⋅write("<I>(none)</I>") ♯end if out⋅write("</TD></TR>\n") ♯end while out⋅write("</TABLE>\n")
1
No, because Rust is not a dynamic heap-based language, while Python is.
1
Notice that Python effectively already has generics, because function objects and class objects are constructed at runtime?
1
Text formats are the easiest to use for interchange purposes.
1
That’s quite a reasonable use. Do you introspect the procedure prototype to do typechecking against the arguments before actually invoking it?
1
@NathanHedglin So do I ... mainly in PHP code.
1
10:38 I like to use a name like “def_should_buy_avg”. The extra “def” on the front looks like the keyword for defining a function -- which is what the function does.
1
If those functions are only called from the “main” function, why not make them local to that “main” function?
1
Have difficulty navigating nested blocks? This is why I have editor commands defined to quickly jump between lines with matching indentation.
1
4:13 “await” is actually an expression, not (necessarily) a statement.
1
4:16 Fun fact: the awkward “PostgreSQL” name arises from the fact that the original Postgres DBMS had its own query language, called QUEL. This was in the early days of relational DBMSes, when SQL was still gathering momentum but hadn’t quite become totally dominant yet. So when they finally gave in and adopted SQL as a query language, they had to indicate this by grafting this new thing on the end of their name, with slightly unfortunate results.
1
PHP user?
1
@greggoog7559 What has changed in Python in the last “few weeks”? Hint: Python 3.11 was released nearly a year ago.
1
5:05 If it was a “%d” format specifier and you used printf-style formatting, then it cannot be substituted with anything other than a decimal integer. Problem solved.
1
The low-level mechanism of a coroutine object is that it executes when you call its “send” method. The coroutine blocks itself by calling a generator which does a “yield” back to the caller that did the “send”. On top of this, you can build an entire event-loop scheduling system. I drew up a diagram of how all this interconnects, that I call “Van Rossum’s Triangle”. If you search for “python topics notebooks ldo”, I cover this in one of those notebooks.
1
PHP user?
1
AbstractComponent provides an enforcement check that all abstract methods have been overridden before allowing instancing. Just typesafeness, that’s all.
1
@jeancerrien3016 So that he can predeclare exactly which abstract methods need overriding.
1
Previous
3
Next
...
All