[Python Mastery] The hidden costs of "copy-paste" Python programming

Hey there,

Here's a development story that plays out thousands of times each day:

Avid Pythonista Max is working on a function to find the 10 oldest files in a nested directory hierarchy.

He needs to solve this problem to help automate a complicated (manual) workflow for one of his clients, an accounting firm.

So Max pulls up Firefox and punches some keywords into the StackOverflow search box—

And, lo and behold, a helpful looking answer pops out at him among the first few search results.

The "answer" involves about 20 lines of terse Python code. It uses the os.walk function and the heapq module internally.

Max doesn't know much about those—but the guy who wrote the answer has a reputation score of 49,717...

Max really needs to get this file search thing working so he copies the relevant lines of code from the StackOverflow answer and pastes them into his code editor.

Some slight renaming and adding a few imports later it's "Mission Accomplished!" and Max can wander off and grab another cup of coffee.

Great job!

That's how programming is supposed to work these days, right?

I'm not so sure...

Becoming "stuck" and needing to do some research is a daily occurrence for any programmer I know (myself included).

But every time that happens, you can make an impactful LONG-TERM CHOICE:

Do you jump to the first StackOverflow answer and implement whatever is suggested there—

Or do you use the answer as inspiration and take the time to learn a novel concept from the ground up, that you can then use to solve the problem at hand?

Either option solves the problem...and both have their applications in practice.

Here's how I like to think about this choice:

Taking the time to study a problem is like *improving your vocabulary* in a foreign language.

You build up a body of knowledge over time that you can benefit from in the long run.

Copy-and-pasting the first answer that seems reasonable, on the other hand, is like *hiring a translator*.

Yes, it solves the problem immediately, but you'll depend on the translator FOREVER.

There's a lot of "hire a translator"-style advice out there in the programming world.

And it's often to your detriment.

I'm not trying to knock StackOverflow by the way. It's a resource I use almost daily.

My point is:

When you look at the whole picture, convenience always comes with hidden costs.

In the long run, "building your vocabulary" is the much better strategy to achieve fluency.

This is the exact philosophy behind my book "Python Tricks: A Buffet of Awesome Python Features".

It's NOT a tome of code snippets to mindlessly copy and paste from (which are a dime a dozen).

Instead, you'll understand Python's best practices from the ground up—with a clear and logical narrative, and step-by-step examples:

>> Click here to see how to take your Python skills to the next level (without resorting to Stack Overflow "copy pasta")

Happy Pythoning!

— Dan Bader

Older messages

[Python Dependency Pitfalls] Artisanal "from-scratch" development

Saturday, August 6, 2022

Hey there, The other day I got this question from Newsletter member Newvick in my email inbox: ~~~ I'm trying to get past the beginner's stage in Python and one problem I have is: When do you

[Sublime + Python Setup] How to become a happier & more productive Python dev

Friday, August 5, 2022

Hey there, I really struggled with setting up an effective development environment as a new Python developer. It was difficult to build the right habits and to find a set of tools I enjoyed to use.

[Python Dependency Pitfalls] What dev managers expect from Python candidates

Friday, August 5, 2022

Hey there, My friend Og is a senior manager at Red Hat and works with a large team of developers and quality engineers using Python. I got to pick his brain on what he thought were the most important

[Python Mastery] Learn Python in 21 days!!!!11 (what a lie)

Friday, August 5, 2022

Hey there, One of the first programming books I ever bought was "Teach Yourself C in 21 Days." This four pound tome came with a CD-ROM that included an ancient version (3.1) of the Borland

[Python Dependency Pitfalls] How to set the world on fire

Thursday, August 4, 2022

Hey there, #1 on my list of dependency management pitfalls is there for a good reason: It lead to a single developer causing mayhem and breaking thousands of open-source projects around the world in

[Python Mastery] Learn Python in 21 days!!!!11 (what a lie)

Thursday, August 18, 2022

Hey there, One of the first programming books I ever bought was "Teach Yourself C in 21 Days." This four pound tome came with a CD-ROM that included an ancient version (3.1) of the Borland

[Python Dependency Pitfalls] How to set the world on fire

Thursday, August 18, 2022

Hey there, #1 on my list of dependency management pitfalls is there for a good reason: It lead to a single developer causing mayhem and breaking thousands of open-source projects around the world in

Laravel + WordPress, Silver Play Button and More

Thursday, August 18, 2022

Hey hey, So today is an important day for me, as I have unboxed my Youtube Silver Play button for 100000 subscribers, still can't believe it. Meanwhile, business as usual, will still keep putting

Migrate your Elasticsearch data across clusters with zero downtime

Thursday, August 18, 2022

Deep dive on migrating data effectively using CCS and CCR elastic | Search. Observe. Protect Cloud migration workflow using CCS and CCR Register now Date & Time September 8, 2022 1:30 pm SGT, 3:30

Physical buttons outperform touchscreens in new cars, test finds — RavynOS – Finesse of macOS, freedom of FreeBSD — and VPNs on iOS are a scam

Wednesday, August 17, 2022

Issue #862 — Top 20 stories of August 18, 2022 Issue #862 — August 18, 2022 You receive this email because you are subscribed to Hacker News Digest. You can open it in the browser if you prefer. 1

Google will unplug its IoT Core service in August 2023

Wednesday, August 17, 2022

TechCrunch Newsletter TechCrunch logo The Daily Crunch logo By Christine Hall and Haje Jan Kamps Wednesday, August 17, 2022 Hellooo, Crunchy McCrunchface! (What we're calling the readers of the

Explained | The Relationship Between Climate Change and Wildfires 🔥

Wednesday, August 17, 2022

More carbon in the atmosphere is creating a hotter world—and gradually fueling both climate change and instances of wildfires. View Online | Subscribe FEATURED STORY The Relationship Between Climate

New Webinar! SIMULIA Structural Simulation in Consumer Electronics Design

Wednesday, August 17, 2022

Streamline design cycles and get to market faster View this email in your browser engineering.com Robust Mobile Devices: SIMULIA Structural Simulation in Consumer Electronics Design Live Webinar -

JSK Daily for Aug 17, 2022

Wednesday, August 17, 2022

JSK Daily for Aug 17, 2022 View this email in your browser A community curated daily e-mail of JavaScript news Implementing Route Protection in Angular using CanActivate In any complex web application,

JSK Weekly - August 17, 2022

Wednesday, August 17, 2022

Sometimes less is more and this week Coding Beauty shows us "14 Sensational JavaScript One-Liners That Will Show Your Wizardry", why not give them a bash? Other popular stories this week