Home > Articles > Programming

Advice for New Programmers: Choose Your First Language Wisely

David Chisnall, who works on programming language design and implementation at the University of Cambridge, provides two tips for new programmers: choose your first language carefully, and take the time to learn the underlying theory behind it.
Like this article? We recommend

I learned to program when I was 7, on a BBC Model B with a dialect of BASIC and two dialects of Logo installed. The most important thing for me when I was starting was to find something interesting to work on. It's hard to be motivated to learn to do anything without some reason. I was taught to write some simple games (guess the number) and then learned about simple drawing and wrote small graphical games. Back then, the difference in quality between what I could create and commercial games wasn't too huge: most commercial games were written by one or two people and the limitations of the machine were such that you didn't get significantly more complexity by adding more people.

There are a few potential pitfalls when you're learning to program on your own. In particular, it's very easy to pick up bad habits, and the more that you practice them the worse they get. This is most apparent if you try learning a language that is designed for industrial use first, rather than one designed for teaching. This is part of the reason why I advocate trying lots of different programming languages. Languages like Python make terrible first languages. Anything that describes itself as "multi-paradigm" generally means that it badly implements a lot of possible programming models.

If you want to learn object-oriented programming (and you almost certainly do), then the best place to start is Smalltalk. This, in a system like Squeak or Pharo, gives you an environment where you can inspect everything and where everything is an object. The language is simple enough that it takes half an hour or so to learn, but the time you spend trying it will teach you to write good object-oriented code in any language, even if you never touch Smalltalk again. In contrast, learning a language like Java or C++ first will give you a myriad of bad habits that are very hard to break.

I'd also strongly recommend learning an assembly language, or at the very least a low-level language like C. Again, you don't have to ever use them later, but understanding how high-level constructs map to something that the computer can execute is incredibly valuable.

Understanding the Underlying Theory of Languages

BBC BASIC was not a bad first language, in spite of the overwhelming prejudice against BASIC. It included an inline assembler, so you could get a feel for exactly how things executed on the 6502 processor in the machine, and let you directly manipulate memory via PEEK and POKE, typically for interacting with memory-mapped I/O. Unlike many contemporary dialects of BASIC, it supported structured programming, via subroutines.

I probably wouldn't recommend the BBC micro to new programmers today, because the sparsity of the development environment would be intimidating, but it's worth remembering that the first language that you learn almost certainly won't be the one that you use for real projects later. If it is, you're probably doing something badly wrong, because you won't ever fully understand the limitations of one language until you've learned a few more. There's a small chance that after learning a dozen languages you find the first one you learned was the best for everything that you need to do, but it's quite unlikely.

One trap that self-taught programmers often fall into is neglecting the importance of the underlying theory. I began learning to program when I was 7, and when I arrived at university I was pretty sure that I already knew all of the programming-related parts of the course. It turned out that my lack of knowledge of graph theory and complexity theory was a serious limitation.

In general, the first year of a computer science program tries to teach you two fundamental concepts. If you understand these two ideas well, then you should have no problem with the rest of the course. If you don't, then you'll struggle. These concepts are induction (recursion) and indirection (pointers).

Induction

Induction is the idea that you can define an infinite series by defining a few simple cases and defining a rule that allows you to reduce a complex sequence to a simpler one. For example, you can define multiplication in terms of addition as:

1) n × 0 = 0
2) n × 1 = n
3) n × m = n × (m - 1) + n

If you then want to evaluate 5 × 3, then you look for the first matching rule. It's the third, one, which gives: 5 × (3-1) + 5, or 5 × 2 + 5. Apply it again to that and you get 5 × (2-1) + 5 + 5, or 5 × 1 + 10. Now, the second rule applies and so the 5 × 1 part becomes 5, and so the result is 15.

This is very powerful, because it's simple pattern matching and then applying rules: something that the computer is very good at. You could implement this in a programming language as something like:

int mult(int x, int y)
{
  if (y == 0)
     return 0;
  if (y == 1)
     return x;
  return mult(x, y-1) + x;
}

Multiplication is a pretty trivial example: most computers have hardware for doing multiplication, and it's a lot faster than using this approach, but for more complex things, if you can understand the problem in terms of induction then you can implement it in terms of recursion. This is one of the reason why most universities teach Prolog to undergraduates: you can't write even simple programs in Prolog unless you understand induction, and once you understand induction you've got a very powerful tool to reason with.

Indirection

The other core concept, indirection, is fundamental to building complex data structures. It's simply the idea that a variable, rather than containing a value, can tell you where to look for a value. In a computer, your data is stored in memory and so a variable name is just a human representation of the address of something in the computer's memory. A pointer is just the address of another bit of memory, stored in memory.

Languages like C allow arbitrary levels of indirection, so you can have pointers to pointers to pointers and so on. To the computer, it's nothing special. Most computers don't distinguish between data and addresses (which has been the source of myriad security vulnerabilities over the years, but that's another story), so you can store an address anywhere you can store data. The computer just loads the value and, if you treat it as an address rather than data, and loads the value from that address.

Some IBM mainframes tried to optimise for this by having special values that, when you loaded them, would actually load the result. This caused some problems when people created circular sequences of these values, causing the computer to loop forever trying to find the result that wasn't just another pointer.

Ignore Theory at Your Own Risk

Pointers are one of those things that are hard to explain, because once you understand them you wonder how you (or anyone else) ever found them complicated, but they're one of the core building blocks of programs. One of the problems with using languages like Java or Python for teaching is that students only learn about references, which are a somewhat reduced version of a pointer, lacking the generality in the interests of ease of use. While Java references are easier to use correctly than C pointers, they're slightly harder to understand, because now you have some things that can have references to them (objects) and lots of other things that can't (references, integers, floating point values), and no obvious reason why not. In contrast, C lets you use the full expressiveness of the underlying machine, even if you then use that to shoot your own feet off.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020