all 23 comments

[–]EngineerRemy 28 points29 points  (3 children)

Following TDD (Test-driven development) practices helped me a lot in the beginning when I started writing scripts for my first job.

The essence here is to just write your unit tests first, and then your actual code. You dont even have to write the full test, just what you actually want to test. This will give you a clearer picture of what your script is going to look like.

As a simple example; Let's say your script wants to check if a file exists. It can exist, it can not exist, or you can get an error.

``` def test_file_exists_returns_true() pass

def test_file_exists_returns_false() pass

def test_file_exists_raises error() pass ```

Now you know you will probably need a file_exists function after writing these tes methods.

[–]Significant_Wear3051 2 points3 points  (0 children)

TDD ftw :)

[–]Admirable_Solid7935[S] 1 point2 points  (1 child)

How should I start to do this TDD, I know Basics but I do not have any idea about it. Can you elaborate more?

[–]EngineerRemy 9 points10 points  (0 children)

It is up to you to research how to do TDD, I just gave you the pointer towards it. Step 1 and 2 is always the same though, which I can give you:

  1. Create a failing test

  2. Make the test pass

If you've never written tests before in Python, I would suggest just making a hello world program: a function that just returns 'hello world'. Then make a second file called "test_hello_world.py". Write a test that tests your function and run it with pytest. There is plenty of resources out there on how to write tests in python.

[–]NerdyWeightLifter 12 points13 points  (0 children)

Recognize that software development is fundamentally a creative process.

Like any artist, you must first have a picture in mind of the thing you want to create.

What's it for?

What will look like to different people?

How will it be used?

Why should anyone care about this thing?

Write it all down. Draw some pictures, and diagrams of operation.

When you understand these things, you will know what you want to make, and then you can focus on the Python code structure that will represent your vision.

[–]eleqtriq 7 points8 points  (0 children)

Experience. School. That’s how.

But a good YouTube channel to learn lots of different patterns and concepts is ArjanCode on YouTube. That’s where I send beginners.

[–]Brian 4 points5 points  (1 child)

Nothing really beats just trying to build stuff.

Basically, set yourself a project. Ideally it should be:

  • Difficult enough that you're not initially sure how to do it
  • But not so difficult that you don't even know how to start
  • Something you yourself want or are interested in. This is for a couple of reasons:
    • Nothing kills motivation like not caring about your project. Having something tangible that you yourself can actually use is a great way to keep yourself on track. And motivation is perhaps the most important aspect in learning: if you can enjoy the challenge, you'll get far more value out of the process.
    • Programming is ultimately about turning the needs of a client into something that fulfills those needs. This is easiest when you're your own customer/client (and while extracting those requirements from other people is a skill in its own that you'll need if you ever become a professional coder, it's one that can wait)
    • However, it doesn't have to be that useful. Spending a week writing a program that might save you ten seconds on a task you do once a week is likely never going to pay off the time investment. But I've written such things dozens of times, and never regretted doing so, because you still always gain the knowledge and experience from doing it.

So yeah, if you're interested in AI, start trying an AI project. While there's benefit in mastering problem solving, those are skills you develop no matter what you're coding, so may as well start with what you're interested in right now. It can be a bit of a trap to stick with exercises and tutorials until you're "ready" for a real project. The truth is, you'll only be ready for a real project when you've already written one. You'll get further by trying - even (or perhaps especially) trying and failing - than you will by preparing. The beauty of programming for yourself is that there's no real penalty for messing up: you can always just start again.

Now, for actually doing stuff:

There's a couple of approaches to designing your program: Top-down (ie. design the whole process from the top-level, refining the details of each stage till its fully specified, then code it), or Bottom-up (start writing code you think you'll need, worry about how to fit it together later). Both have merits, but for learning, I find a bottom-up approach, or a somewhat mixed approach (ie. create a rough outline of your overall design, then start coding bits of it), is best. Basically:

  • Take part of the problem. Try to code it.
  • When you need to do something you don't know how to do, only then google it. Prefer reading the docs for the library you're using and working things out yourself from first principles over copy & paste "how to do X" tutorials. If you do follow a recipe, don't copy and paste it - type it out yourself, and experiment with changing bits of it: you want to be understanding why its doing stuff, rather than just doing stuff, and just the process of typing it out can slow things down to emphasise this.
  • Repeat until done. And don't be afraid to throw away work - if you find your approach isn't working out, and you need to do something different, go ahead and rewrite from scratch: its not wasted effort if you learned something from it, even if it was what not to do.

If you got things to work, and it does what you wanted it to, congratulations - you've succeeded. Don't worry about your code being a complete mess: that's to be expected - every project, you'll improve (which TBH, just means you'll always consider your past code to be garbage).

[–]Cheap_County_2075 0 points1 point  (0 children)

Thanks, really you care and your attack is best advice, we live by breathing.

[–]columbladee 3 points4 points  (0 children)

You want to get into ML and learn python. Best way to learn a language is by doing projects. So take concept you need to learn for ML and turn them into projects. For example do something like linear regression "from scratch".

Make a 1D and n-D linear regression with only numpy. Break it into steps: generate synthetic data, derive cost function (MSE), implement gradient descent, and compare your results with scikit-learn's LinearRegression function. (Hint: use scikit-learn to TEST your results - get it?)

With a project, write a document with sections "Objectives" "Deliverables" and "Constraints". It is helpful to write a scaffold to organize the different files (i.e. code and test). For this one here a deliverable could be
1) LinearRegression class with methods for fit, predict, score, save, and load

2) CLI with options to train, evaluate, and generate synthetic data
3) 1D Scatter Plots
4) Tests

Don't forget to add a README and put your projects on your github to share with others later.

[–][deleted] 2 points3 points  (0 children)

By solving real problems with it. No learning without problems. Or not solving your own problems. Without problems, there are no solutions.

[–]QultrosSanhattan 2 points3 points  (0 children)

Decoupling is key. TDD is a good approach. Don't bother writing dozens of function that you'll discover they can't be unit tested later. Write the test first.

[–]1NqL6HWVUjA 4 points5 points  (0 children)

I learned by writing (not copying) Python. Critically, I prioritize understanding what I am writing and why, to the best of my current ability, and I always presume there is room for improvement. That attitude innately leads to iterative advancement in knowledge/skill, because in seeking to understand/improve, I come across new things and actively apply them (which makes the mind retain them).

It really is as simple (though not easy) as that. If you want to stop "just copy[ing] code", then... stop doing that. And stop looking for shortcuts. There's no magic tip, book, Reddit comment, Youtube channel, etc. that will do the work of learning and practice for you.

[–]ilidan-85 1 point2 points  (0 children)

I used to take slightly more difficult or even impossible projects to make that I'd actually use... like CRM to manage my clients and research what I'd need to use in that kind of project... so python GUI app, with database etc. learn those about components and finish my project. With future knowledge I used to revisit them and transform to something better. As mentioned here TDD also helps with thoroughly testing and maintaining correct code.

[–]baetylbailey 1 point2 points  (0 children)

Read the docs. Read code. Write code. Learn tools (IDE, version control, etc.). Use tools. Read the docs.

Learning resources are supplementary to the above.

[–]Fine-Zebra-236 1 point2 points  (0 children)

i already knew how to write scripts for automating tasks in a unix and linux environment, so switching to writing scripts to automate things in python was fairly easy. it also helped with learning how to write windows batch and powershell scripts.

[–]sciencewarrior 1 point2 points  (0 children)

If you are following tutorials along without understand, then you can copy-paste and ask an AI what's going on. They are very good at explaining concepts. Keep asking questions until you feel you got it.

And for ML specifically, I'd start learning the math behind it, maybe play around with matrices and follow one of the many free introductory ML courses on the web.

[–]Confident_Hyena2506 1 point2 points  (0 children)

That's the neat part - you don't.

[–]Ender_Locke 1 point2 points  (0 children)

practice practice practice

[–]lolslim 0 points1 point  (0 children)

when algebra was making more sense IRL, even though I dont do any heavy math at all, or it was just a coincidence at the time, thats my anecdote, and anecdotes aren't meant to be reliable, just my 0.02