What is the best way to learn to code?

I’m teaching myself to program in Python and I’ve hit a bit of a snag. I’m using a course on Udemy and it covers quite a lot; variables, if elif and else statements, while and for loops, booleans, lists dictionaries and tuples, functions, and object oriented programming. However, I’ve found that it’s very, very difficult to take the lessons I’ve learned on the course and apply them more generally to other problems. The instructions are very specific to each exercise. The instructor will say “Give variable X this value, then give variable Y that value, then use a while loop, etc…” all the way through until the project is completed. The end result is that I’ve learned to complete that specific project, but only by following the instructions like a recipe. Ask me to complete a different project using the same techniques and I’m stuck, even if the second project is objectively easier than the first one.

It’s getting very frustrating, especially since I don’t currently have the money to pay for a real course and am basically stuck with teaching myself. What, in your experience, is the most effective way for a novice coder to learn the principles of coding so as to best expedite his ability to use code to solve different problems? Thanks in advance.

Write a lot of code.

Now, you say you’re stuck. What do you get stuck on? If you know what you want to do, but don’t know what algorithms/data structures/techniques to use, then google it. Read stackoverflow. See how other people solved similar problems.

If you’re stuck on translating a higher level concept into something that you might begin think about coding, that that’s a tougher nut to crack. Definitely write down what you want to do, then break that into smaller and smaller pieces until you can recognize that as something that’s doable.

Even though at one point I was a whiz at Fortran 77, yes, I’m that old, I wanted to teach myself Python. My company suggested I go through Google’s Python Class and the exercises were general enough to be applied to lots of different situations. You want to take a look and see if that works better for you. Once you learn the basics you should be able to apply them to just about kind of programming you need.

Coding is sort of like building things with Lego. You’ve got some pre-built chunks (assignment, loops, etc.) that you can stick together however you want. To some extent, it’s one of those things where, once you see them snap together, you shouldn’t really need anything more to figure out how to snap them together in another way to get a different design.

If you understand what the blocks are and what they do, but you can’t figure out how to accomplish tasks with them, then I’m not sure that this is a problem with the course you’re taking. Ideally, it just means that the projects you’re trying to do without the book are too big for you to try doing. You should be doing things like printing the letters into a triangle, in the terminal, not trying to build your own 3D shooter. But if you can’t even figure out how to do some simple loops and drawing stuff to the terminal, then I’d probably suggest against throwing too much money into your continued studies.

This. And look at real code written by others. Reading code is a skill in itself and working out how someone else’s code works leads to understanding what you will need to do when you write your own.

Learning what code is doesn’t automatically lead to developing algorithms, something else you’ll get a better understanding of from seeing how solutions to actual problems were implemented.

Silly question, probably, but what qualifies as “real” code, and where would I find it?

That.

Seconded. I learned to write code by poring over code written by others. Why did they do that? Was it genius or a mistake?

And I learned to write music by poring over discarded music charts in a reproduction shop. Why did they to that? How did they do that? Was that a good idea or a mistake?

Googling “python code snippets” is a start. Usually, these are short code samples that aim to execute very small, specific tasks. Try to understand the logic of how the code samples work. Ask yourself what the purpose of each line of code is, why it needed to be included at all, and other such “why” questions.

It sounds like you may be trying to tackle projects that are too complex for your experience level. There is a reason the canonical learning examples are things like printing text onscreen (“Hello World!”), doing arithmetic and writing a simple text-based calculator program, dumping text file contents to screen, writing text to a text file, and so on.

Question: why do you want to learn to program at all? Do you have specific long-term goals in mind?

Code used in actual programs that people successfully use, as opposed to snippets of code used in classrooms and nowhere else. Where you find it is in open source applications and Github, as well as offices everywhere. If you run Linux, it should be easy to dig into the guts of any program on your computer. Raspberry Pi I think is geared towards just that use.

Speaking of which, a lot of microcontrollers, DSPs, experimenter boards, and other programmable hardware often come with fairly sophisticated sample programs, if you want to go that route. I’ve found the sample programs are a good bridge between “Hello World” type practice stuff and large, complicated applications. One I remember was a temperature sensor network that came with an RF board. Good way to understand how the radio features worked and how to access them in code.

The other.
mmm

I want to become a professional programmer. Ideally, I’d like to work in front end web development. I’m learning Python because some friends of mine who know a bit about programming recommended it to me as a good beginner’s language, and as a useful stepping-stone to more complicated languages like Javascript.

As a bit of background, I’m 35 and have spent my entire adult life working in a completely unrelated field (banking). I wouldn’t have thought about changing careers but the company where I’d happily spent the last 10 years decided to move my office to the other end of the country as a cost-cutting measure, so I had to take redundancy. I’m currently working in another bank near where I live doing a much more menial job, and that’s kind of soured me on banking altogether, so I’m looking for a fresh start in a new industry. I’ve always been quite good with computers, and coding seems like a growth industry so I thought I might give it a shot.

Figure out a problem that interests you, and then break it down into discrete steps.

The only way to learn this is by doing it. Dealing with problems already broken down for you by someone else might work for learning the basics of syntax, but yeah, it doesn’t really help you with the conceptual matters.

Say I need to clean my gutters. I can break that down into a number of steps: Move the ladder next to my house, climb the ladder, pull the shit out of the gutter, put the shit somewhere for temporary storage, climb down the ladder, move the ladder a few feet down, climb back up it, pull more shit out, etc.–these last few get repeated several times, of course, so it might be represented as a loop: do (these things) until (ending condition) is reached.

There are a couple more steps, of course: dispose of the shit, and return the ladder to its storage location.

Then, I break each of those steps further down. Moving the ladder next to my house involves getting the ladder out of my shed, carrying the ladder, setting the ladder down, opening it up, and finally moving it into its final position.

And we can break it down further: getting the ladder out of my shed involves getting up from where I am now, walking to my shed, opening the door, walking to where the ladder is, wrapping my hands around the ladder, lifting the ladder up a few inches, walking back outside the door, closing the door, etc.

“Pulling shit out of the gutter” also requires a number of steps: I reach my hand in, wrap my hand around a bunch of shit, lift the shit up, move my shit-filled hand away from the gutter, drop the shit–and since this is repeated a few times for each trip up the ladder, then it too can be represented as a loop, nested within the broader go up the ladder–pull shit out–go down the ladder–move the ladder loop described above.

You keep dividing these steps into further and further substeps and control structures until you reach the level at which your chosen language and environment abstracts away everything more fundamental.

You do this enough, and you’ll notice a few things. First, there are certain patterns that are approximated in a number of different problems–some are common to a class of closely-related problems, others are mostly universal. Second, you’ll notice that certain collections of substeps are logically equivalent to other, differently-expressed collections of substeps, and sometimes one form or another of expressing it can be better either in terms of how much time it takes you to write it, resource usage, the time it takes to execute, etc. Third, a lot of times processes that you thought were very different actually look very similar on a more fundamental level, meaning that you can use the same code to accomplish different tasks by adjusting some starting parameters.

Suppose you do teach yourself to program. Will someone hire you on that basis? Society seems to run more on certifications of one type or another. So I would ask what are the best types of programming learning venues that will provide certifications for your circumstances.

Piggy-backing on Beren Erchamion’s ideas and tying it to your background, start with problems that you conceptually understand, and code solutions for them. Write a program that spits out a loan amortization schedule given input parameters. Write a register program that accepts multiple numerical values as inputs and tallies totals and subtotals. Build a Monte Carlo investment simulator. Sort things, group things, whatever you want. Identify manual, repetitive computer-based tasks you regularly perform; write a program that automates the task for you.

Programmers are hired based on their ability to demonstrate the ability to code during an interview. No developer cares how you learned your craft, so long as you can demonstrate the ability to do the work.

HR, though, checks to see whether you have a CS degree and unless you have decent experience, they are unlikely to pull you in. Though, now, some companies are using online tests and deals with online coding challenge websites to find people, bypassing the regular HR resume check.

I’ve never seen anyone with a certificate on their resume who could code and many other people I have spoken to have said the same. I’d say that, on average, having a certificate is going to work against you rather than for you.

I’d also recommend against posting your github or sending in any way for a person to check out your code. So far, I’ve never seen anyone who did this whose code didn’t scare me.

If you’re learning python, there are many libraries written for it that will allow you to do different things. They should all be open source and available on the web.

There are a few, like numpy, that are not really python libraries. Rather, they’re C or C++ libraries that can be called into from python. Ignore those, if you see them, but that should be the minority.

I’m a computer programmer by trade, if that makes my answer any more or less appealing to you. Not webdev though, more back-end computer-vision/image-processing stuff.

Python is a solid place to start if you’re going to be doing front end stuff (like webdev) as it hides and abstracts many of the scary aspects of lower level languages. So recommend you stick with that, if you’re going into webdev you’re absolutely going to need to be proficient at writing javascript however.

You should also check out “Automate the Boring Stuff with Python” by Al Sweigart. The ebook is free, and the paperback is pretty cheap on Amazon. This book will teach you basic Python syntax while at the same time giving it practical applications. Website scraping, parsing text-files, automatically sending text and email, even basic image manipulation. It’s really good IMHO. I’ve successfully used this book to tutor a few friends, so I can vouch for it personally.

Other than that, its practice, practice, practice. Seriously you should be reading or writing something new just about everyday. If you need a place to start, two of my favorites are (1) write a program to visualize the Mandlebrot set (great way to learn recursion and basic image processing) and (2) write a program to scrape the archives of your favorite podcast and d/l every episode (teaches you web crawling and regex).

The most common certification in the U.S. is college degrees. I find it very strange that you and the other people you have spoken to have never met a BS in computer science from a major university who could code.

Exercises are fine but at some point you have to write a program without anyone telling you how to start.

Pick something to do that seems interesting. Just a for instance, we just recently had a thread on the longest word pair you get by changing a single letter. Try implementing a program that finds those word pairs, or really any other puzzle that sounds fun. If you find that’s too hard, go simpler. Just pick something, “alphabetize this list of words”, “find all palindromes”, “show all permutations of these letters”, or whatever. Or maybe make a simple game, like a text adventure.

Whatever it is, just try to do it from scratch. Don’t Google for programs that already do what you want and try to recreate them; it’s important to develop the skills you need to program things out of whole cloth. And again, if you’ve picked something too difficult, don’t cheat, just try something simpler. Or maybe just a small piece of what you picked.

I’ve written hundreds, maybe thousands of little programs along these lines and I continue to learn new ways of doing things. And when learning a new language, I do the same thing–pick some easy self-contained project and go. It’s way more helpful in the long run than either doing endless exercises or reading pages of someone else’s code. And it’s fun because I’m solving some problem I was already interested in.