What Is Hacking?
Hacking is primarily[1] a style of programming, and following the recommendations in this document can be an effective way to acquire general-purpose programming skills. This path is not guaranteed to work for everybody; it appears to work best for those who start with an above-average talent for programming and a fair degree of mental flexibility. People who successfully learn this style tend to become generalists with skills that are not strongly tied to a particular application domain or language.
Note that one can be doing hacking without being a hacker. “Hacking”, broadly speaking, is a description of a method and style; “hacker” implies that you hack, and are also attached to a particular culture or historical tradition that uses this method. Properly, “hacker” is an honorific bestowed by other hackers.
Hacking doesn't have enough formal apparatus to be a full-fledged methodology in the way the term is used in software engineering, but it does have some characteristics that tend to set it apart from other styles of programming.
- Hacking is done on open source. Today, hacking skills are the individual micro-level of what is called “open source development” at the social macro-level. [2] A programmer working in the hacking style expects and readily uses peer review of source code by others to supplement and amplify his or her individual ability.
- Hacking is lightweight and exploratory. Rigid procedures and elaborate a-priori specifications have no place in hacking; instead, the tendency is try-it-and-find-out with a rapid release tempo.
- Hacking places a high value on modularity and reuse. In the hacking style, you try hard never to write a piece of code that can only be used once. You bias towards making general tools or libraries that can be specialized into what you want by freezing some arguments/variables or supplying a context.
- Hacking favors scrap-and-rebuild over patch-and-extend. An essential part of hacking is ruthlessly throwing away code that has become overcomplicated or crufty, no matter how much time you have invested in it.
Recently it has become evident that hacking blends well with the “agile programming” style. Agile techniques such as pair programming and feature stories adapt readily to hacking and vice-versa. In part this is because the early thought leaders of agile were influenced by the open source community. But there has since been traffic in the other direction as well, with open-source projects increasingly adopting techniques such as test-driven development.
Stages of Learning How To Hack
The hacking equivalent of fingering is learning the capabilities of programming languages, and the mechanics of using tools like editors, interpreters, and compilers. (If you don't understand these terms, see The Unix and Internet Fundamentals HOWTO.) We won't cover those mechanics here as they vary too much according to what language you're using. Tutorials for all the languages you might want to use are available on the Web; use a search engine.
The equivalent of playing scales is writing small programs, alone. Unfortunately, playing scales (a) doesn't teach you anything about music, and (b) is boring as hell. Similarly, writing toy programs doesn't tend to teach you much about hacking, and (b) will tend to de-motivate you unless the program immediately solves a problem you care about.
Most formal programming instruction gets to playing scales and stops. Thus, it tends to produce coders who are poor at collaborating with each other and have the equivalent of no ear for music — a poor feel for software design and architecture.
The Incremental-Hacking Cycle
- First, pick a program that does something you are interested in.
Ideally, it should be a program you use regularly and have opinions
about. The next best thing is a program you don't normally use, but
that does something you think is interesting. For this learning
method to work, you should avoid trying to hack on code that bores
you.
The program you choose doesn't have to do anything serious. Many programmers have honed their skills by improving games that they enjoyed. The only drawback to this is that modern games are often quite large and complicated, and may be beyond the grasp of a raw beginner. For this reason, you may want to investigate one of the classic text-oriented games that still survive; nethack is a prime example, and there are many others. - If you don't already know the program, learn how to use it. Read the documentation. Develop a mental model of how it works.
- Pick a small feature to change or add.
- Search the code until you find the part you need to modify.
Note: you should specifically not try to read the entire program. You will just exhaust and frustrate yourself if you do that. Instead, use the module structure of the code to zero in on just the part you need to understand. Along the way, you will learn things about how the whole program fits together.
It's a good exercise to add explanatory comments and notes to the code as you figure out things about it. This will help your memory, and will help you organize your thoughts as well. - Make, test, debug, and document your change.
Documenting your change is important. If you develop the habit of doing this early, you'll produce much higher-quality work. - Send your change as a patch to the program maintainers. See the
Software
Release Practice HOWTO for tips on how to do this in an
effective and polite way.
I originally described this as an optional step; a wise friend pointed out that probably I shouldn't have. Solitary noodling on your instrument is all very well for practice, but music is completed and validated when the creativity in it is heard by other people. Solitary noodling on your computer is similarly good for practice, but hacking is completed when other people use what you wrote. That real-world test is important.
Sometimes (oftener when you are just starting) your patches will be rejected. You need to learn to cope with this. It doesn't mean you're doomed to fail in your quest; usually what it does mean is that you have not read the code carefully enough, or (just as usually) you have missed something important aboout the culture and practices of the developmemt group you are trying to contribute to. These mistakes can be repaired. - Now, ask yourself: do I understand this entire program?
If yes, you're done. If no, go back to step 3. This time, pick a different and perhaps slightly more difficult thing to change.
Developing Your Design Sense
When you have done the incremental-hacking cycle on several very small programs (or if you are unlucky enough to not find any suitable very small ones), try it on slightly larger programs. Look for codebases in the range of 100-500 lines.
When you master that level, go to the order of magnitude, 1000-5000 lines. By the time you master the 1K-5K level, you will have entered the bottom end of the capability range of what is usually considered a skilled programmer.
At or before the 1K-5K level, you should occasionally begin to notice that you are having itches to change the structure or organization of a program, not just its features. You may find yourself thinking “This code is ugly” and having feelings about making it prettier and cleaner.
When this happens, pay attention. This is your design sense trying to wake up. Don't rush to patch in another feature. Instead, start to explore the program that gives you this itch at a higher level. Now might be a good time to try to read all the code, but don't be too concerned if you can't; most programs are just too big and messy for gulping them down all at once to work. Just try to get a grip on what you need to know to clean things up.
You are now entering the intermediate portion of learning to hack. This involves not merely changing surface-visible features but doing what is called “refactoring” — reorganizing the code internally so that it is cleaner and has better architecture (better hiding of data, narrower interfaces between different parts, more functional separation among modules).
Once your design sense (your equivalent of musical ear) is activated, you'll often find that you start refactoring each program you work on as rapidly as the third or fourth time around the incremental-hacking cycle.
In fact, this is exactly how skilled hackers normally approach learning the code of large programs — by tinkering and refactoring and rewriting until they grok what is going on. You make small changes in order to learn how to make large ones.
If you successfully refactor three or four large systems, you will not just develop strong programming skills, you will be on your way to something much more rare and powerful: becoming a software architect, one who can do original design of large software systems.
This is the only way I know of for fledgling software architects to train their design sense. It may be the only way there is.
Being original
Before you have read and absorbed the lessons of a lot of code, you will probably not have in your head the pattern library you need to be creative on scales larger than very small ones. One purpose of doing the incremental-hacking cycle is to immerse yourself in a lot of code — at increasing complexity scales — under circumstances that provide you with motivation to keep reading.
Eventually you will lead group projects and do entirely original work. Do not feel you have to rush this or force it; if you give your skills time to mature, your first original composition will be better for it. By contributing effectively to existing open-source projects you will learn the skills (including the communications skills) that you need to run your own projects.
In computer security, a hacker is someone who focuses on security mechanisms of computer and network systems. There is a community and shared culture of expert programmers and networking wizards that traces its history back through decades to the first time-sharing minicomputers and the earliest ARPAnet experiments. The members of this culture were the first "hackers." Breaking into computers and breaking phone systems have come to symbolize hacking in popular culture, but hacking culture is much more complex and moralistic than most people know. Learn basic hacking techniques, how to think like a hacker, and how to gain respect in order to crack your way into the complex world of hacking.
Part 1
Fundamentals
-
1Run Unix. Unix is the operating system of the Internet. While you can learn to use the Internet without knowing Unix, you can't be an Internet hacker without understanding Unix. For this reason, the hacker culture today is pretty strongly Unix-centered. A Unix like Linux can run alongside Microsoft Windows on the same machine. Download Linux online or find a local Linux user group to help you with installation.[1]
- A good way to dip your toes in the water is to boot up what Linux fans call a live CD, a distribution that runs entirely off a CD without having to modify your hard disk. This is a way to get a look at the possibilities without having to do anything drastic.
- There are other operating systems besides Unix, but they're distributed in binary — you can't read the code, and you can't modify it. Trying to learn to hack on a Microsoft Windows machine or under any other closed-source system is like trying to learn to dance while wearing a body cast.
- Under Mac OS X it's possible to run Linux, but only part of the system is open source — you're likely to hit a lot of walls, and you have to be careful not to develop the bad habit of depending on Apple's proprietary code.
-
2Write HTML. If you don't know how to program, learning basic HyperText Mark-Up Language (HTML) and gradually building proficiency is essential. What you see when you look at a website of pictures, images, and design components is all coded using HTML. For a project, set out to learn how to make a basic home page and work your way up from there.
- In your browser, open the page source information to examine the HTML to see an example. Go to Web Developer > Page Source in Firefox and spend time looking at the code.
- You can write HTML in a basic word processing program like Notepad or Simple text and save your files as "text only," so you can upload them to a browser and see your work translated.[2]
- You'll need to learn to format tags and learn to think visually using them.[3] "<" is used to open a tag and "/> is used to close it. "
" is the opening for a line of paragraph code. You'll use tags to
signal anything visual: italics, formatting, color, etc. Learning HTML
will help you to understand better how the Internet works.
-
3Learn the language of programing. Before you start writing poems you have to learn basic grammar. Before you break the rules you have to learn the rules. But if your ultimate goal is to become a hacker, you're going to need more than basic English to write your masterpiece.[4]
- Python is a good "language" to start off with because it's cleanly designed, well documented, and relatively kind to beginners. Despite being a good first language, it is not just a toy; it is very powerful, flexible, and well-suited for large projects. Java is an alternative, but its value as a first programming language has been questioned.[5]
- If you get into serious programming, you will have to learn C, the core language of Unix. C++ is very closely related to C; if you know one, learning the other will not be difficult. C is very efficient with your machine's resources, but will soak up huge amounts of your time on debugging and is often avoided for that reason, unless the efficiency of your computer is especially important.
- It is probably a good idea to use a good starting platform such as Backtrack 5 R3, Kali or Ubuntu 12.04LTS.
Part 2
Hacking Attitudes
-
1Think creatively. Now that you've got the basic skills in place, you can start thinking artistically. Hackers are like artists, philosophers, and engineers all rolled up into one. They believe in freedom and mutual responsibility. The world is full of fascinating problems waiting to be solved. Hackers take a special delight in solving problems, sharpening their skills, and exercising their intelligence.
- Hackers have a diversity of interests culturally and intellectually, outside of hacking. Work as intensely as you play, and play as intensely as you work. For true hackers, the boundaries between "play," "work," "science," and "art" all tend to disappear, or to merge into a high-level creative playfulness.
- Read science fiction. Go to science fiction conventions, which is a great way to meet hackers and proto-hackers. Consider training in a martial art. The kind of mental discipline required for martial arts seems to be similar in important ways to what hackers do. The most hacker-ly martial arts are those which emphasize mental discipline, relaxed awareness, and control, rather than raw strength, athleticism, or physical toughness. Tai Chi is a good martial art for hackers.
-
2Learn to love solving problems. No problem should ever have to be solved twice. Think of it as a community in which the time of everyone is hackers is precious. Hackers believe sharing information is a moral responsibility. When you solve problems, make the information public to help everyone solve the same issue.
- You don't have to believe that you're obligated to give all your creative product away, though the hackers that do are the ones that get most respect from other hackers. It's consistent with hacker values to sell enough of it to keep you in food and rent and computers.
- Read older pieces, such as the "Jargon File" or "Hacker Manifesto" by The Mentor. They may be out of date in terms of technical issues, but the attitude and spirit are just as timely.[6]
-
3Learn to recognize and fight authority. The enemy of the hacker is boredom, drudgery, and authoritarian figures who use censorship and secrecy to strangle the freedom of information. Monotonous work keeps the hacker from hacking.
- Embracing hacking as a way of life is to reject so-called "normal" concepts of work and property, choosing instead to fight for equality and common knowledge.
-
4Be competent. So, anyone who spends time on Reddit can write up a ridiculous cyberpunk user name and pose as a hacker. But the Internet is a great equalizer, and values competence over ego and posture. Spend time working on your craft and not your image and you'll more quickly gain respect than modeling yourself on the superficial things we think of "hacking" in popular culture.
Part 3
Hacking Well
-
1Write open-source software. Write programs that other hackers think are fun or useful, and give the program sources away to the whole hacker culture to use. Hackerdom's most revered demigods are people who have written large, capable programs that met a widespread need and given them away, so that now everyone uses them.
-
2Help test and debug open-source software. Any open-source author who's thinking will tell you that good beta-testers (who know how to describe symptoms clearly, localize problems well, can tolerate bugs in a quickie release, and are willing to apply a few simple diagnostic routines) are worth their weight in rubies.
- Try to find a program under development that you're interested in and be a good beta-tester. There's a natural progression from helping test programs to helping debug them to helping modify them. You'll learn a lot this way, and generate goodwill with people who will help you later on.
-
3Publish useful information. Another good thing is to collect and filter useful and interesting information into web pages or documents like Frequently Asked Questions (FAQ) lists, and make those generally available. Maintainers of major technical FAQs get almost as much respect as open-source authors.
-
4Help keep the infrastructure working. The hacker culture (and the engineering development of the Internet, for that matter) is run by volunteers. There's a lot of necessary but unglamorous work that needs done to keep it going — administering mailing lists, moderating newsgroups, maintaining large software archive sites, developing RFCs and other technical standards. People who do this sort of thing well get a lot of respect, because everybody knows these jobs are huge time sinks and not as much fun as playing with code. Doing them shows dedication.
-
5Serve the hacker culture itself. This is not something you'll be positioned to do until you've been around for a while and become well-known for one of the four previous items. The hacker culture doesn't have leaders, exactly, but it does have culture heroes and tribal elders and historians and spokespeople. When you've been in the trenches long enough, you may grow into one of these.
- Hackers distrust blatant ego in their tribal elders, so visibly reaching for this kind of fame is dangerous. Rather than striving for it, you have to sort of position yourself so it drops in your lap, and then be modest and gracious about your status.
Comments
Post a Comment