Introduction to Programming – Part 1: Fundamentals of Programming
It is often difficult for the beginner to get started in programming or better in the entire process of software development. Questions about choosing the right programming language or which development environment is best suited to answer. In a multi-part series, we present a comprehensive introductory course in software development, focusing on the actual programming, IE the implementation. Also read other good post for development guidelines from our partners.
Every beginning is hard! In fact, this statement also applies conditionally to the entry into professional software development. In a comprehensive article series (see box “series of articles”) we present an introduction to software development for the discerning reader. We are thus explicitly addressing beginners who have not yet gained comprehensive knowledge in the programming (implementation) of software.
For example, our target group includes students of computer science at the beginning of their studies or related disciplines who would like to acquire practical knowledge in program development. The interested autodidact will also find a compact entry here. The focus of the essays is clearly on the implementation.
When considering this technical discipline, it is not neglected that the actual programming represents only a partial step of the entire development cycle (Fig. 1). We will point this out in the appropriate places and name sources for deeper entry.
Introduction to programming – the series
The goal of any software development process is to provide programs. At the same time it does not matter fundamentally on which system such a computer program should run. In addition to the classic programs for the desktop, applications for so-called mobile devices (smartphones, tablets) are increasingly playing a role today.
To develop computer programs one uses a programming language. Starting point is always a problem of the real world. For example, calculations should be carried out or the data of the customers should be systematically managed. Even computer games fall into this category. The problem has to be analyzed and made accessible to a solution. For this algorithms are used. An algorithm is defined as follows : “An algorithm is a detailed and explicit rule for the gradual solution of the problem”.
The Following Properties Apply:
- The algorithm is executed in individual steps
- Each step involves just a simple basic action
- It must be clear at each point in time which step is to be performed next
Then the problem is written in a programming language. One speaks also of the source code (source program, source code). Programming languages are more or less aligned to the needs of the problem and thus allow a problem-oriented formulation of the solution. From the computer technology is largely abstracted.
The computer itself understands only the machine language (a sequence of 0 and 1). Between source program and machine program the translation takes place. This process is done by the compiler. Ultimately, the entire process of programming can also be understood in analogy to the communication process between people. For example, as a grown-up, a very complex situation of the real world is explained in a child-friendly manner, only with the help of the child’s vocabulary
This question can only be answered conditionally. First of all, there are no ideal programming languages suitable for all purposes. In principle, the individual languages can be classified in terms of the concepts they support.
Depending on the problem, one or the other language is better, it is supported by the selected operating system more comprehensive, or the tools available for this purpose (development environments) are particularly powerful. The historical development of programming languages also plays a major role to this day. Some languages have become universally established and have a wide range of concepts, other languages have responded to recent developments and deliberately broken with “legacies”.
And which language do we choose now? No matter … not quite! In order to make the start of program development as easy as possible, one should choose a universal language with good tool support, a variety of applications and sufficient dissemination. Modern concepts should also be supported.
Once you have understood the basics of a language, it is relatively easy to learn a second or third programming language. There are always many things in common. Over time, you will see the differences as an opportunity to select your favorite for the current problem. Ultimately, it also remains a matter of taste. We chose C #. The reasons are:
- It is a modern language, with potential for different application types (desktop, app, web)
- It is based on the powerful .NET framework, which is now considered the standard for the development of Windows applications
- The language is relatively easy to learn, the complexity of C and C ++ has been left out
- It offers the best possible support through the integrated development environment Visual Studio
- Availability of diverse information (textbooks, Internet, community)
- Compilers and tools for getting started are freely available
The efficiency of the program creation is significantly defined by the quality of the available development environment. .NET applications and C # use Visual Studio. Visual Studio Community – currently in version 2013 – is available for a professional start. The download takes place via the website, the installation is no different from a conventional application program.
A First Program
Let’s start with a first test. We create a Windows application. You’ll see, it’s pretty easy. The motivating effect should be that with the help of the integrated development environment Visual Studio the frame code is created for a complete application in a few simple steps. Let’s start immediately:
- Start of Visual Studio 2013.
- We call the assistant for a new project via the menu item File
- From the templates we offer, we choose Visual C # | Windows Dektop and immediately the first entry Windows Forms application.
- In the lower part of the dialog, enter the project name and location. It makes sense to create your own folder in any case.
- Click on the OK button to create the project. After a few moments, this process is complete, and you end up in the draft mode of the only form of future application
- A first start is now no longer in the way. To do this, click Start directly in the Visual Studio toolbar. The application will be executed immediately. Of course, only an empty window is displayed, but it already fulfills all the typical features of a Windows application: You can move, minimize, maximize or close the window. The system menu is also available.
Now let’s expand our first application. To demonstrate basic aspects, we’ll add some text boxes to the interface. You can later enter numbers in these text boxes that allow us to do simple calculations and return the result to another text box. The following steps are necessary:
A First Analysis
This section briefly reviews the source code in Listing 1: Lines 1 through 9 contain using statements (for example, using System). This will load libraries needed for programming. By default, Visual Studio has already made some useful suggestions. First, no further adjustments are necessary here. Each statement must be completed with a semicolon.
Line 11: Each program code must be assigned to an area. These areas are called namespace. As the projects become more extensive, the namespaces serve to structure the source code later. Again, Visual Studio is already making a suggestion. Such areas are enclosed in curly brackets (line 12 and line 32).
Other contiguous areas must also be enclosed in curly brackets. In this case, areas are to be nested.
Line 13: C # is an object-oriented language, i. H. all instructions must be within classes (the class concept is detailed in Part 3). Basically, the form is also a class named Form1. All classes belong to a specific type (here of the form type).
The class Form1 includes u. a. the event-handling method button_Click (line 20 through line 30). Of importance now are lines 22 to 28)
Line 22: Definition of a variable (used to store values of a certain type) named number1. The type is int (integer = integer).
Line 23: Definition of a variable named number2. The guy is int again.
Line 24: Definition of a variable named Result. The guy is int again.
Line 25: Assignment of the value from the text box (textBoxZahl1) to the variable Zahl1. The value entered is in the text property of the text box, and it is a string. This string must be converted into a number. This is done using the method int.Parse
Line 26: Same as line 25 for the variable number2.
Line 27: Execution of the addition and assignment of the result to the variable Result.
Line 28: The calculation result from the variable Result is displayed in the text box (textBox result). To do this, it must now be converted from a number (type int) to a string. This is done by the ToString () method.