r/Python • • Jan 14 '22

Discussion Python is a hammer, and we are carpenters, building houses

Something I struggled with for a long time is beginners, and it might just be a personal bias, but particular Python beginners. Both online and offline I see so many questions weekly that roughly fall into two camps

  • Are there any universities that teach undergraduate CS purely using Python?
  • How do I become a data analyst using Python`?
  • What should I learn to get a job as a python developer?
  • How do I make quick money using Python?

While the other camp is roughly along the following lines

  • I want to build a Python application that calls me and ask if I have taken my medicines.
  • How do I build a website only using Python?
  • I am playing game X, how do I train an AI to play the game perfectly?
  • How do I make Python buy and sell crypto currency based on tweets?

I am not saying these are bad questions (from beginners), but they irked me. I was struggling to explain to beginners what the issue with questions such as these are. Is there an easy to understand analogy which would help. Finally, last night it struck me.

Python is a hammer, and we are carpenters, building houses

Lets rephrase the initial questions with this background instead to show how absurd they become

  • Are there any universities that teach carpentry only using a hammer?
  • How do I become a roofer, framer, ship carpentry etc., only using a hammer?
  • What should I learn to quickly get a job using a hammer?
  • How do I make quick money using a hammer?

Now we see that the fundamental issue with the first sleeve of questions is that Python is a tool, we as programmers use, to solve problems. Limiting our toolbox to only using a single tool would make it impossible for us to work. In addition we are offered jobs based on how well we are able to solve problems, not on the particular tools we know. If I am adding someone to my team I am 99% sure they have never worked with our framework, and I could not care less if they are Thor the god of hammers. What I care about is if they can learn our framework, flow of work and seamlessly fit our team after half a year or so of on-board training.

Instead we should first look at what we are trying to do, and then pick the right tool for the job.

Similarly the issue with the second handful questions is unfamiliarity with programming and the amount of work required to make something. What I like with the carpentry analogy is also that it is easier to visualize the scale. A real life program (or a house) is a big project, something that requires multiple people, several weeks or months to make.

Maybe the carpentry / hammer analogy will help next time someone asks:

"Hey I got this idea for a website, and I know you know Python, can you make it for me real quick?"

790 Upvotes

132 comments sorted by

View all comments

51

u/czar_el Jan 14 '22 edited Jan 14 '22

it might just be a personal bias

I agree with your points and overall perspective. But an explanation for why beginners ask the questions they do is they are beginners, and you're not considering their context.

Your points seem biased to the experienced/professional side of Python users. Would you train a new homebuilder by saying "Don't focus on how hammer works, there are so many other tools we'll need to build this house. Today's lesson will cover hammers, miter saws, concrete stampers, electrical wiring tools, plumbing wrenches, insulation sprayers, and roofing nail guns. If you ask a question, make sure it's not about just one tool." No, you wouldn't, because each of those tools is in a different homebuilding discipline and you'd teach them in phases. But that's kinda the equivalent of your post. You're critiquing beginners for asking about the tool they're learning in the context in which they want to learn it, and telling them to think/learn bigger. Beginners sometimes need to go one step at a time, like how the new homebuilder won't master carpentry, electrical wiring, plumbing, foundations, and roofing all at the same time. They may eventually learn them all, especially if they move up in the industry or decide not to specialize, but not as beginners. The questions you mention having a problem with are the one step in their journey, not their lifelong approach to Python.

Another bias with your post is that you're coming at it from a programmer/comp sci perspective, but some Python users aren't full developers, they may just need Python for quick visualizations or basic statistics, not full stack UI and web dev. Would you train someone interested in building furniture by saying "Hammers will work here, but they are also often used alongside concrete, electrical wiring, plumbing, and insulation tools -- be sure you ask about them too." Of course not. So it's OK that a Python learner asks about their context and not about Python in relation to the whole ecosystem of approaches to problem solving, because they need to learn their context first and may not need the extra context yet. Again, they may eventually need to branch out, which is when your advice would apply. But not when they're still beginners.

Your points make the most sense for someone who is just past the beginner phase. They now know the basics of a language, and need to follow your advice so they don't begin to see every problem as a nail. Depending on their needs, they need to decide whether to go deeper into Python mastery, or prioritize learning another language/framework with a complementary pro/con list to Python.

tldr; you're right, but beginners may have legitimate reasons to ask the questions the way they do because they are beginners.

14

u/rupen42 Jan 14 '22

I think it's easy to forget that learning other programming languages looks much more daunting if you haven't done it before, specially coming from a friendly and nice-looking language like Python. You just spent a few weeks/months/years learning python, you're just now getting confident in it. You don't want to "lose all that progress."

I used to think that until I actually tried to build a widget in html/css/js and finished it in the same day, with no prior experience with them. It's not obvious that a lot of that "progress" transfers over pretty well.

2

u/tmckeage Jan 14 '22

from a friendly and nice-looking language like Python.

ehhhh, I love python, but like the majority of scripting languages it is full of landmines.

I really wish people would stop saying it can do OOP.

4

u/doulos05 Jan 14 '22

What part of OOP can't python do? It's got classes, it can do is-a and has-a inheritance, it can do encapsulation. Is it the lack of a private keyword?

-1

u/tmckeage Jan 15 '22

The lack of a private keyword means it can't do encapsulation.

Classes are state engines. Properties are pointless unless you can be 100% sure no one can directly change the underlying private members.

A contrived example:

Let's say you have a class called Int_Compare:

class Int_Compare:
    def __init__(self, n1, n2):
        self._n1 = n1
        self._n2 = n2
    
    @property
    def product(self):
        return self._n1 * self._n2

    @property
    def common_factors(self):
        if not hasattr(self, '_c_f'):
            self._c_f = get_c_f(self._n1, self._n2)
        return self._c_f

This is all well and good until some junior dev comes in, creates an instance, gets the common_factors and then changes _n1 because they want to get the product of a different number.

Now there is a ridiculous bug that could take weeks to find all because python's developers refuse to make private variables private.

That is a huge problem. What I find particularly amusing is supposedly it is "to keep things simple."

This completely belies the fact I have to completely muck up my code with a billion "self." prefixes. That neither keeps things simple or improves the readability of the code.

Now this isn't strictly a OOP requirement, but it coupled with the lack of private members demonstrates that OOP is still being shoehorned in.

Python has objects and that is great, but it can't do OOP.

0

u/[deleted] Jan 15 '22

[deleted] — view deleted comment

1

u/tmckeage Jan 15 '22

First no one would write a a class like that period.

It is completely contrived to demonstrate the concept of just in time computation and how a lack of true encapsulation breaks OOP.

If you can't get past a class name that's on you 😂

0

u/[deleted] Jan 15 '22

[deleted] — view deleted comment

1

u/tmckeage Jan 15 '22

Actually no screw that.

The class itself is contrived, but the class name is perfectly acceptable. If the point of the class is to generate various outputs based on the comparison of two integers what else would you name it?

0

u/[deleted] Jan 16 '22

[deleted] — view deleted comment

→ More replies

2

u/oouja Jan 15 '22

Unfortunately, it's really daunting. Yes, it's (usually) trivial to write a simple thing in a new language. But a whole new project, following best practices, utilising its extended ecosystem (something like pandas and Django in case of Python) and avoiding pitfalls? I will take at least months to get to that level. I'm currently learning Rust in addition to Python to rewrite some performance-critical code and damn, it takes A LOT of effort to produce something actually useful, and I still wouldn't be good enough to be employable as Rust developer without investing the same time I've invested in Python ecosystem.

2

u/rupen42 Jan 15 '22

Yeah, that's a really good point! It's not as daunting as someone whohas never done might imagine, but it's also not a walk in the park. Once you start using stuff like pandas or if you want professional level fluency, it will take more time. I was thinking from a very beginner perspective and for mostly personal use.

Also a good argument for getting started on other tools, provided they're better for the task and/or you see yourself needing them in the future. Sticking to python exclusively will be easier on the short term, but it likely won't be a great long term strategy, depending on your goals.

13

u/mikew_reddit Jan 14 '22 edited Jan 14 '22

The questions you mention having a problem with are the one step in their journey, not their lifelong approach to Python.

OP is pulling the "How to draw an owl" meme.

Step 1. Draw a circle

Step 2. Draw the rest of the owl

Let the beginners learn and use Python everywhere; explain there are better ways and if they want to take on other things, go ahead and explain further. But if they don't since programming in Python is enough to keep them busy, that's fine also.

5

u/richieadler Jan 14 '22

Let the beginners learn and use Python everywhere; explain there are better ways and if they want to take on other things, go ahead and explain further.

I don't know if that's OP's point, but I find many of these questions can be retranslated to "There's this tool. Is the only tool I'm willing to invest a modicum of time learning. Not the process of thinking how to use tools in general or how to solve problems: this tool. How can you help me make it big with it?". There's a lot of lazy magical thinking in those kinds of questions.

4

u/doulos05 Jan 15 '22

When I first learned python, I thought learning a programming language was like learning a natural language (i.e. hard to do and requiring extensive, focused practice over an extended period of time). This was reinforced when a friend of mine discovered Ruby and was like "Oh My GaWd, RuBy Is TeH aWeSoMeS!" So I tried to learn it and thought, "This isn't actually that awesome, I don't understand why he's so hyped about it, it just looks like my Python code but harder to read because it's a bunch of one-liners."

I didn't know programming fundamentals and I didn't know Python, so I wasn't writing Ruby, I was writing Prubython (python in ruby syntax). It was ugly and confusing because I wasn't using either language correctly.

Now, I know that learning programming languages is not at all like learning natural languages. I now know Python and JavaScript reasonably well, Common Lisp and elisp very well, and am learning Java (and soon C#). These are the languages I'm comfortable enough in that I could write a small to medium project pretty much directly from the documentation in whatever libraries I needed to use because I know the core or the language well enough to envision the code.

But it took me a decade to even attempt learning another language because of that false perception about programming languages being like natural languages. In other words, what we really need to be doing is teaching beginners that learning your second programming language is far FAR easier than learning your second natural language.

3

u/richieadler Jan 15 '22

what we really need to be doing is teaching beginners that learning your second programming language is far FAR easier than learning your second natural language.

That's an interesting point. Thank you for sharing.

4

u/Humbabwe Jan 14 '22

Tbf, as a beginner myself, this cleared a lot up.

2

u/tmckeage Jan 14 '22

I agree with almost everything you said except the bias.

I have serious doubt that this person is a professional, or if they are they are only a couple years out of school.

It drips of Dunning Krueger.

1

u/SnooCats196 Jan 14 '22

Wow, excellent response.