简明现代魔法 -> 互联网时代 -> 如何自学编程

如何自学编程

2010-03-20

You've always wanted to learn how to build software yourself—or just whip up an occasional script—but never knew where to start. Luckily, the web is full of free resources that can turn you into a programmer in no time.

你也许曾经想过要学习如何开发软件或只是想临时的写出一个脚本但不知道如何入手。 幸运的是,现在的互联网上到处都有丰富的学习资源让你能在短时间里成为一个程序员。

Since the invention of the internet, programmers have been using it to discuss software development techniques, publish tutorials, and share code samples for others to learn from and use online. If you're curious about how to become a programmer, you can get off to a running start using tons of great free web-based tutorials and resources.

因为互联网的出现,使程序员们可以通过它讨论软件开发技术,发布学习指导,以及共享代码实例让其他人可以在线学习。 如果你感兴趣如何才能成为一个程序员,从网上这些大量的优秀的培训资料、学习向导入手将会是个不错的开始。

First Things First: Don't Get Hung Up on Choosing a Language 首要之首:不要急于选择一种语言

A common pitfall for beginners is getting stuck figuring out which programming language is best to learn first. There are a lot of opinions out there, but there's no one "best" language. Here's the thing: In the end, language doesn't matter THAT much. Understanding data and control structures and design patterns does matter very much. Every language—even a simple scripting language—will have elements that you'll use in other languages as well and will help you learn. In classes I took to get my degree in Computer Science, I programmed in Pascal, Assembly, and C—languages I never actually got paid to program in professionally. I taught myself every language I've used in my career, reusing concepts I already knew, and referring to documentation and books to learn its syntax. So, don't get hung up on what language to learn first. Pick the kind of development you want to do, and just get started using one that works.

新手们有一个常见的错误就是犹豫于判断哪种编程语言是最好的、最该先学的。 我们有很多的选择,但你不能说哪种语言最好。 我们应该理解:说到底,什么语言并不重要。 重要的是理解数据结构、控制逻辑和设计模式。任何一种语言甚至一种简单的脚本语言都会具有所有编程语言都共有的各种特征,也就是说各种语言是相通的。 我正在攻读我的计算机学学位,我编程使用Pascal,汇编和C语言,事实上我从来没有把它当成职业以求获得回报。 我一直在自学编程,工作上用不到它,我使用现有的知识,参考各种文档和书本,学习它们的用法。 因此,不要急于选择何种编程语言。 找出你想要开发的东西,使用一种能够完成这项任务的语言,这就可以了。

There are several different kinds of software development you can do for various platforms, from the web to your desktop to your smartphone to a command line. In this article, we'll outline some of our favorite starter tutorials and resources for teaching yourself how to program for each major platform. We're going to assume you're a savvy user, but a newb when it comes to wrangling code snippets, so we'll keep things at the beginner level. Even just following through a beginner programming tutorial, you'll be happy to see how far you can get.

根据各种开发平台的不同,有很多不同的软件开发形式可供你选择:从网站应用到桌面软件到智能手机软件到命令行脚本工具。 这篇文章里,我将重点介绍一些很受欢迎的入门教程和资源,它们能帮助你学会如何在各种主流的平台上编程开发。 我先假设你是一个悟性很强的读者,但对于新手,当我谈论程序代码时还是要按照入门级的水平。 因为即使是你自己看一篇编程入门手册,如果发现都能理解时,心情自然会很高兴,这样利于你进一步学习。

Desktop Scripting 桌面脚本

The easiest way to try your hand at programming for your Windows or Mac desktop is to start with a scripting or macro program like AutoHotkey (for Windows) or Automator (for Mac). Right now hardcore coders throughout the Lifehacker readership are yelling at their monitors, saying that AHK or AppleScript are not "real" programming. That may be true—technically these types of tools just do high-level scripting. But for those new to programming who just want to get their feet wet, automating actions on their desktop, these free tools are a fantastic way to start—and you'd be surprised at how much you can do with them.

想要动手在Windows里或苹果系统里编程,最简单的方法是从一种脚本语言或宏语言开始,例如AutoHotkey (Windows) 或 Automator (苹果系统)。如今一些硬件程序员冲着他们的屏幕大喊大叫,说AHK和AppleScript并不是真正的编程语言。也许他们说的是对的,技术上,这些种类的语言只能做一些上层的编程。但是对于那些只是想来脱盲、想在他们的电脑里实现一些能自动运行的程序的新手来说,这些语言会是一个绝妙的入门入口,而且你会吃惊于它们丰富的功能。

For example, Adam developed the standalone Windows application we all know and love, Texter, using AutoHotkey, so this scripting language is capable of far more than just small-scale automation projects. To get started with AutoHotkey, check out Adam's tutorial on how to turn any action into a keyboard shortcut using AutoHotkey. (Then, check out the source code for Texter to see the innards of a full-fledged AHK-based Windows application.)

例如,大家都喜爱的Texter就是Adam使用AutoHotkey开发的能独立运行的Windows应用程序,所以说这种脚本语言远不是只能开发小规模脚本软件。如果你想从AutoHotkey入手,可以参考Adam的指导: how to turn any action into a keyboard shortcut using AutoHotkey(然后,你可以下载Texter源代码,看看这个功能齐全的使用AHK开发的Windows应用程序的内部结构)。

Web Development Web开发

Instead of being bound to specific programming languages and the look and feel of a particular operating system, you can put your killer application in the browser and run it in the cloud, as a webapp. Welcome to the wonderful world of web development.

除了把自己约束在特定的编程语言和特定的操作系统上,你还可以在浏览器里开发你的杀手锏程序,让它在互联网上运行,这就是WebApp。 欢迎来到奇妙的web编程世界。

HTML and CSS: The first thing you need to know to build any web site is HTML (the page markup that makes up web pages) and CSS (the style information that makes that markup look pretty). HTML and CSS are not true programming languages—they're just page structure and style information. However, you should be able to author simple HTML and CSS by hand before you begin building web applications, because a web page is the frontend to every webapp. This HTML tutorial is a good place to start.

HTML 和 CSS:开发网站,你第一件要知道的事情就是HTML(网页就是由它组成的)和CSS(一种让外观更好看的样式标记)。HTML和CSS并不是编程语言它们只是页面的结构和样式信息。 然而,在开始开发Web应用程序之前你必须要学会如何手工的编写简单的HTML和CSS,Web页面是任何WebApp的前端显示部分。 这个HTML指导是你入手的好地方。

JavaScript: Now that you can lay out a static web page with HTML and CSS, things get fun—because it's time to learn JavaScript. JavaScript is the programming language of the web browser, the magic that makes dynamic in-page effects go. JavaScript is also the stuff of bookmarklets, Greasemonkey user scripts, and Ajax, so it's the key to making all sorts of web goodies. Start learning JavaScript here.

JavaScript:当你可以通过HTML和CSS构建一个静态页面后,事情就开始变得有趣了,因为到了该学JavaScript的时候了。 JavaScript是一种Web浏览器上的编程语言,它的魔力就是能在页面里制造一些动态效果。 JavaScript可以做bookmarklets, Greasemonkey脚本和 Ajax,所以它是Web上各种好东西的关于因素。学习JavaScript从这里开始。

Server-side scripting: Once you're good at making things happen inside a web page, you're going to need to put some dynamic server action behind it—and for that, you'll need to move into a server-side scripting language, like PHP, Python, Perl, or Ruby. For example, to make a web-based contact form that sends an email somewhere based on what a user entered, a server-side script is required. Scripting languages like PHP can talk to a database on your web server as well, so if you want to make a site where users can log in and store information, that's the way to go. Excellent web development site Webmonkey is full of tutorials for various web programming languages. See their PHP Tutorial for Beginners. When you're ready, check out how to use PHP to talk to a database in WebMonkey's PHP and MySQL tutorial. PHP's online documentation and function reference is the best on the web. Each entry (like this one on the strlen function) includes user comments at the bottom which are often as helpful as the documentation itself. (I happen to be partial to PHP, but there are plenty of other server-side scripting languages you might decide to go with instead.)

服务器端脚本:一旦你学会了网页里的知识,你就要开始对它添加一些动态服务器操作,为了实现这些,你需要把目光转移到服务器端脚本语言,例如PHP, Python, Perl, 或 Ruby。 举个例子,如果想要制作一个网页形式的联系方式表单,根据用户的输入发送邮件,你就需要使用服务器端脚本来实现。像PHP这样的脚本语言可以让你跟Web服务器上的数据库进行沟通,所以如果你想搭建一个用户可以登录注册的网站,这样的语言正是你需要的。 Webmonkey是一个优秀的Web开发资源网站,里面有大量的各种Web编程语言的指导手册。阅读一下他们的PHP初学者指南。当你感觉差不多了的时候,看看WebMonkeys PHP and MySQL tutorial,学习如何使用PHP跟数据库交互。网上最好的要数PHP语言官方的在线文档和函数参考了。 每个知识点上 (例如strlen function这个)都在后面列出来用户的评论注释,这些对于文档的本身是非常有价值的。 (我很喜欢PHP,但还有很多其他种服务器端的脚本语言你们都可以选择。)

Web frameworks: Over the years, web developers have had to solve and resolve the same problems and rewrite similar code to build dynamic web sites. To avoid making everyone reinvent the wheel for every new web development project, some programmers have come up with development frameworks that do some repetitive work for you. The popular Ruby on Rails framework, for example, takes the Ruby programming language and offers a web-specific structure for getting common web application tasks done. In fact, Adam used Rails to build his first serious (and impressive!) web application, MixTape.me. Here's his take on how to build a web site from scratch with no experience. Other popular web development frameworks include CakePHP (for PHP programmers), Django (for Python programmers), and jQuery (for JavaScript).

Web框架:过去数年里,Web开发人员在开发动态网站的过程中不得不一遍又一遍的针对重复遇到的问题写出重复的代码。为了避免这种每次开发一些新网站都会重复劳动一次的问题,一些程序员动手搭建了一些框架,让框架替我们完成重复性的工作。非常流行的 Ruby on Rails 框架,作为一个例子,它利用Ruby编程语言,为我们提供了一个专门面向Web的架构,普通的Web应用程序都能使用它来完成。事实上,Adam使用Rails开发了他的第一个正式的(而且是叹为观止的!)Web应用程序,MixTape.me。这就是他的如何在没有任何经验的情况下搭建一个网站。还有一些其他的Web开发框架包括 CakePHP (针对 PHP 编程者),Django (针对 Python 编程中),以及 jQuery (针对 JavaScript)。

Web APIs: An API (Application programming interface) is a programmatic way for different pieces of software to talk to one another. For example, if you want to put a dynamic map on your web site, you want to use a Google Map instead of building your own custom map. The Google Maps API makes it easy to programmatically include a map in a page with JavaScript. Almost every modern web service you know and love has an API that lets you include data and widgets from it in your application, like Twitter, Facebook, Google Docs, Google Maps, and the list goes on. Integrating other webapps into your web application via API's is the final frontier of rich web development. Every good, major web service API offers thorough documentation and some sort of quick start guide to try it out (here's Twitter's, for example). Go crazy.

Web APIs:API (应用层序编程接口) 是指不同的软件之间相互交换的程序途径。例如,如果你想在你的网站上放一个动态的地图,你可以使用Google Map,而不需要开发自己的地图。The Google Maps API 可以轻松的让你通过JavaScript在程序中引入一个地图到你的页面上。几乎所有的现代的你所知道和喜爱的Web服务都提供了API,通过这些API你可以获取到他们的数据和小工具,在你的应用程序里就可以使用这些交互过来的东西了,例如Twitter, Facebook, Google Docs, Google Maps, 这个列表远不止这些。 通过API把其他Web应用集成到你的Web应用里是现在富Web开发的前沿地带。 每个优秀的主流的Web服务API都附带有完整的文档和一些快速入手的指导(例如,这个就是 Twitter的)。 疯狂吧。

Command Line Scripting 命令行脚本

If you want to write a program that takes textual or file input and outputs something useful, the command line is the right place to do it. While the command line isn't as sexy or good-looking as a webapp or desktop app, for rapid development of quick scripts that automate processes, you can't beat it.

如果你想开发一个程序,让它读取文字或文件、输入输出一些有用的东西,那么,命令行脚本语言将是个不错的选择。 然而它并不像Web应用程序和桌面应用程序那样有吸引力和好看的外观,但是作为快速开发的脚本语言,你却不能忽视它们。

Several scripting languages that work on a Linux-based web server also work at the command line, like Perl, Python, and PHP—so learning one of those baddies makes you conversant in two contexts. My path never took me too far down the Perl road, but I taught myself Python using the excellent and free online book, Dive into Python.

很多的在Linux平台上运行的Web脚本同样能以命令行模式运行,例如Perl,Python和PHP,所以如果你学会了使用它们,你将能在两种环境中使用它们。我的学习道路一直没离开Perll太远,我自学Python使用的是这本优秀的在线免费书Dive into Python。

If becoming a Unix ninja is one of your programmer goals, you absolutely must get good at shell scripting with bash. Bash is the command line scripting language of a *nix environment, and it can do everything from help you set up automated backups of your database and files to building out a full-fledged application with user interaction. Without any experience writing bash scripts beyond a dozen lines, I wound up developing a full-on personal to-do list manager in bash, Todo.txt CLI.

如果成为一个Unix高手也是你学习的目标,那么你绝对要精通bash这个脚本语言。Bash是Unix和Linux环境下的一种命令行脚本语言,它能够为你做所有的事情:从自动备份数据库脚本到功能齐全的用户交互程序。起初我没有任何使用bash脚本的经验,但最终我用bash开发了一个全功能的个人代办任务管理器: Todo.txt CLI。

Add-ons 插件(Add-ons)

Nowadays, modern webapps and browsers are extensible with with bits of software that bolt onto them and add features. Add-on development is gaining in popularity as more developers look at existing software, like Firefox or WordPress, and think "But if only it could do THIS..."

如今的Web应用程序和浏览器都可以通过一些扩展软件来丰富自己的功能。由于一些现有的软件,例如Firefox、WordPress越来越受到开发人员的关注,插件的开发也日益流行,人们都在说“But if only it could do THIS…”。

You can do a whole lot in any web browser with just a mastery of HTML, JavaScript, and CSS. Bookmarklets, Greasemonkey user scripts, and Stylish user styles are created with the same bits of code that make regular web pages, so they're worth learning even if you just want to tweak an existing site with a small snippet of code.

只要你掌握了HTML,JavaScript和CSS,你就可以在任何的浏览器里开发你想要的很多东西。Bookmarklets, Greasemonkey user scripts 和 Stylish user styles这些软件都是用的更普通页面一样的语言写成的,这几个东西都值得你去研究一些。

More advanced browser add-ons, like Firefox extensions, let you do more. Developing Firefox extensions, for example, requires that you're conversant in JavaScript and XML (markup that's similar to HTML, but way more strict in format). Back in 2007 I ran down how to build a Firefox extension, a skill I picked up after I stumbled upon a free tutorial.

更高级的浏览器扩展程序,例如Firefox的扩展,它们可以帮助你很多。开发Firefox的扩展,举个例子,需要你精通JavaScript和XML(一种标记语言,类似HTML,但具有更严格的格式)。早在2007年我就写下来 how to build a Firefox extension,这是我在笨手笨脚的研究网上的一些学习资料后获得的成果。

Many free and well-loved web applications offer an extension framework as well, like WordPress and MediaWiki. Both of those apps are written in PHP, so comfort with PHP is a prerequisite for getting started. Here's how to write a plug-in for WordPress. Developers who want to ride the cutting edge of Google Wave can get started writing gadgets and bots in HTML, JavaScript, Java, and Python. I wrote my first Wave bot following this quick start tutorial in one afternoon.

很多免费的、受欢迎的Web应用程序都提供了扩展框架,例如WordPress 和 MediaWiki。这些应用程序都是用PHP写成的,所以只有对PHP熟悉你才能做这些事情。这个就是 如何编写WordPress插件。 而想驾驭Google Wave前沿技术的开发人员可以从使用HTML, JavaScript, Java 和 Python 写小组件和小工具开始。我写的第一个Wave bot是跟着这个一个下午时间的快速入门指导开始的。

开发桌面上的Web应用程序 Web Development for the Desktop

The best part about getting started programming in one context is when you can take those skills and apply them elsewhere. Learning web development first is a great way to start because now there are ways to put those skills to work on desktop applications, too. For example, Adobe AIR is a cross-platform run-time environment that lets you build your app once and release it to run on the desktop for every operating system AIR runs on. AIR apps are written in HTML, Flash, or Flex, so it lets you apply your web development skills in a desktop context. AIR is a great option for deploying desktop apps like one of our top 10 apps worth installing Adobe AIR for.

学习编程最好的结果是你在一个环境下学的东西可以应用到另外的环境中。先学习开发Web应用程序的好处就是我们有一些方法可以让Web应用程序直接在桌面上运行。例如, Adobe AIR 是一个跨平台的即时运行平台,它能让你编写的程序运行在任何装有AIR的操作系统的桌面上。AIR应用程序都是由HTML, Flash 或 Flex 写成的,所以它能让你的Web程序在桌面环境中运行。AIR是开发部署桌面应用程序的一个优秀的选择,就像我们提到过的 10个让你值得去安装AIR的应用程序。

移动应用开发 Mobile App Development

Mobile applications like the ones you run on your iPhone or Android smartphone are all the rage right now, so you may have dreams of striking it rich in the iTunes App Store with the next killer app. However, for the new coder, diving headfirst into mobile development can be a rough learning curve, since it requires comfort with advanced programming languages like Java and Objective C. However, it's worth checking out what iPhone and Android development looks like. Check out this simple iPhone application development example to get a taste of what iPhone developers do. Android apps are written in Java。

能在iPhone或者Android智能手机上运行的手机应用程序的开发如今正呈现井喷之势,所以你也可以梦想一下如何在iTunes应用商店里通过你的天才程序大赚一笔 但是,作为一个编码新手,直接奔向移动开发所经历的学习曲线可能会很陡,因为它需要你熟悉高级的编程语言,例如Java和Objective C。然而,你当然应该看看 iPhone 和 Android 编程究竟是什么样子的。阅读这个 简单的iPhone应用开发例子 可以初步认识一下iPhone程序的开发过程。Android 程序都是由Java写成的。

耐心,刻苦,尝试,失败 Patience, Elbow Grease, Trial and Error

Good coders are a special breed of persistent problem-solvers who are addicted to the small victories that come along a long path of trial and error. Learning how to program is very rewarding, but it can also be a frustrating and solitary experience. If you can, get a buddy to work with you along the way. Getting really good at programming, like anything else, is a matter of sticking with it, trying things out, and getting experience as you go.

好的程序员都有一个不达目的誓不罢休的品质,他们会惊喜于通过长期推敲和失败换来的一点成绩。学会编程会有很好的回报的,但是学习的过程可能会是饱受挫折和孤独的。如果有可能,最好找个伴一起陪你做这件事。想精通编程,这和其他事情一样,需要坚持,反复尝试,获得更多的经验。

This article is just one self-taught programmer's top-of-mind recommendations for beginners. Experienced programmers: What did I miss? No matter your skill level, add your thoughts and recommendations for beginners to the comments.

这篇文章里的内容就是对那些想通过自我研究达到学会编程目的的新手们的一些重要建议。 编程老手们:我有什么遗漏吗? 不论你的水平如何,请留下你的想法。

英文原文:Programmer 101: Teach Yourself How to Code

随机文章推荐
网站分类


注:如需转载本文,请注明出处(原文链接),谢谢。更多精彩内容,请进入简明现代魔法首页。

进入新博客
喜欢本文,就分享它吧
给我留言
您的名字:
您的邮件:
您的网站:


 

copyright © 2009 简明现代魔法    学习、分享、进步

power by Gonn 感谢所有关心和支持本站的朋友们