Pitfalls in learning to program

Tim H. commented:

[…] do you have any advice based on personal experience from when you first started coding? Things to do (or avoid doing) or perhaps something that you know now that you wish you had known when you first started?

Oh, please. I wish I could say that I took all the right turns while learning–if I had, I’d be a much better coder than I am–but that’s not the case.

This is probably more than you bargained for, but here–you’re now the… third? commenter to get a full post in reply to a question.

Building on your own

The biggest thing is that building stuff outside the books and classes is the most important thing to do. I’ve been coding in some form or another since I was about twelve: RPG Maker XP at 12, basic web design at 13-14, VB at 15, Java at 16, and then I went to college–I didn’t choose all my tools, most of this is an expression of what classes/books/programs were available to me at the time. But I usually didn’t go out and build stuff with what I learned in my classes.

I did try to make some games with RPGXP, but I was pretty awful at it because I didn’t know Ruby (the game maker has a Scratch-like interface that generates syntax) and the English documentation was very lacking (I looked). And I put together a few web sites for my parents’ birthdays that… were actually pretty nice-looking, but never got published. I was kind of lukewarm about VB, and I had a hard time coding in Java on my own computer for some reason–something about NetBeans not wanting to work.

–Basically, I tended to use the stuff I self-taught (RPGXP and HTML/CSS) more than the stuff I learned in classes (VB and Java). I did have a class on HTML/CSS, but not before I self-taught it, which was good because the class was horribly outdated. That repeated itself with the Linux class–which was taught very well and was up to date, but didn’t teach me as much as I’d learned by tinkering.

School isn’t as useful as you think

This pattern has held consistently through college: I learn better, and learn more relevant stuff, by screwing around with stuff on my own than by sitting in a class.

What I learned in class: Flash, old Dreamweaver (which was as bad as Flash), VB, Java, pseudocode markup, flowcharts (as if I couldn’t make those before), Windows networking, shell scripting, C#, .NET programming (sort of–the class had serious technical difficulties)

What I’ve self-taught: RPGXP (sort of), HTML/CSS, Linux, Python, working with an API, and a tiny bit of FileZilla and phpMyAdmin for freelance web work. Plus all the stuff I read online about programming and startups and businesses and new technology and other awesomeness of that stripe.

What I’ve used: the second list (minus RPGXP really)

What I feel like I know well: the second list (minus RPGXP again)

I’ve long maintained that I’m going to college to get a degree (formal credentials) and to meet people. I’m much less there to learn, because if that were my only priority, I could accomplish it more cheaply and efficiently by sitting around in an ethnic restaurant of my choice with some books and my laptop every day.

Although, probably the teacher who’s taught me the most is Mr. Noord, because he rarely stays on topic for more than half an hour, and the stuff he ends up talking about tends to be more useful and interesting. Don’t tell the school board.

It’s totally different for networking students though. Then classes are way more worthwhile because the school has the hardware they need to work with, and networking is easier to teach in a class.

Programming is an art form that can’t be taught in a class. Programming is a separate skill from knowing the syntax of programming languages, which can be taught in classes. Knowing the syntax is like memorizing a French textbook. But to learn French, you have to speak it (write programs), listen to other people speak it (read programs), let them correct your speech (take criticism from older programmers), learn the current grammar and slang rules (style and best practices), and keep using your skills.

Classes just don’t usually let you mess around with stuff, and when they do, they put lots of restrictions in place: how long you get to work, how fast you have to work, what you can make, and what other things you have to do or write in order to discuss what you learned so someone can prove you learned it and somehow quantify what you did. It’s a real pain. And then you have to pay for them, instead of getting to spend the money on new books or tools or hardware.

I’m not saying that schools can’t be useful. They can be! They can teach the basics and introduce you to other programmers, and they introduce you to some great teachers and other students. They just won’t teach you the sort of skill that makes a great programmer.

Books are quite a bit better, but still watch out

Books still won’t get you all the way; you have to build on your own. But, at least for me, they’re definitely more productive than classes, in terms of learning a new technology or language.

Books tend to a) be cheaper, b) invite you to mess around freely and without restrictions on time or what you do with the example code or stuff like that, and c) let you choose your tools. When you buy a book, there aren’t required classes. You get to study what you want.

The tools you choose are important

The main reason I’ve never used VB or C# or Flash or the other stuff I took classes on isn’t necessarily because the teacher was bad or the curriculum was awful. On the contrary–I’ve had mostly great teachers.

But the technologies are pretty crap, to be honest.

If you’ve been around very long, you know about my burning hatred of Visual Studio. I didn’t always hate it so much. I used to be lukewarm towards it, back in the days I was using VS 2012 for my Visual Basic classes. We had technical difficulties with it even then, and it liked to crash and all sorts of crap, although nothing like the temper tantrums it’s thrown in my more recent classes.

But now that I know what programming is actually like, I look back on it and realize how boring and tedious it was. It sucked! No wonder I wanted to go into psychology instead. I thought coding was cool, but sometimes I wondered if I just thought the idea of coding was cool and I liked the romantic techie-nerd image it let me imagine, because what I was doing was not that much fun.

(Straight-up HTML and CSS isn’t very fun either, to be honest. Once you get good at it, both the novelty and the challenge kind of wear off. I’m looking forward to learning to code dynamic web pages, though.)

Java was okay, but we didn’t get very far into it, the coding examples were largely busywork, and it was really complex. I think we just got a bad textbook, honestly.

The books you choose are important

The difference between a bad textbook and a good textbook is like the difference between a bad teacher and a good teacher.

Here are the different kinds of books:

Diving Into ASP.NET, MVC, TLA, GPS, and SAT by J. Random Microserf

This will probably have some geometric feature on the cover. It’ll look deceptively shiny and colorful, but it’s as engaging a read as the Terms of Use agreement for the technology it’s purporting to teach. Said technology will of course be the kind that has a Terms of Use agreement, because these books are usually made in order to sell both the book and the IDE or language or whatever the book is about, plus all the attached certifications (which probably all have test prep books of their own).

They’re written by someone who probably does not like the technology they’re writing about, even if they say otherwise in the intro. This will translate into the writing, and you will end up not liking it either.

Generally, these books are best used as eBay fodder or, if the technology described therein has already flunked out (it will soon if it hasn’t), as expensive firewood.

Learn Foo in 24 Hours!!!!

You will not learn foo in 24 hours.

You may get a basic but deceptively broad understanding of foo. But you will not have learned foo.

This book is not quite firewood. It may be helpful, if not so in-depth.

Weird homebrew-looking e-book sold on Amazon

?????

Head First Foo

Made by O’Reilly. This will have a lot of pictures and silly jokes. They’re great for learning from if you need to get a complete understanding of a technology quickly, or if you’re a beginner and you’re kind of intimidated.

I lose patience with them, though, under two circumstances:

  1. I have something I want to build, and I don’t want to sift through 50 pages of pictures of tigers and pizza before I find the bit of information I’m looking for. What I need is not exactly a reference book; I just want the info in a more dense and organized form.
  2. I’m trying to read it as an ebook. They don’t translate well to the format. Don’t buy these as ebooks.

Notably, they’re bad reference books, as you might have gathered. Don’t get them for that either.

Making Stuff with Foo

This could be “Building Dynamic Websites with Django”, “Creating Apps with Kivy” (<3), et cetera.

It’ll contain something like this in the intro.

I’ve been using this technology for foo amount of time, and I think it’s a great tool for doing bar because of how it bazzes the quuxilators. I tried some other ways of doing bar and overall, I like this one the best because it’s well-designed and has great features.

Anyway, I thought a lot about how to write this book, and you might notice that the example code (which is on GitHub at [URL], by the way) is actually not a bunch of different projects–it’s just a couple projects, and we change them over the different chapters so you can see the development cycle better.

I really hope you have fun making stuff with foo using this book. If you find any errors along the way, send me an email at foo@gmail.com.

Not exactly, necessarily, but approximately that tone–you get the idea. The tone of the book will be friendly, but practical and not too goofy. These are great books!

It has a picture of an animal on the front?

That is probably an O’Reilly book. It is worth its weight in gold.

These are very often the “Making Stuff with Foo” variety.

If O’Reilly doesn’t make a book about a technology that is well known enough to have school classes taught on it for, say, a year… that technology may not be worth learning. Unless you can find someone else who wrote a good “Making Stuff with Foo” book about it, and then it might be okay.

Dry Internet documentation

For when you already know what you’re doing. Confusing, frustrating, and boring if you don’t. Buy a book.

Good Internet documentation

Save your bookmarks!

Make stuff. Solve problems. Meet other nerds. Eat cake. Browse GitHub. Play a board game. Tinker with stuff. Install Linux on something. Eat cake again. Hang with your nerd friends.

Have fun.

Happy hacking!

Plant Yourself in STEM: Linux FAQ

I. Questions about Linux

Q: I want to play with Linux some more.

A: Great! You have a few options.

  1. Use a virtual machine. Here are my instructions on how to make one. I recommend this one most because you can run the software well on most modern systems, and there’s no risk of accidentally overwriting Windows or whatever you’re running, and losing all your files in the process. Also, if you break a virtual machine, you can reload it from a snapshot or just make it over again. VMs take a little patience to make the first time, which is why I wrote that tutorial. (It contains a lot of stuff I had to learn by trial and error.)
  2. Use a live CD or USB. Google is your friend on making these, but check at least two tutorials when you make Linux-related stuff. Be careful not to install it over your current system.
  3. If you have money: get a Raspberry Pi and its associated accessories. This can be fun, but you’ll probably end up dropping quite a bit of cash on it. If you want to anyway, again, Google it.
  4. If you REALLY know what you’re doing and this is your own computer, not your parents’, you can make a Linux partition. Be careful with this one. You have to be a little more technical to get it right, and it’s risky to get it wrong. You might want to choose your distro a little more carefully with this option too, to make sure it’s one you like.

Q: What’s with all these different “distributions”?

A: Linux distributions, or distros, are just different varieties of Linux. They all have the same stuff running at the core of the system, roughly, but they can have different software installed and sometimes different commands. Each distro is meant to serve a particular purpose.

Ubuntu and its variants (Kubuntu, Xubuntu, Lubuntu, etc) are meant as a beginner’s Linux–they’re designed to look roughly like Windows and be as easy to use as possible. Linux Mint has a clean design for users and programmers who want something simple, elegant and effective, without tons of shiny graphics. Debian and Fedora are often used in servers or on the personal computers of programmers. Kali is for network security administrators. There are even advanced distros such as Arch and Gentoo, for increased customizability or transparency to the core system below–Arch doesn’t even come with a desktop environment installed, you start out with just the command line interface.

It’s best to start with a simpler distro, like Mint or Xubuntu (which is preferable to normal Ubuntu because of the interface it comes with–it runs faster and I think it looks better). I’m fond of Debian, personally. GNOME 3, the window system it comes with, is rather heavyweight but very shiny. You can put different interfaces on it, though.

Q: Wait, what do you mean “interfaces”? What’s a “window system”? Are they different things?

A: In Linux, the command line is the default interface that’s built into the system. But you can put window systems over the top of it. You know how Mac desktops look different from Windows desktops? Like, the windows look different and Mac has the dock instead of the taskbar? That’s because they use a different window system. Linux has tons of these and you can just swap them around.

“Interface” is a more general term than “window system”–the command line is an interface but not a window system. (Apart from that distinction, they’re interchangeable as far as I know.) That’s semantics, though.

Q: What makes Linux so great, anyway?

A: Lots of things! There are so many reasons to use Linux over Windows (and, to a slightly lesser degree, over Mac)–ranging from the practical to the aesthetic to the philosophical. Here, I’ll list a few of the reasons you probably care most about, but understand that this list is by no means exhaustive.

  1. It’s free! Not only are the vast majority of distros free to download and use, but you can change them however you like or make contributions to them.
  2. Linux is faster, especially on old hardware.
  3. It’s far, far more secure than Windows. Linux very rarely gets viruses, even more rarely than Mac OS X, and when viruses for Linux do appear, an update comes out very quickly to protect the system. But it’s hard to write viruses for Linux because it’s designed so well.
  4. They’re easier to program on. Linux comes with better tools for coders and makes things a lot easier. Tools like git and shell scripting make Linux a far better choice than Windows for a coder.
  5. Linux has a powerful command line, which Windows lacks. (Mac’s command line is okay though.)
  6. Package managers make it easy to install and remove software without leftover files like you get on Windows and Mac. This saves space on your hard drive and keeps your programs working well.
  7. Linux is easy to use and customize! You CAN learn to use Linux without touching the command line (although you’d be missing out on a feature, and if you’re coding you should know it). The basic controls aren’t that different from any other operating system–it just has a few extra tricks it can do.
  8. Linux is becoming a platform for gaming! It’s not totally there yet, but there’s serious progress being made. Steam has certainly jumped on this bandwagon with Steam OS. Personally, Humble Bundle is my favorite place to find Linux games, and it’s for a good cause. And remember what I said about Linux being faster? Your games will perform better. It’s pretty awesome.
  9. Free software–you don’t have to pay for Microsoft Word or Photoshop, as Linux has open-source software that does the same thing. LibreOffice and GIMP are great programs.
  10. It’ll teach you about how computers work! Linux is a great behind-the-scenes of how computers function. To me, that’s really important and cool.
  11. Free support from a great community. Got a question? Google it, and if you can’t find anything to help you, there are forums full of people who’ll help you out for kicks–they just like fixing stuff and making users happy because it’s challenging.
  12. The power to fix your computer when it breaks. Windows doesn’t let you see where stuff is failing, it just pops up with the box that says it’s trying to diagnose the problem and fix it–and I’ve never heard of that working for anyone. Linux lets you see what’s going wrong, if you know where to look, and lets you fix it instead of making you give up. Linux boxes don’t really get the kind of issues that can be solved by rebooting–they work too well for that–but they do occasionally run into bigger blocks where Windows would just throw up its hands and tell you to reinstall.

I’m stopping there. Twelve is a nice round number, and I don’t want this to go on forever.

Q: How do I learn Linux?

A: This is actually a really good question. I was asking the same thing about a year ago. Now that I know from experience, I’ve covered it to send you in the right direction.

II. Questions about coding

Q: How do I start learning to code?

A: Starting to code is easy! There are great sites out there to help people take the first step into programming–I like codecademy–and there are plenty of books too–like this one, which is available for free (although I suggest buying a hard copy or tipping the author if you can). If you’re intimidated, you can start with HTML and CSS and make some basic web pages, in which case I recommend this book.

Q: I’ve been coding for a while… I know a language or two, but I feel like I’m missing something. Open source is really hard to get into and everything is confusing.

A: Basically everyone feels like this after working with books and classes and tutorials for a while. It doesn’t go away with more books and classes and tutorials. It starts to go away once you try to build stuff on your own. Keep your eyes peeled for stuff you think you might be able to build, and then try to build those things. Even if they’re terrible at first. Trust your ability to learn what you don’t need in order to finish your projects.

You’ll feel stupid. You’ll think your program sucks. You’ll get frustrated working on a problem and walk away. But then you’ll figure out something that might be the answer while you’re making dinner and you’ll rush back, and you’ll put it in, and maybe it won’t work but sometimes it does and sometimes it helps you figure out what works, and everything is exciting again. And you’ll forget you were making dinner, and you’ll keep coding and forget to eat at all while your cat eats the lunch meat you left out.

If you love it anyway, you should keep coding.

At some point, after months spent alternating between frustration and excitement, it’ll hit you that six months ago you would have absolutely no clue about anything you’re doing now. You’ll realize that, although you may not be as good as the open-source folks yet, you do know a lot of valuable things that would massively confuse most people.

Q: Uh… really? It’s that hard? But I bought a book that says I can learn Java in a week.

A: You might be able to learn Java syntax in a week, but it’s really just another tutorial. Programming is a separate skill, agnostic of any one language but tied to all of them, and it takes time and effort and trial and error to learn. Also, don’t start with Java. Start with Python, Ruby, or web development.

Q: Is HTML a programming language?

A: No, not really. HTML is a markup language (HyperText Markup Language), and it isn’t Turing-complete. That is, it lacks the different logic structures that programming has. HTML is more just a way to tell the computer how to display stuff, and the things you write with HTML aren’t interactive. To make interactive web sites, you need to use a programming language like Python, Java, PHP, Ruby… etc. You don’t think about it, but most websites you use on a regular basis have tons of programming behind them–it’s not just HTML and CSS.

CSS isn’t a programming language, either. Same deal, I’m afraid.

One could argue that they are both coding languages, though, in that you’re using an artificial language designed for computers in order to tell computers what to do. That’s valid. One speaks of “HTML code” after all.

III. Inevitable diversions

These are here because I don’t want to spend activity time on them.

Q: Can I use Linux to be a l33t hax0r and break into computers?

A: Yeah, if you’re an idiot who can’t figure out anything more fun to do with your computer than break into someone else’s. It’s a lot more technically difficult and interesting to build things rather than destroy them, and it also pays more and doesn’t get you into legal trouble.

Also, that’s not what a hacker is. You’re thinking of crackers. Hackers are the people who build open-source stuff, and they don’t like it when you mix up their names with criminals.

Q: Will you teach me cracking?

A: No.

Q: Should I use Kali Linux as my desktop OS?

A: If you want to be a white-hat, it makes sense to know Kali and the network security tools it comes with. I wouldn’t recommend it as a desktop OS, though. A lot of people are attracted to Kali because it sounds edgy, though, and that’s not a good reason to use it. Don’t do anything stupid with Kali.

Q: Do girls code and game in their underwear?

A: Yes, but where you get it wrong is in thinking that it looks remotely attractive.

Q: What are the best energy drinks? Is Monster good?

A: I covered this, actually. And no, Monster is toxic waste–Full Throttle, NOS, or Venom are much better.

 

Design Patterns

After taking a kind of quick course in some of the finer points of OO programming, I’ve come back to the design patterns book I had my mom buy for me recently.

It’s this one:

Head First Design Patterns cover

 

(Clicking the image will take you to its Amazon page, where you can buy it for yourself if you want.)

Oh, a note before you do that, though. All the code examples are in Java, so you need to either be reasonably familiar with Java and its syntax, or with a similar language like C++ or C#. Although, quite honestly, if you’re familiar with some other OO language and clever enough to recognize patterns, I’d say you’ll probably be fine; take note that I haven’t finished the book, though.

 

I have to admit that sometimes I get bored with coding. Usually, this means one of two things:

1) I’m too stressed or burned out from working on other things, and my motivation for doing ANYTHING is next to nonexistent, let alone my motivation to work on complex intellectual activities like coding; or

2) I’ve been working on something that’s either too easy or too difficult, and I’m getting bored or frustrated, respectively.

I was getting pretty bored of working with the Python book. I found myself skimming stuff, wishing Shaw would just get to the point already… I think I’m finding that the point where you can just look at code and immediately see what it does means you have to move on, because you’re sitting in a kiddie sandbox. My 12-year-old brother will really find the book interesting, especially the simple game engine near the end, which was supposed to be one of the major final projects–but since I spent a lot of time when I was 12 fiddling around with RPG Maker XP*, my thoughts were more along the lines of, “Cute. Let’s move on.”

And it was time to move on. There’s a lot of stuff in this new book that I don’t know about, which I probably should know about before trying to get into it… but since it’s the only source where I’m finding any mention of these concepts, I’m just going to glark it from context.

Concepts like what the difference between a class and an interface is, and how the syntax for writing them is different… and then there’s this diagram system they use that I’ve never seen before… what “programming to an implementation” means… How come I’ve taken so many programming classes in OO languages, and they’ve never touched on this stuff?

Does all school work this way? You attend classes that teach you the easy half of what you need to know (or next to none of what you need, if it’s high school) until they’re satisfied enough with you to give you a fancy piece of paper, and then you go home and actually learn all your skills yourself? Mostly I’m annoyed on principle, as it’s not so much of a problem in my case–self-paced learning works really well for me–but it doesn’t for everyone, and that is super uncool.

An interesting thing I noticed myself doing while I was going through the Python book: I had read part of the first chapter of the HFDP book, and not really understood it despite trying very hard to do so, so I went back to the Python book. And as I went through it, I kept piecing together how the design pattern worked. So even though what I’d read was mostly Greek to me, having tried to understand it, it stuck in my mind anyway and I was able to use later clues to get it without even looking back at the HFDP book.

Of course, having returned to HFDP, it’s even a little clearer, although I don’t totally get everything the chapter has to say yet. Since this is a complicated book and I need to learn a lot of what’s in it from context (because I’ve never seen a lot of this stuff before and don’t know enough about it to even form questions on it), I’m doing two runs through the book. The first run, I’m just going to read it and try to understand stuff. I’m almost inevitably going to hit a point in the middle of the book where I get stuck and can’t understand anything more, and after that I’m going to skim. But I am going to go through the whole thing because, as mentioned above, stuff I don’t understand apparently sticks anyway if I wrestle with it enough. I didn’t think it would at first because it seems so complicated, but it does and the skill will develop more if I take advantage of it.

Reading HFDP is an experience. In each chapter so far, they present a problem that requires a design solution and they go through several different ways an inexperienced programmer might approach the problem, pointing out the issues and potential issues in each of them. Then they introduce their design pattern, not only coded properly but sometimes it even has extra features; not stuff that bogs down the code, but simply makes it more flexible. Objectively, but especially by comparison to the other code, the final solution is beautiful.

I don’t know if I can explain what constitutes beauty in code to my non-technical readers (if there are any? you guys must have patience). It can be achieving the best, most flexible results by the simplest, most minimal means possible even when the problem is complicated–in fact, that’s probably the most beautiful of code structures, something referred to as “elegance.” To be told your code is elegant is very high praise. Code beauty can also be achieved through ingenuity and creativity in design, although it’s still very important that the code be readable and maintainable, and most of all it should run. There are other ways for code to be beautiful, though, including code that is intentionally designed to do something ridiculous but actually manages to do it, or code that only works because of a loophole in the way the programming language itself is written (there’s a Jargon File example of this too, but I’m not sure where it is).

Head First Design Patterns’ solutions are the first kind of beautiful, which is the kind most worth committing to memory because they’re the most versatile. That’s the selling point of the book, really; that it teaches you good code structure, templates that are reusable, and then it’s your job to decide which one(s) you want and how you want to adjust it to your own needs.

Anyway, as much as I like writing and hopefully also encouraging other book-apprenticed coders and wannabe open-source junkies, I kinda want to go back to my book. I’m leaving this here for the day.

 

*If you’re not familiar with RPG Maker XP, think of it as kind of like Scratch (or, ostensibly, Alice, which I’ve never used), but more obscure and difficult to use. The map builder for the graphics part of the game is a lot like using virtual Legos. It runs Ruby, but since I didn’t know Ruby, I just used the game’s interface to generate the code line-by-line; its engine for that is closer to the code than the code-generating tools I normally get irritated with (like, you have to manage your variables yourself). I learned some programming logic from it, and a little bit of work with Photoshop for some graphics, but I never became very good at it. Nevertheless, I hammered away at the thing for hours on end, trying to recreate game versions of scenes from the fantasy novels I wrote (I was a weird kid).