惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
Google Online Security Blog
Google Online Security Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Simon Willison's Weblog
Simon Willison's Weblog
T
Threat Research - Cisco Blogs
C
CXSECURITY Database RSS Feed - CXSecurity.com
L
Lohrmann on Cybersecurity
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Forbes - Security
Forbes - Security
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security
S
Schneier on Security
T
Tor Project blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
WordPress大学
WordPress大学
The Hacker News
The Hacker News
Hacker News - Newest:
Hacker News - Newest: "LLM"
罗磊的独立博客
Application and Cybersecurity Blog
Application and Cybersecurity Blog
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
C
Check Point Blog
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
雷峰网
雷峰网
S
Security @ Cisco Blogs
PCI Perspectives
PCI Perspectives
Spread Privacy
Spread Privacy
W
WeLiveSecurity
SecWiki News
SecWiki News
A
About on SuperTechFans
H
Help Net Security
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
爱范儿
爱范儿
S
Securelist
M
MIT News - Artificial intelligence
云风的 BLOG
云风的 BLOG
月光博客
月光博客
Jina AI
Jina AI
博客园 - 叶小钗
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
Recent Announcements
Recent Announcements
S
Secure Thoughts
The Cloudflare Blog
美团技术团队
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

blag

SQLite prefixes its temp files with `etilqs_` - blag Setsum - order agnostic, additive, subtractive checksum - blag Oldest recorded transaction - blag Replacing a cache service with a database - blag SQLite commits are not durable under default settings - blag PSA: SQLite WAL checksums fail silently and may lose data - blag Rickrolling Turso DB (SQLite rewrite in Rust) - blag Collection of insane and fun facts about SQLite - blag How bloom filters made SQLite 10x faster - blag In search of a faster SQLite - blag Galloping Search - blag Building a distributed log using S3 (under 150 lines of Go) - blag Zero Disk Architecture - blag PSA: Most databases do not do checksums by default - blag PSA: SQLite does not do checksums - blag Disaggregated Storage - a brief introduction - blag Why does SQLite (in production) have such a bad rep? - blag SQLite Slaps - blag Now - blag Learning C - blag Snapshot Testing - blag Win: contribution to libSQL (SQLite) codebase - blag Errata in Hekaton MVCC paper - blag Internet is wholesome: MVCC edition - blag MongoDB secondary only index - blag Introducing CaskDB – a project to teach you writing a key-value store - blag Recurse Center: Winter Break - blag Recurse Center Day 24: Hacking Go compiler to add a new keyword - blag Recurse Center Day 20: Django v4 upgrade (from v1) - blag Recurse Center Day 19 - blag Recurse Center Day 18 - blag Recurse Center Day 17 - blag Recurse Center Day 16: Open Source - blag Recurse Center Day 15: B Tree Algorithms - blag Recurse Center Day 14: NoSQL Transactions - blag Recurse Center Day 13: Why 'Raft'? - blag Recurse Center Day 12: Isolation Anomalies - blag Recurse Center Day 11: B Tree Insertions - blag Recurse Center Day 10: Learning Distributed Systems - blag Recurse Center Day 9: Papers We Love - blag Recurse Center Day 8: B Tree Fill Factor (Part 2) - blag Recurse Center Day 7: Basics of ncurses - blag Recurse Center Day 6: B Tree Root - blag Recurse Center First Week - blag Recurse Center Day 5: Garbage Collection Algorithms - blag Recurse Center Day 4: B Tree fill factor - blag Recurse Center Day 3: Hammock Driven Development - blag Recurse Center Day 2: BTree Node - blag Recurse Center Day 1: init - blag What I want to do at Recurse Center - blag Accepted to the Recurse Center! - blag Towards Inserting One Billion Rows in SQLite Under A Minute - blag Marshaling Struct with Special Fields to JSON in Golang - blag I ended up adding duplicate records on a unique index in MongoDB - blag Setting up Github Actions for Hugo - blag Moving to Hugo - blag Catching SIGTERM in Python - blag Git/Github fork-pull request-update cycle - blag Using uWSGI with Python 3 - blag When is my Cake Day? - blag Staying Ahead of Amazon, in Amazon Treasure Hunt Contest - blag How I Am Maintaining Multiple Emails For Git On A Same Machine - blag An exploit on Gaana.com gave me access to their entire User Database - blag Flashing Asus-WRT Merlin by XVortex on NetGear NightHawk R7000 - blag Install Windows 8 UEFI on Legacy BIOS with Clover (and Dual boot with Yosemite) - blag Scraping Javascript page using Python - blag Installing Transmission (remote and CLI) client on Raspberry Pi - blag About - blag Projects - blag
It is becoming difficult for me to be productive in Python - blag
2023-02-05 · via blag

Note: Following blog post more or less applies to any dynamically typed programming language, e.g. Ruby. I am only sharing my experience and frustrations with Python, cos that's the language I use.

I started learning to program with Python, which holds a special place in my heart. It’s the language which taught me how to think about programming, modelling a problem to code and communicate with the machine. I was hired at my current job (or the previous one) because of Python. I was a fanboy and evangelist. I spent a lot of time in Python communities, learning and helping others. When I started mentoring beginners to code, Python was my choice of language.

I distinctly remember having the following conversation with a friend:

Friend: C# makes life a lot easier with types

Me: I haven’t had the need. Are they needed?

Friend: But how do you deal with functions that can take any type of argument?

Me: I have unit tests and high test coverage. A small change will catch any changes. Also, you add documentation on functions explaining what they do and the type of arguments they expect. Easy peasy.

Oh boy, how wrong I was. At that time, I had shipped code to production in Python, but there were few users. I did not have experience with other languages.

When I joined my current startup (a team of 3 developers), I started learning Go. I had the responsibility of building a few services. I picked Python for a few because I was most comfortable with it, and I could ship fast. Django was better suited for some of the problems. Indeed, I could ship fast and build some services that are still in use.

In a couple of months, I had stopped writing any new Python. Go was used for new services, and I started contributing them, including some that would be the core, crucial ones. This was many years back. I was still learning Python on the side, e.g. when async came; I upgraded one of my side projects to use it.

We upgraded some internal APIs and libraries a few months ago, and a few Python services needed updates. I was eager to work with Python again, but my enthusiasm faded quickly.

Guess Driven Development

The first issue I faced was understanding the code. It took a sweet amount of time to figure out the kind of objects, things certain functions were receiving and what they were doing with them. The code did have some unit tests, but the coverage was poor. So I had to guess, make changes and test the code at many places.

I could not get hints in my IDE for a few modules. It became a habit to keep the source file open in another tab and refer every time for any new code I was writing. Without type (or type hints), I had no idea how to use a function. A language with type makes a lot of difference when refactoring; one glance at the signature, and I know what to do.

After all the guessing game and refactoring, how do I ensure my changes work effectively? The only way to be sure is by running the code and verifying that every line is executed under all possible combinations.

Years of coding in Go gave me this comfortable feeling: if it compiles, it works. (Rust takes it to the next level; if it compiles, you won’t have memory issues or data races.) The compilation gives quick feedback, which makes it very easy to make changes.

Unit tests and type hints

Type hints solve these issues to some extent, but bugs can still slip through. Unit testing is the way to go. However, this is not always possible, for instance, when enforcing rules within a team is difficult or when inheriting a legacy project. But does enforcing strict rules work in practice? You could set up CI/CD pipeline enforcing 100% code coverage, but that will affect team productivity and surely piss off people.

I want a system where the chances of making mistakes are minimal. I can achieve that with unit tests and CI/CD pipelines. But type safety provides me that by default.

What I have learnt is the real world is not perfect. Having codebases without comments, documentation, and unit tests is common. Some of these are inevitable when working in a team with large codebases. In such cases, working in Python becomes a huge pain.

Is Python fast to ship?

With typed languages, I used to think, ugh, I’d have to define types everywhere, make struct (or classes) in advance, and sometimes make wild guesses because those things were unknown or not finalised. All of these are valid complaints. If I am prototyping in Rust, I will take a lot of time. With Python, I can ship fast. But only once.

Refactoring involves reading the existing code, understanding it and then making changes. Types are like free documentation. For me, it’s hard to understand and reason about the code without them. Types give me the confidence to make minor changes quickly and ensure they work fine when the code compiles.

I am finding it painful to refactor in Python. I can’t even complain that someone else wrote it. I only wrote that code years ago! I could mitigate these issues with type hints and unit tests. But is it fast to ship if I spend so much time doing all these?

Static languages have an initial one-time cost. I find it similar to TDD. But your future self will thank you. If I am touching a project after years, I’d rather wish it was in a typed language. I have written some interesting stuff in Python, like one or this one. I will continue to learn and use it for my side projects. But I am going to dread working on a large Python codebase.

Have comments? Share your thoughts here on the Twitter thread.

Thanks to Hari, Satan, and Sumesh for reading a draft of this.


1. I found this post coining Guess-driven development: Bad programmers spend much of that 90% debugging code by randomly making changes and seeing if they work.
2. Yes, I will not miss the meta-programming features, many of them felt like voodoo to me anyways, and I’d like to avoid voodoo in my codebase.