@nedbat@hachyderm.io
@nedbat@hachyderm.io avatar

nedbat

@nedbat@hachyderm.io

Python, software, coverage.py, typography, juggling, Boston, autism (dad). Laughing at the world doesn't mean I don't take it seriously. He/him.

This profile is from a federated server and may be incomplete. Browse more on the original instance.

nedbat, to random
@nedbat@hachyderm.io avatar

Tired of this: "learn C so you can understand how a computer really works."

So much of modern computers is not visible from C (pipelining, virtual memory, branch prediction, cache misses, etc).

I guess what they mean is, "you learn about pointers and consecutive memory locations"? How is that helpful for programming in other languages without pointers?

C teaches you an abstraction of computers based on the PDP-11. It's interesting, but it's not essential.

nedbat, to python
@nedbat@hachyderm.io avatar

Opinions? Should this produce a syntax warning?

if x == 2 or 3:

https://discuss.python.org/t/can-we-make-a-syntaxwarning-for-if-x-2-or-3/30263

nedbat, to random
@nedbat@hachyderm.io avatar

Python proposal (inspired by Lua!):

args = {'a':1, 0:98, 1:99, 'b':2}
f(**args)

is the same as:

f(98, 99, a=1, b=2)

I've long wished to have one thing that could serve as both *args and **kwargs. Int keys are already invalid, so nothing would break.

nedbat, to python
@nedbat@hachyderm.io avatar

Want to do something simple to help people start off right with ?
Make pull requests for docs to change
pip install whatever
to
python3 -m pip install whatever

nedbat, to random
@nedbat@hachyderm.io avatar

At work we're running a hackathon (three days, try out any idea you want), but we want to pull in non-engineers also. "Hackathon" sounds very engineer-y. What are some other possible names for the event that would attract a broad audience? The days don't have to be devoted to code, there are lots of ways to explore innovation. No idea is too weird...

nedbat, to random
@nedbat@hachyderm.io avatar

Coverage․py 7.4.0 can use Python 3.12's lightweight sys.monitoring module. Coverage measurement with much lower overhead! Try it, and let me know.

https://nedbatchelder.com/blog/202312/coveragepy_with_sysmonitoring.html

nedbat, to python
@nedbat@hachyderm.io avatar

If I could change one thing about education, it would be to change every example of for i in ... to something more meaningful (for number in ...) so that people would stop writing things like for i in employees:

nedbat, to random
@nedbat@hachyderm.io avatar

My test suite has just one dot on the last line. What would you do?

  • Delete one test
  • Change the width of the terminal
  • Keep it as a visceral reminder of the uncomfortably chaotic nature of the universe
  • Write more tests
nedbat, to random
@nedbat@hachyderm.io avatar

Is it bad that "nedbat" means scars in Arabic, overlook (verb) in Czech, don't care in Serbian, decline in Norwegian, reckless in Romanian and negligence in Ukranian?

OTOH, it's hard to argue with bearded (Catalan).

(according to Google Translate...)

nedbat, to random
@nedbat@hachyderm.io avatar

I was going to do a poll about whether common Latin abbreviations (e.g., i.e., etc.) are OK in technical docs.

But then i remembered I already have a strong opinion: you should avoid them. There are perfectly good English words to use (for example, that is, and so on).

(This was prompted by finding "cf." in the Pydantic docs, but not used correctly I think? https://scientistseessquirrel.wordpress.com/2016/06/13/friends-dont-let-friends-use-cf/)

nedbat, to security
@nedbat@hachyderm.io avatar

Why is everyone OK with credentials being stored in well-known files like ~/.netrc or ~/.config/hub ? Any code I run on my machine has access to them: convenient but also dangerous! Is there something I'm missing that's keeping malware from using or exfiltrating them?

nedbat, to python
@nedbat@hachyderm.io avatar

Quick #Python packaging tip: if you ever find yourself wanting to type import src.anything or from src import anything, turn back. src should never be part of an import.

nedbat, to python
@nedbat@hachyderm.io avatar

Advice for beginning ( and anything else) learners: https://nedbatchelder.com/blog/202309/advice_to_beginners.html

"Write code. Write more code. Get your hands in there, do things and find out what happens. You’ll learn best by doing."

nedbat, (edited ) to python
@nedbat@hachyderm.io avatar

When you read or write about 's init() method, which seems right to you:

nedbat, to python
@nedbat@hachyderm.io avatar

Remember that dicts can have tuples as keys! Consider a dict with (x,y) keys instead of nested lists for a grid. It simplifies sparse grids, "resizes" are automatic, it doesn't matter where (0,0) is, and you can use negative positions:

Adding more to the board in flexible ways. https://gist.github.com/nedbat/f22b03f70ceb9686881c4bcd442fad11

nedbat, to random
@nedbat@hachyderm.io avatar

@brettcannon At the SC panel, you asked people to make beta wheels, but cibuildwheel says not to? https://cibuildwheel.readthedocs.io/en/stable/options/#prerelease-pythons I guess I need a more nuanced reading of the advice...?

nedbat, to random
@nedbat@hachyderm.io avatar

"I think I'll go back to that work I was doing six months ago."

opens file

"I have no idea what any of this code does, or why the author would have written it like this..."

nedbat, to random
@nedbat@hachyderm.io avatar

A theory: if you are unfamiliar with a technology, all docs seem like bad docs. It's really hard to learn your way around new tech. The perfect explanation for your particular background, perspective, and needs will not exist.

nedbat, to python
@nedbat@hachyderm.io avatar

A common question: what's the difference between a script and a program?

  • A program is something you've put some thought into.
  • A script is something you didn't think you had to put any thought into.
nedbat, to python
@nedbat@hachyderm.io avatar

You can use Unicode characters in identifiers if they are classified as letter-like, but that doesn't mean that you should!

(Full rules at https://docs.python.org/3/reference/lexical_analysis.html#identifiers)

nedbat, to python
@nedbat@hachyderm.io avatar

A surprising way to get the item from a one-element dictionary:

nedbat, to random
@nedbat@hachyderm.io avatar
nedbat, to random
@nedbat@hachyderm.io avatar

A long expert piece by @glyph about why you shouldn't sign git commits (tl;dr: there's no public web of trust so we don't know what it means; meaningless badges distract from true security; extra complexity; compromised keys could leave permanent lies): https://blog.glyph.im/2024/01/unsigned-commits.html#fnref:2:unsigned-commits-2024-1

https://cloudisland.nz/@ehashman/111814514609384307 rebuts that git commits are really easy to spoof so signing proves it was you.

What to do?

nedbat, to random
@nedbat@hachyderm.io avatar
nedbat, to python
@nedbat@hachyderm.io avatar

Earlier I griped about black/ruff formatting similar #Python lines differently because of their varying line lengths. After looking at it more, I decided to reduce the duplication in the lines, which shortened them, making the meaning more visible:

  • All
  • Subscribed
  • Moderated
  • Favorites
  • JUstTest
  • kavyap
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • tacticalgear
  • cubers
  • Youngstown
  • mdbf
  • slotface
  • rosin
  • osvaldo12
  • ngwrru68w68
  • GTA5RPClips
  • provamag3
  • InstantRegret
  • everett
  • Durango
  • cisconetworking
  • khanakhh
  • ethstaker
  • tester
  • anitta
  • Leos
  • normalnudes
  • modclub
  • megavids
  • lostlight
  • All magazines