[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

Key phrases

Older messages

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

Saturday, November 12, 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 Mastery] The secret to "ethical self-promotion"?

Friday, November 11, 2022

Hey there, Here's some food for thought: There's a difference between *doing* a great job as a Python developer, and *to be seen doing* a great job. Being a skilled developer among peers—and

[Python Mastery] What does it mean to "master" Python?

Thursday, November 10, 2022

Hey there, A couple of years ago I'd become quite interested in martial arts. Hours upon hours of watching "The Karate Kid" growing up must've taken their toll on me... And so, I

[Python Dependency Pitfalls] The Iceberg

Tuesday, November 8, 2022

Hey there, The other day I read this quote from a Python developer that made me stop and think: "As a noob with a little programming knowledge already, I've found setting up and installing

[Python Dependency Pitfalls] "Re-inventing the wheel" disease

Monday, November 7, 2022

Hey there, PyPI, the Python packaging repository, now contains more than 100000 third-party packages in total. That's an *overwhelming* number of packages to choose from... And this feeling of

Tesla.com/.gitignore — Show HN: Using stylometry to find HN users with alternate accounts — and The Need to Read

Saturday, November 26, 2022

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

⚡️30% OFF – only three days left⚡️

Saturday, November 26, 2022

Don't miss out! ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌

Digest #79: Run GitHub Actions Locally 🚀

Saturday, November 26, 2022

Digest #79: Run GitHub Actions Locally 🚀 #79: Run GitHub Actions Locally This week's newsletter highlights why containers are just chrooted processes, how to migrate from Postgres to DynamoDB,

Daily Coding Problem: Problem #947 [Hard]

Saturday, November 26, 2022

Daily Coding Problem Good morning! Here's your coding interview problem for today. This problem was asked by Oracle. We say a number is sparse if there are no adjacent ones in its binary

12 AirPods Features You Should be Using

Saturday, November 26, 2022

Did You Know?: Most cranberries are harvested by flooding their fields (they float thanks to little air pockets in the berries) and tend to be frozen or processed quickly once harvested. Those that are

Infographic | Every Song With Over 1 Billion Spotify Streams 🎧

Saturday, November 26, 2022

Spotify's 'Billions Club' playlist tracks every song with over 1 billion streams. We took the data and broke it down by decade and artist. View Online | Subscribe Presented by: Our latest

U.S. Bans Chinese Telecom Equipment and Surveillance Cameras Over National Security Risk

Saturday, November 26, 2022

The Hacker News Daily Updates Newsletter cover A Must-Have Checklist for Workplace Security and Protection What do a bustling workplace, happy employees, and secure equipment and data all have in

Noonification: White Man

Saturday, November 26, 2022

Top Tech Content sent at Noon! Find Your Next Software Engineering Job on Hired How are you, @hacker? 🪐 What's happening in tech this week: The Noonification by HackerNoon has got you covered with

8 Ways Google Assistant Can Increase Your Work Productivity

Saturday, November 26, 2022

Read in Browser Logo for Review Geek November 26, 2022 The year is winding down, and it's getting more difficult to be productive than ever. Call it the weather, call it the holidays, call it all

New Python tutorials on Real Python

Saturday, November 26, 2022

Hey there, There's always something going on over at realpython.com as far as Python tutorials go. Here's what you may have missed this past week: Python REST APIs With Flask, Connexion, and