Subscribe: Mostly Maths
Added By: Feedage Forager Feedage Grade B rated
Language: English
code  design  documentation  email  fast  find  lists  maybe  mostlymaths  new design  python  reading  side  slightly  started  tree 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Mostly Maths

Mostly Maths

Programming for backyard gardeners, cooking for linux users, drawing for mathematicians. WTF?

Updated: 2018-04-18T13:42:20.372+02:00


A Slightly Better reddit Upvote/Downvote Widget (button)


A subtitle to this post could be More yak shaving

A few days go I played a bit with a naive implementation of Bloom filters in Python. I wanted to time them against just checking whether a field is in a set/collection. I found something slightly puzzling: it looked like in worked too fast for smaller lists. And I wondered: maybe small lists are special internally, and allow for really fast lookups? Maybe they have some internal index? This raised the question: how does in find stuff in sequences?

Instead of reading the documentation I delved into the cpython source. Skipping the documentation was a bad idea, since it is not only pretty comprehensive but explains everything... if you know what you are looking for. But a dive into this big pile of C was more fun. I was also stupid enough to not Google the answer until I was editing this post... This excellent Stack Overflow answer covers more or less what I explain here.

The in keyword (defined here) is actually a shorthand for running __contains__ from the target object, you probably know this already. Your class will be able to provide in if you add this magic method, you can read about this in the first chapter of Fluent Python. But tracing this inside cpython is a bit cumbersome and got me diving into interesting pieces of the code. By the way, how the Python compiler works is documented here.

First, after we have parsed the code and generated a parse tree from our text, we go to the abstract syntax tree. Converting the string in as part of some node of Python source in this tree into an In here:


New Design: I hope you like it


It was about time. Something like 3 years ago I redesigned, just after purchasing the domain. Cleaned the design... But left lots of cruft on the side.Back when I started writing HTML for myself, one of the best reading experiences I saw was Paul Graham's one-column text. Also, the reasoning makes sense. When I needed to redesign mostlymaths I tried to go one-column, but I fell for the sidebar trap. Added a section with most-viewed posts, an Amazon widget, a post archive... Lots. Of. Crap.I had been thinking about cleaning up everything for quite a few months and then Matt Gemmell posted a very interesting post: Designing Blogs for Readers. I have been following his twitter account and posting for a while, and many ideas in this post rang a bell.For the past few weeks I have been putting off several writing ideas saying to myself: I'll write it when I do the new design. So screw it, the other day I devoted like 45 minutes to clean up everything. I borrowed a pair of numbers from Matt's CSS (font-size and font-height, mine are slightly larger but are close to his) and basically deleted every design thing that wasn't useful.I have killed comments. This was hard, because I love interacting with readers, and quite a few of my best tweeps have started with me commenting on their blogs or them commenting in mine. But as of late, I have been neglecting answering and moderating, and the best solution was to remove them. If you want to comment, feel free to click on contact on top. I'm not very fast answering my "personal" email either, but eventually I do. You can also reach me over twitter or the Facebook page for mostlymaths without many problems.I left a lone ad on the side (I may turn it into 300x250, but for now I like how small it looks) and I will probably add social sharing at the bottom and find a good way to inline code (no, I don't like github styled widgets). Currently you can't even share what you read here. This is not exactly done on purpose, but after all, if you want to share something you can do it without needing a button. I know I do.Oh, and if you are subscribed by email you may have received a stupid-looking email with many images. Sorry! Messed up with a draft post where I store images I have used. [...]