Green leave
 
 
 
 
 
 

 

Welcome to www.naturalprogramming.com! This site provides more than 850 examples of computer programs and gives information about Kari Laitinen's programming books. Please, click the following names of programming languages to enter the homepages of  individual books

Java    C++    C#    Python

General information about the books.
A story about successful use of these books
Begin your studies using the free sample pages
Try IC8 -- a truly simple computer!

To personal homepage of Kari Laitinen.
More information (mostly for experienced people)
 
 

 © 2002-2008 Kari Laitinen
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
  Green leave
 
 
 
 
 
 

 


 
 
 
 

General information about these books 

My name is Kari Laitinen and I am a "boy" from the Finnish countryside who has ended up writing books about computer programming. The reason why I have ended up doing this work is that the programming books that I have encountered during my 20-year career have not been satisfactory to me. So, I have tried to write better and more understandable programming books.

Readability is the primary concern in the design of my books. Examples of computer programs are written without the traditional confusing abbreviations. I have developed a graphical way to present the example programs. I probably break a traditional bookmaking rule when I sometimes leave the lower part of a page empty in order to be able to present and explain a complete computer program on the following two pages.

If you are a person who is beginning the studies of computer programming, you might try my books since they do not assume any previous knowledge about the subject. Especially if you have recently started your studies about the subject, but you still feel confused about the whole concept of computer programming, my books might open you the door into the world of computers.

If you are a person who already has some experience in computer programming, my books might show you how to write better computer programs, and improve your programming skills. An experienced person might use the books selectively, so that he or she could concentrate on the examples of computer programs which are explained with special text bubbles.

At the moment I have three books about computer programming available. One presents programs written with the Java programming language. The two other books use the  C++ and C# programming languages. All these books are possible starting points for your studies, but perhaps the Java book is the best choice since it introduces a truly object-oriented programming language that can be used in many computers. Nevertheless, if you choose one of these books, it is easy to switch to other programming languages because the example programs are almost the same in all of these books. For example, if you know a program that is presented in my Java book, and you want to know how that particular program is written with the C++ language,  you can simply go to the homepage of my C++ book and you'll find a C++ version of that particular program. Similarly, you can get C# or Python versions of the programs presented in the Java book.

Please, click on the following book titles to find information about individual books.

A Natural Introduction to Computer Programming with Java

A Natural Introduction to Computer Programming with C#

A Natural Introduction to Computer Programming with C++
 
 

© 2004-2006 Kari Laitinen
 
 


 
 
 
 


 
 
 
 
 
  Green leave
 
 
 
 
 
 

 


 
 
 
 

How Mrs. Eija Vieri-Gashi ended up teaching computer programming

Mrs. Eija Vieri-Gashi is a teacher and my colleague at the Institute of Technology of Oulu Polytechnic in Finland. During many years, she has been teaching courses related to the basic phenomena of electricity and electronics. The students at our institute like Eija very much, and she was once selected the best teacher at Oulu Polytechnic.

Like me, Eija has studied at the Department of Electrical Engineering in the University of Oulu. Unlike me, she did not want to concentrate on computers and computer programming in her studies. She told me that she found computers and the programming courses rather confusing and frightening, and therefore she concentrated on other areas of electrical engineering.

When my book A Natural Introduction to Computer Programming with C++ was published in 2003, Eija decided to buy the book because she felt that she knew too little about computer programming. During that year, Eija had free time, and she started to read the book systematically from the beginning. What happened was that she started to understand things. Those confusing and frightening computers started to behave like manageable devices in her mind. What happened ultimately was that she got so excited about the subject that she wanted to start giving basic courses about computer programming. Thus we now have an excellent new teacher in this field.

I think there are many clever people who could understand how computers operate, and who could learn to write computer programs, but somehow these people are prevented from entering the "world of computers". For this reason, I have tried to write books which reveal the secrets of the computer world in a natural and easy-to-read manner. The story of Mrs. Eija Vieri-Gashi indicates that I have succeeded in this work.
 
 
 

© 2004 Kari Laitinen
 
 


 
 
 
 

 
 
 
 
 
  Green leave
 
 
 
 
 
 

 


 
 
 
 

Begin your studies with the free sample pages

Plenty of sample pages of my programming books are freely available. You can actually start your studies about computer programming by printing the free sample pages of chapters 3 and 4 of the book A Natural Introduction to Computer Programming with C#. All the pages of the mentioned chapters are available. Chapter 3 explains how computers store information in their memory, and Chapter 4 explains how computers operate as logical systems. These chapters are presented in the book before the actual studies related to the C# programming language begin. Therefore you can use these chapters even if you later decide to study some other programming language. 

For a person to learn computer programming, it is necessary to know how computers operate in principle, but is is not absolutely necessary to know all the details of computer electronics. The mentioned chapters provide the necessary information so that you can quickly learn the basics of computer technology without having to become an expert in technical details. In your studies you can use the IC8 simulator.

Note that you may print the sample pages of my books for your personal use only. As is explained on the sample pages, they may not be used for any commercial purposes.

Go to see the list of sample pages of the C# book.
 
 

© 2005 Kari Laitinen
 
 


 
 
 

 
 
 
 
 
  Green leave
 
 
 
 
 
 

 


 
 
 
 
 
 

Some "stories" for experienced programmers, educators, and people who do research related to computer programming

The idea of natural naming
How I define "natural programming"
Some words about debugging
How difficult it is to change one's programming style

Some documents to be downloaded freely
 
 
 
 

© 2005 Kari Laitinen
 
 


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 
 
 
 
 
  Green leave
 
 
 
 
 
 

 


 
 
 
 

What is natural naming?

When we write computer programs, we need to invent names (identifiers, symbols) to various program elements such as variables, constants, methods (functions), classes, arrays, object references, etc. Natural naming means that when a name is given to a program element, a name which consists of preferably several natural words is selected. This idea is a kind of opposite to the tradition according to which program elements are named with abbreviations.

A traditional abbreviated name for a variable which stores a character that is read from the keyboard might be ch. A natural version of such a name could be character_from_keyboard or characterFromKeyboard. A traditional abbreviated name for an index variable is i. This variable could be given a natural name such as character_index if an array of characters is being indexed, or event_index if an array of Event objects is being indexed.

A comprehensive discussion about natural naming can be found here.

If you want to see how programs with natural names look like, click here to find more than 850 programs that are written with natural names.

Here you can find Prolog programs written with natural names.
 
 
 

© 2005-2007 Kari Laitinen
 
 


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
  Green leave
 
 
 
 
 
 

 


 
 
 
 

The definition of "natural programming"

The name of this site www.naturalprogramming.com was selected because it happened to be free at the time when it was necessary to set up this site.  I have not previously used the term "natural programming" in my papers, but it might be defined as follows. "Natural programming" means that
  • Computer programs are written with natural names and by using uniform programming style.
  • Program writers attempt to produce working programs in a natural way, with no or little use of debugging aid.

  •  

    Some words about debugging

    Debugging usually involves using special debugging tools with which it is possible to detect errors in computer programs. Because I mentioned debugging in the above "definition" of natural programming, I must say some words about it.

    I am, at least to some extent, against the use of debuggers because it is possible that the sole existence of those tools can make programmers less careful in their work. Errors in computer programs are errors in thinking and they result from inadequate understanding of the programming language or the application domain. I think it is more natural to try to understand the programming language and the application domain well than to resort to a tool after a program has been found behaving in a strange way.

    A former colleague of mine, Mr. Ari Okkonen, once said during a software design course that we should get rid of spending time on debugging and, instead, start carefully designing programs. During that course Ari was teaching the use of a certain software design method, but in my opinion it is possible to add carefulness to programming work so that you simply carefully select informative natural names for your program. You have to spend time inventing the names but that spent time then increases your knowledge about the program you are developing.

    When I was working in Holland in 1988, I once met a Belgian colleague whose boss had forbidden the members a software development team to use debugging tools. The reason for the ban of debugging tools was that when those tools are available people tend to rely too much on those tools and hence they forget how to write "good" programs.

    At least theoretically, programs should be written so that they work as intended right after they have been written, and they compile without errors during the first compilation. This should be the aim in programming and software development work, though this goal can seldomly be reached. If one even thinks that he or she will use a debugging tool after a program has been written, the person in question has an obscure goal in his or her work. How can such a person produce well-working programs?

    I find it quite annoying that some integrated development environments have a Debug button so easily available on their toolbars. The existence of such a button on a toolbar means as if the development tool would say: "Here is this Debug button. Because you are such a stupid person that you inevitably make errors, it is better to debug your programs." Could it be that the existence of a Debug button on a toolbar is a kind of invitation to writing low-quality programs? Does the Debug button say: "Don't think too much. Just press this button when you have problems."
     
     
     
     
     
     

    © 2005 Kari Laitinen
     
     


     
     
     
     

     
     
     
     
     
      Green leave
     
     
     
     
     
     

     


     
     
     
     

    How difficult it is to change one's programming sytle

    HOW DIFFICULT IT IS TO ACCEPT NEW WAYS TO WRITE PROGRAMS?

    As I have explained in the epilogue of the C++ book, the reason why I wrote the book was that I wanted to write a programming book in which all example programs are written with natural names, names that are made of usually several natural words and not of abbrevaitions. According to my experiences, this kind of programming style forces a person to think carefully during the process of programming, and that results in better programs and less programming errors.

    I suppose that a teacher or some other professional should accept, at least to some extent, the idea of natural naming in order to use my books in his or her work.

    What I have learned during the past years is that people (inlcluding me) can be very sensitive about naming and other matters related to programming style. Programming is, at least partly, a kind of emotional process. Talented people are very proud about how they write their programs, and it can be an insult to propose some other way to do their work. Thus, if one has used abbreviations in programming for a long time, it may be difficult to accept the idea of natural naming.

    I can tell you a personal example about the difficulties that are involved in accepting new programming styles. During the spring 2002, I started to study C# programming after having almost finished my C++ book. (C#, "see sharp", is a programming language developed by Microsoft and it is like Java in many ways.) Before starting with C#, I was accustomed to the convention that class names are capitalized (e.g. Date), whereas all other names including method names begin with a lowercase letter (e.g. search_largest_integer, searchLargestInteger). When I saw that in the C# book I was reading method names are capitalized (e.g. SearchLargestInteger), I was furious. How can they do such a thing? Writing method names with an uppercase first letter is against the tradition in C, C++, Java, etc. I almost stopped studying the C# language because of this scandalous deviation from the traditional programming style. However, as time passed, the uppercase letters in method names started to look less impossible, and I found myself at least partially accustomed to this naming style.

    Based on this and other experiences, I can understand that it may be difficult to start writing character_index instead of i, command_line_parameters instead of args, bytes_from_file instead of buf, etc. When I started to use natural names in computer programs more than 15 years ago, I was very unsure whether computer programs can be written that way, and I was wondering why people do not write programs that way.

    What I can recommend is that just try to use natural names in practice. Write a small program in which you use long names, at least two words in each name! It is difficult because you have to think about how to name variables, methods, classes, etc. It is difficult because you have to spend time to find the right names. But when you think while you write a program, it is likely that you write a better program. Errors in programs are a result of not thinking enough.
     
     
     
     

    © 2005 Kari Laitinen
     
     


     
     
     
     

    This page is the Internet home of Kari Laitinen's textbooks
    about computer programming. The page also supports his other activities
    related to computer programming and software development.
    If you would like to invite Mr. Laitinen to speak at your special event,
    here are some interesting subjects.
     

    Please, click the links at the beginning of the page.

    The rest of this page may not be very well written since the
    following words exist  merely to remind me about how to
    develop this Internet site in the future.
     

    My textbooks of computer programming intend to present the best practices
    in computer programming.
    The books are suitable for self study. You can study at home with them, and
    teach yourself computer programming. The books can also be used
    in all such educational institutions where an introductory course in computer
    programming is given. The books thus work in high school level, university level,
    college level, etc..

    The books are written for people who are beginners in the field of computer programming.
    They might, though, give new ideas for  more experienced people as well.
    The books are new kind of programming  books in which many obstacles for learning
    have been eliminated through creative and non-traditional writing and book design.
     

    The textbooks are based on an excellent  programming style and a
    very careful naming style which is referred to with the term
    natural naming. This means in practice that the names used in the
    example programs are long names made of the words of a natural language.
    I use the term "name" in the books. In other books, the terms "symbol" and
    "identifier" are used to refer to names, and terms "identifier naming" and
    "symbol naming" can mean "naming". Names can also be called
    "symbolic names", and long names can be called "long identifiers" or
    "long symbols".

    Natural naming means that abbreviations are considered harmful in
    computer programs. An acronym is a special case of an abbreviation.
    Therefore, also acronyms are considered harmful. Abbreviating
    names in computer programs is thus discouraged in the book.

    I have been writing my programs with natural names for more than
    15 years. I think that naming is an important issue in computer programming,
    but not all programmers share this opinion, and, therefore, I have
    been a quite lonesome fellow with my ideas. The names in computer
    programs have, however, been growing longer during the past
    15 years, and that means that people have started to "implicitly"
    realize the importance of naming. Still, my C++ book is the first programming book
    in which all programs are written with natural names and abbreviations
    are explicitly banned. After these experiences it was quite nice
    to read the document "C# Language Specification", a freely available
    ECMA Standard number 334. That standard presents naming rules and
    it explicitly says that "do not use abbreviations in names". So it seems
    that also the Microsoft guys are now realizing something that I have been
    saying for 15 years.
     

    The terms "disabbreviation" and "disabbreviate" are related to
    replacing abbreviated names with natural names in computer programs.

    My books should be interesting for researchers who work in the fields
    of  psychology of computer programming and  human factors in software development.
    These are subfields of software engineering research.
    Even the researchers of natural languages and linguistics might be interested.
    Software documentation involves using a natural language. In my book
    natural language is used so that confusing abbreviations are left out from
    the language. My opinion is that software project (programming project) is
    a kind of linguistic process during which software developers initiate
    language development.

    My books are also books about object oriented programming although
    conventional programming is presented first. UML class diagrams are
    explained to some extent and some basics about object oriented design
    are discussed at the end of the books.

    Extreme programming is a popular term these days. My books present
    programs with extremely informative symbol names or
    extremely understandable names. I have always been a supporter of
    extremely careful program design and extreme software design.

    My approach to programming is related to literate programming. That is
    discussed more thoroughly in my doctoral thesis. My programming approach
    involves using meaningful variable names and  naming rules, and no
    special tools are needed in this approach. Literate programming involves
    using special tools. My approach could be called "Literate programming without
    the literate programming tools.

    My books respects the rules of structured programming. goto statements
    are considered harmful and  not used in the book. I even consider
    continue statement harmful, and break and return statements are used
    sparingly.

    I consider my programming books, at least to some extent, pieces
    of art. They are more like pieces of art than other programming books because
    I have designed all the pages and drawn all the program descriptions.
    The term "artistic programming" might, however, be too much ...
    The books contain some programming style guidelines ...

    The natural approach used in the books tries to make programming
    easy although the slogan "programming made easy" might be a too
    agressive term to describe the book. Programming is always a difficult task,
    but with the natural approach it can be made a less complex task.
    My books are against complexity, and for simplicity. I hope that a student
    can learn quikly with my book, and a teacher, lecturer, or a professor
    can find it pedagogically efficient.
     
     

    The following table compares the three books.
    The comments in the table cells explain how the three books and the used programming languges
    differ from each other. If a table cell does not contain any text, it means that the chapter in question
    like a corresponding chapter in the other books.
     
     
      Java C# C++
    Chapter 1
    COMPUTING: SOME CONCEPTS AND TERMINOLOGY
    hardware software operating system, main memory, mass memory, auxiliary memory devices
    source program, object program, and executable program
    application system program development
         
    Chapter 2
    FIRST LOOK AT Java/C#/C++ SOURCE PROGRAMS
    This chapter introduces a couple of computer programs, and explains how programs are compiled and executed. Some free editor programs (e.g. Notepad2, EditPad Lite, and JFE Jens' File Editor) are discussed in the books or on the internet site.
    Instructions for downloading the Java 1.5 Software Development Kit which includes a free Java compiler. Instructions for downloading the .NET Framework which includes a free C# compiler. Instructions for downloading the free Borland C++ compiler
    Chapter 3
    HOW INFORMATION IS STORED IN THE MEMORY OF COMPUTERS?
    numerical information, numbering systems,  the binary world of computer, textual information, the ASCII coding system, Unicode,
    encoding of pictures, sound, and moving pictures
         
    Chapter 4
    LOGICAL OPERATING PRINCIPLES OF COMPUTERS
    How does the main memory operate?
    computer memory, main memory,
    components of an imaginary computer, inside the imaginary processor, machine instructions
    step and state of program execution
    ICOM simulated imaginary computer, program that contains a loop, subroutine call and stack operation, program that use keyboard, memory area, and stack
    towards high-level programming
         
    Chapter 5
    VARIABLES AND OTHER BASIC ELEMENTS IN  PROGRAMS
    integral variables (int, short, long, char), keyword, name, space, and newline, floating-point variable,
    operator, assignments, numerical constant, literal constant, operand,
    formatting the output on the screen
    The format specifiers used by the printf() and String.format() methods are explained. The format specifiers of C# are explained. The input/output manipulators of C++ are explained.
    Chapter 6
    DECISIONS AND REPETITIONS: BASIC ACTIVITIES IN PROGRAMS
    making decision with keywords if and else, decisions with switch-case construct, while loop enable repetition, for loop repeat known number of times, do-while loop execute at least once, block structure of  programs,  truth values
    The new "foreach" loop of Java is explained at the end of the chapter. The foreach loop is explained at the end of the chapter.  
    Chapter 7
    ARRAYS : SETS OF SIMILAR DATA ITEMS
    declaring and creating  arrays,  referring to array elements, array positions, initialized multidimensional arrays
        In the C++ book, Chapter 7 introduces also C-style strings which are arrays of type char. The string functions strcmp, strcat, strcpy, etc., are also discussed. The string class of C++ is introduced in Chapter 15.
    Chapter 8
    STRINGS STORE SEQUENCES OF CHARACTER CODES
    In the Java and C# books, this chapter introduces the standard String and StringBuilder classes and string methods.
        In the C++ book, Chapter 8 introduces pointers. Because pointers are not used in the other languages, Chapter 8 is different in the other books.
    Chapter 9
    METHODS: LOGICAL PERFORMING UNITS IN PROGRAMS
    static methods,  concept of calling, caller, callee, method parameters (arguments), return statement, 
    role of stack in method calls,
    scope of variables, local variables, global variables, parameters for the 
    main() / Main() method,
    overloading method names
    Java does not have output paramters. This chapter is thus simpler in the Java book. The parameter modifiers out and ref are explained in this chapter. In the C++ book, the term "function" is used in place of the term "method". C++ function prototypes are explained in this chapter.
    Chapter 10
    CLASSES AND OBJECTS
    class members, fields, instance methods, constructor (and destructor), creation of objects, several constructors in a class, array of objects, stack that grows dynamically.
        In the C++ book, Chapter 10 is entitled STRUCTURES AND FILES: LARGER PIECES OF DATA, and it does not correspond to any chapter in the other books. In the other books, file accessing is discussed in Chapter 14.
    Chapter 11
    MORE ADVANCED CLASSES
    This chapter introduces some large classes and applications.
      In the C# book, this chapter introduces also properties and indexers. In the C++ book, Chapter 11 is entitled GOING CLOSER TO THE MACHINE and it thus corresponds to Chapter 16 in the other books. However, threads are not discussed in the C++ book.
    Chapter 12
    INHERITANCE AND CLASS HIERARCHIES
    base class, derived class, superclass, subclass, parent class,
    child class, polymorphism, polymorphic method, public, private, protected, abstract class,
    early binding, late binding
      In the C# book, structs are introduced at the end of Chapter 12. Chapter 12 in the C++ book corresponds to Chapter 10 in the other books.
    Chapter 13
    This chapter introduces the Object class, exception classes, and some other important classes. Boxing and unboxing are discussed as well.
    Wrapper classes Integer, Short, Byte, Double, etc. Standard structs Int32, Int16, Byte, Double, etc. Chapter 13 in the C++ book corresponds to Chapter 11 in the other books.
    Chapter 14
    STORING INFORMATION IN FILES
    text files vs. binary files, reading files, writing files, appending data to a file, standard classes available to access files
        Chapter 14 in the C++ book corresponds to Chapter 12 in the other books.
    Chapter 15
    This chapter introduces more standard classes (e.g. ArrayList class)
    Classes Calendar and GregorianCalendar. Generics are discussed shortly. C# DateTime struct Chapter 15 (STANDARD C++ CLASSES) in the C++ book corresponds "loosely" to chapters 14 and 15 in the other books.
    Chapter 16
    GOING CLOSER TO THE MACHINE
    Bit operators &, |, ^, ~. >>, and <<; getting current time and date into a program; threads
    Java has the extra bit operator >>>. In the C# book, delegates are discussed shortly as they are needed when threads are used. Chapter 16 of the C++ book is entitled LARGE OBJECT-ORIENTED APPLICATIONS and the other books do not have a chapter that would correspond to to it.
    Appendices
    The appendices are logically "equivalent" in all books.
         

    SITE MAINTENANCE NOTES:

    Where shall the latest version of index_for_ic8.html kept? At home!!!

    A story with the title "Why we always want to write programs so quickly"
    might be interesting.

    SITE HISTORY:

    Page created: June 13, 2002
    Homepage for the C# book added: February 8, 2004
    Link to the IC8 simulator was added August 25, 2004
    Sample pages from the C# book were added December 11, 2004
    Full chapters 3 and 4 from the C# book were added February 21, 2005
    The source programs of the books were made freely available on March 19, 2005
    Pages for the Java book added: March 2, 2006.
    Python programs added: May 11, 2006.
    Links to all example programs added: June 11, 2006. Those make roughly 750 programs.
    On November 12, 2006, this site contains 100 new programs in directories
    javagui, pythongtk, pythonmaemo, and javagui_in_finnish
    March 10, 2007 : THIS PAGE MUST BE UPDATED WITH NOTEPAD2!!!!
    2008-05-02 IC8 v1.1 is now available
    Last modification: 2008-05-02 with NOTEPAD2

     
     
     
    tontit.html