Ned Batchelder

nedbatchelder.com · Personal blog · on HN since 2007

Ned Batchelder, a Python developer who created coverage.py and Cog, writes about Python, Unicode, and software practice.

What HN saysHN commenters link Cog for generating C++ code from Python, and his talk on Python names and values; one describes him as creator of coverage.py.
208HN people shared it
86linked it in comments
256stories submitted
5.5Kstory points
4 months agolast shared
2007people per year2026

Most-shared posts

  1. 1
    Pragmatic Unicode
    17 people · 58 points · first shared 2012 · 19 comments on HN
  2. 2
  3. 3
    Python Eval really is dangerous
    7 people · 10 points · first shared 2012 · 1 comments on HN
  4. 4
    Stopping spambots with hashes and honeypots (2007)
    7 people · 7 points · first shared 2007 · discussion on HN
  5. 5
    Running out of hex words?
    6 people · 40 points · first shared 2011 · 12 comments on HN
  6. 6
    Python Names and Values
    6 people · 14 points · first shared 2015 · 1 comments on HN
  7. 7
    Print this file, your printer will jam (2008)
    5 people · 769 points · first shared 2008 · 208 comments on HN
  8. 8
    Pickle’s Nine Flaws
    4 people · 72 points · first shared 2020 · 38 comments on HN
  9. 9
    Spore creature creator and steganography
    4 people · 4 points · first shared 2008 · 1 comments on HN
  10. 10
    Two problems
    4 people · 2 points · first shared 2012 · discussion on HN
  11. 11
    What’s in Which Python
    3 people · 214 points · first shared 2022 · 72 comments on HN
  12. 12
  13. 13
    Facts and myths about Python names and values
    3 people · 68 points · first shared 2013 · 18 comments on HN
  14. 14
    Alan Kay’s Objects and Arts
    3 people · 6 points · first shared 2023 · discussion on HN
  15. 15
    Toxic Experts
    3 people · 6 points · first shared 2017 · 1 comments on HN

What HN people wrote when they linked it

malhaar · 2017-01-30
Ned Batchelder. Blog - http://nedbatchelder.com/ Stack Overflow answers - http://stackoverflow.com/users/14343/ned-batchelder Coverage.py - https://github.com/nedbat/coveragepy Twitter - https://twitter.com/nedbat Ned created coverage.py and is one of the most famous Python devs. He explains Python concepts in a very lucid, easy-to-understand way. Going through his stack overflow answers, his tallks in PyCon are worth doing it.
rogual · 2025-03-26
This is what I do, these days. Whenever I would previously have reached for X-macros or some other macro hack, I tend to use Cog [1] now instead. It's quite a clever design; you write Python to generate your C++ code and put it inside a comment. Then when you run the Cog tool on your source file, it writes the generated code directly into your C++ file right after your comment (and before a matching "end" comment). This is great because you don't need Cog itself to build your project, and your IDE still understands your C++ code. I've also got used to being able to see the results of my code generation, and going back to normal macros feels a bit like fiddling around in the dark now. [1] https://nedbatchelder.com/code/cog/
BiteCode_dev · 2024-08-23
Tangential, but if all you want is inline code generation from Python and not a full preprocessor, you can use the excellent cog from Ned Batchelder: http://nedbatchelder.com/code/cog#h_what_does_it_do
tech2 · 2023-09-02
Except that nothing is passed by reference (or everything is, depending on how you look at it). It's just that some objects have methods which can modify state (like list, dict) and others don't (like int, str). Ned Batchelder did a good presentation on this many years ago which is still probably the best I've seen for explaining how it works to people coming from other languages - https://nedbatchelder.com/text/names1/names1.html - where the names passed to a function act just like regular assignment.
PebblesRox · 2021-01-06
My kids aren't quite old enough, but I recently enjoyed the following stories: "Haaarg, world!" (writing a vampire-themed number-guessing game with a six-year-old): http://davidbau.com/archives/2005/07/29/haaarg_world.html Madlibs with a 13-Year-Old: https://nedbatchelder.com/text/madlibs.html
svat · 2019-06-17
Related reading (perhaps worth reading as a precursor to this), from Ned Batchelder: • Facts and myths about Python names and values https://nedbatchelder.com/text/names.html and its presentation version: • Python Names and Values https://nedbatchelder.com/text/names1.html
AlbertoGP · 2019-02-02
> I haven't read the Microsoft edition yet but I know Ted hates what they did with his book. Here is a review of the book that describes the problem: https://nedbatchelder.com/blog/200301/computer_libdream_machines.html > The 1987 revised edition is classic ‘80 laser-printer chaos, and is not nearly as nice to read: the dimensions have been scaled down resulting in text narrowly wrapped, and awkwardly flowed from page to page.
Permit · 2018-06-24
Absolutely, when I was searching I followed this guide to search for hex words: https://nedbatchelder.com/text/hexwords.html But there are definitely other 'interesting' numbers people could come up with.
manaskarekar · 2018-04-22
Here is, what I thought, is an excellent video and the related article for Python: Ned Batchelder - Facts and Myths about Python names and values - PyCon 2015: https://www.youtube.com/watch?v=_AEJHKGk9ns Article: https://nedbatchelder.com/text/names.html
ubernostrum · 2018-03-31
Since it just came up again yesterday, it's worth noting that the term "compiled language" is a tricky one to use here: https://nedbatchelder.com//blog/201803/is_python_interpreted_or_compil… So: is Python compiled? Yes. Is Python interpreted? Yes. Sorry, the world is complicated...
resc1440 · 2015-11-18
Mitsuhiko has written extensively about Py3 unicode problems, e.g. http://lucumr.pocoo.org/2014/5/12/everything-about-unicode/ I think a lot of it boils down to, sometimes you really really don't want to care about unicode. Linux filenames are one thorny issue - Linux thinks of them as strings of bytes, and a tool is broken if it can't also deal with them that way. Py3 makes it very difficult to do that correctly. There are also issues with stdin/out being opened as unicode vs byte streams. For web development, the "unicode sandwich" (http://nedbatchelder.com/text/unipain.html) works great in my experience. However, I can see his point that for some kinds of tasks, Py3 is unambiguously a downgrade.
ingve · 2013-07-06
If you work with other languages in addition to Python, it's easy to fall back into old habits. You should internalize the content from these two excellent presentations: Raymond Hettinger's "Transforming Code into Beautiful, Idiomatic Python": http://pyvideo.org/video/1780/transforming-code-into-beautiful-idiomat… (pyvideo.org has a lot of other great talks and presentations.) Ned Batchelder's "Loop Like A Native": http://nedbatchelder.com/text/iter.html Python Module of the Week is also an excellent resource: http://pymotw.com/2/
bockris · 2010-06-21
I'm late to the game but you should check out 'Cog' by Ned Batchelder. http://nedbatchelder.com/code/cog/ I used it several years ago with great success.
ganley · 2009-08-27
A few of my favorites that I didn't see people list; note that many of these are sort of combined personal blogs and programming-related (like mine - http://joeganley.com): - http://wilshipley.com - http://lbrandy.com - http://nedbatchelder.com - http://www.teamten.com/lawrence/writings/
stan_rogers · 2009-05-03
If money isn't particularly tight, or if the family already has a licensed copy, Flash and ActionScript make a particularly good start. Like Logo, the kid can make things happen nearly immediately, but since ActionScript has a syntax that is similar to "real" languages in common use, the habits gained are more directly transferable to other projects later on. I'll refer you to Ned Batchelder's site for a better argument: http://nedbatchelder.com/blog/200711/best_computer_language_for_a_begi…
jcl · 2009-01-21
You can use characters to draw, and it's cross-platform, too: http://nedbatchelder.com/blog/200805/css_homer_animated.html (Not that I'd recommend it.)
Mawr · 2021-05-18
The difference is that with exceptions sloppy code is the default. As you write code in a language with explicit errors, the language makes you acknowledge that the code you call can error out. This makes you stop and think what to do about the error. You can choose to ignore it, but that's a conscious decision that the language forces you to make. With exceptions, there's no such feedback mechanism from the language/compiler. In order to write robust code you yourself must have the discipline to add exception handlers around the appropriate calls. In short, defaults matter. It's simply easier to write correct, robust code when you don't have to go out of your way to do it. See https://devblogs.microsoft.com/oldnewthing/20050114-00/?p=36693: > It’s really hard to write good exception-based code since you have to check every single line of code (indeed, every sub-expression) and think about what exceptions it might raise and how your code will react to it. ... which leads us straight to favorite exceptions-caused bug: https://nedbatchelder.com//blog/202001/bug_915_solved.html: > Inside tempfile.NamedTemporaryFile, the error handling misses the possibility that _TemporaryFileWrapper will fail.
lumpa · 2021-02-10
Makes sense, I think you can get some answers in HN (worth asking again, maybe direct the question to "parents of children in the autistic spectrum"?), but there are better places to ask. It's great that you're taking steps to give your son the best environment you can, please take these as attempts to help you achieve that. You say you don't know about what I asked and if asked directly they'll justify as necessary focusing on the affected children. That doesn't help you much, maybe there's something already published you can find yourself and read to help figuring things out? What do Dane psychologists/neurologists say in articles they write? Are the comparisons of the different systems in Europe? You have to go a bit deeper to figure out what is best, reading about about autism is part of the package IMO. Some people[0][1] find that writing about it also helps. Also, you're (going to be?) THE expert on your son and his needs, no doubt about that. So if you study a lot right now it'll help to make your case (and/or mind, if you haven't decided what's best yet) and get the assistance he needs sooner. You can be the best people at fighting for what your son needs, it's a necessary skill to have in the long run. Asking and caring about the best way shows you've already started on this journey. Being somewhat of an outsider does complicate some things, but it also offers you perspective and that may be more important for you and your son in the long run. So don't blame…
jordigh · 2015-04-02
This is a quibble, but there are cases when the physics of the computer cannot be disregarded and must be considered. Two of my favourite examples are cosmic rays flipping bits [1] and printers jamming. [2] Regardless, I agree with his overall thesis: the machine is just a hunk of atoms with no meaning of its own. It is us who place a meaning on the machinations of the computer. Computer people have come to accept the abstractions of computer science as tangible and consider the abstractions of mathematics intangible. I think both abstractions are comparable. Both end up being interpreted and executed by humans and by computers, and it is merely the overwhelming prevalence of CS abstractions being executed by computers and mathematical abstractions being executed by humans that is causing this divide between the two tribes. There is much that computer scientists can learn from remembering that the machine is just a represantion of abstractions, just like mathematicians can benefit from remembering that occasionally the physics of the machine are relevant. ---- [1] An entirealy reasonable explanation at times, http://lwn.net/Articles/219983/ [2] http://nedbatchelder.com/blog/200811/print_this_file_your_printer_will…
dfcarney · 2013-02-14
Their server is down. Here's the content: -- by Rohit Sethi on February 13, 2013 -- http://blog.sdelements.com/author/rohit/ The latest Rails security flaw [1] is example of a common anti-pattern. Ned Batchelder wrote an awesome post [2] explaining how a similar issue may also exist in Python’s YAML parser [3]. Looking at these vulnerabilities, I am reminded of similar flaws in other frameworks and libraries. The issue in each case is an abuse of extensibility. At first glance the idea is clever: allow for run-time execution of new code or binding of server-side variables without changing your compiled code, thereby greatly enhancing extensibility. For example, provide extensions to your Python YAML parser that allow you to create arbitrary objects and execute Python code; provide extensions to XML Template parsing that allows for arbitrary command execution [4]; or dynamically assign user-supplied parameters to server-side variables [5] (aka mass assignment) based on the parameter name. This kind of vulnerability is by design in contrast to many other by accident vulnerabilities. We called the mass assignment anti-pattern out [6] several years ago when doing a security analysis of the Core Java EE Patterns for OWASP. I have a strong feeling we’ll see more vulnerabilities of this type, particularly with the rising popularity of standards like SAML that are built upon several layers of libraries implementing and extending complex specifications. These kind of issues can…
SanjayMehta · 2026-02-07
That's his style. It's not just his blog style, it's the same in his book. https://nedbatchelder.com/blog/200207/stephen_wolframs_unfortunate_ego
rmunn · 2025-09-13
> ... Batchelder's piece on the "Unicode Sandwich," ... Is this the piece you mean? https://nedbatchelder.com/text/unipain.html
jcalx · 2025-08-25
This article and its associated HN comment section continue in the long tradition of Big O Notation explainers [0] and getting into a comment kerfuffle over the finer, technical points of such notation versus its practical usage [1]. The wheel turns... [0] https://nedbatchelder.com/text/bigo.html [1] https://nedbatchelder.com/blog/201711/toxic_experts.html
nedbat · 2025-07-29
Using multi-level Carlson Truchet tiles for half-toning images: https://nedbatchelder.com/blog/202208/truchet_images.html
Terretta · 2025-07-23
I still prefer Andale Mono. Here's an interesting take on the two: https://neil.computer/notes/berkeley-mono-december-update/ See if you can figure why I linked this one. --- More about Andalé: https://en.wikipedia.org/wiki/Andalé_Mono This conversation may still be going on 20 years from now: https://nedbatchelder.com/blog/200602/monospace_fonts_compared.html Nice we have more choice since this capture in 2006: https://www.donationcoder.com/forum/?topic=2499.0
Gibbon1 · 2024-11-01
I saw someones tool that allows you to embed python code to generate C code. https://nedbatchelder.com/code/cog/ Never used it.
hprotagonist · 2024-07-06
https://nedbatchelder.com/text/which-py.html Ned’s list is what I usually use.
Until the 3.13 release, here's a trick on pasting: the paste function from https://nedbatchelder.com/blog/201904/startuppy.html will accept pasted input and then evaluate it as code (after EOF is sent via Ctrl+D on Linux/Mac or Ctrl+Z Enter on Windows). Adding that function to a $PYTHONSTARTUP file will make it available automatically every time you launch the REPL. It's definitely a hack, but it's a pretty decent workaround for now. I'll likely continue to use it even after the new REPL launches because the textwrap.dedent call will auto-unindent indented code (when pasting from a markdown or reStructuredText file for example).
mirashii · 2023-12-29
One example is reimplementing coverage.py with this, as its made to reduce overhead for the types of tools enumerated in the docs. https://nedbatchelder.com/blog/202312/coveragepy_with_sysmonitoring.ht…

Keyboard shortcuts

/Search
j kNext / previous blog
EnterOpen selected blog
vVisit the blog site
fFollow / unfollow
lSwitch grid / list view
dSwitch dark mode
g hHome
g pTop posts
g tTopics
g fFollowing
g lLiked
g yHistory
g qFAQ
EscBack / close