Pseudocode

You might associate the word pseudo with a sham. But when developing a programmer mindset, we try to eliminate as many aesthetic smells that concepts carry. Pseudo comes from the Greek, pseudes, which means “false.” But the reason we call it pseudocode is because it is not the full expression of the code – the code that actually runs; it is rather like the skeleton. It should instead be called skeletoncode, and it is a method for expressing a program’s order of instructions in the spoken language, rather than a programming language.

In this way, the programmer can concentrate on designing a program without also being slowed down by immediately converting to the syntax of the particular programming language. This is the same as when drawing. When drawing a human we first draft a faceless model. The pseudocode for calculating the sum of two numbers would look like this:

Screen Shot 2018-12-07 at 1.07.15 PM

There are no rules. You can use any wording that works for you.

Let’s look at another example. Suppose your program needs to calculate the square root of an integer. The instructions for calculating a square root are rather complex; gracefully and compassionately, Java provides prewritten code that computes the square root of any integer. The prewritten code is called a method, and your program can execute that code by calling the method. As part of the method call, you tell the method which integer’s square root you want to calculate. This is called passing an argument to the method. When the method finishes executing its instructions, control is passed back to your program just after the method call.

Another way of looking at method calls is to consider what happens when you’re walking through a night-lit city and find a restaurant with an aroma that lures you in. Your brain marks your place in the night-lit city trajectory and goes to eat inside the restaurant. When you’re finished dining on the meal, you go back to the streets and continue walking.

Here I show the pseudocode for calculating the square root of an integer:

Screen Shot 2018-12-07 at 1.30.37 PM

The order of operations is still input, calculate, and output, but we’re calling a method to perform the calculation for us. Now suppose your task is to determine whether a number is positive or negative. First, your program should input the number into the computer. Next, you need to determine whether the number is positive or negative. You know that numbers greater than or equal to 0 are positive and numbers less than 0 are negative, so your program should compare the number to 0. Finally, your program should write a message indicating whether the number is positive or negative.

Like in the pseudocode examples, the operations are input, calculate, and output, in that order. However, depending on whether the number is positive or negative, your program should write a different message. If the number is greater than or equal to 0, the program should write a message that the number is positive (may the God of Mathematics forgive this sin), but if the number is less than 0, the program should write a message that the number is negative. Code used to handle this situation is called selection; the program selects which code to execute based on the value of the data.

The pseudocode for this program could be written as that shown:

Screen Shot 2018-12-07 at 1.33.44 PM

Notice the indentation for the code that will be selected based on the comparison of the number with 0. Programmers use indentation to make it easier to see the flow of control of the program.

Now let’s get a little more complicated. Suppose your program needs to find the sum of a group of numbers. This is called accumulating. To accomplish this, we can take the same approach as if we were adding a group of numbers using a calculator. We start with a total of 0 and add each number, one at a time, to the running total. When we have no more numbers to add, the running total is the total of all the numbers. Translating this into pseudocode, we get the code shown:

Screen Shot 2018-12-07 at 1.37.31 PM

The indented code will be repeated for each number read until there are no more numbers. This repeated execution of the same code is called looping, or iteration, and is used extensively in programming whenever the same processing needs to be performed on each item in a set.

Accumulating a total and determining whether a number is positive or negative are just two of many commonly performed operations. In programming, you will often perform tasks for which there are standard methods of processing, called algorithms. For example, the algorithm for accumulation is to set a total to 0, use looping to add each item to the total, then output the total. More generally, you can think of an algorithm as a strategy to solve a problem. You yourself are a strategy to solve a problem in the multiverse, a timeless algorithm. However, knowing the full nature of the problem would not allow you to solve it – this would be equivalent to having already solved it – hence becoming permanently stuck at a local maxima. The human mind is set up to be deceived about where it is going.

In an earlier post, we used an algorithm to convert a decimal number to its binary representation. Other common programming tasks are counting items, calculating an average, sorting items into order, and finding the minimum and maximum values. Here on Vitrify Her, you will learn the standard algorithms for performing these common operations. Once you learn these algorithms, your ability to achieve synchronization will become easier. When you recognize that a program requires these tasks, you can simply plug in the appropriate algorithm with some minor modifications.

Programming, in large part, is simply reducing a complex task to a set of subtasks that can be implemented by artistically combining the Four Noble Algorithmic Truths: sequential processing, method calls, selection, and looping. The most difficult part of programming, however, is recognizing which algorithms to apply to the problem at hand. This requires analytical skills and the ability to see patterns. Here on Vitrify Her, I will point out common patterns wherever possible.

Looking for patterns will help you determine the appropriate algorithms for your programs. Looking for patterns is the way of sunyata.

Short Intro To Object-Oriented Programming

Let’s recall what high-level languages are: these are languages that are symbolic, so not the ones and zeros underneath it all. They are that which provides handles for the human mind to pilot the Eva – in other words complete the task of serving a functional role in a complex society that you as an individual did not create. The way you do this is by learning symbols and how to manipulate these.

Like with all good creation myths, in the beginning, there were two high-level languages, Fortran and Pascal. These were procedural. What that means is that the program starts with a problem and then breaks that problem down into smaller sub-problems or sub-procedures.

Procedural language took a literal approach, working as a straightforward story composed of top-down instructions.

But a program inevitably has sections. Typically, programmers of old had to write task-specific code in separate procedures/functions, and invoked these procedures from one section of the program to another in order to perform various tasks. And the program’s data was generally shared among the procedures – there were no membranes enclosing different cells in the original primordial soup.

In the mid-1970s, the first object-oriented programming language, Smalltalk, was born from the sins of the procedural languages, enabling programmers to write code with a different approach. Whereas procedural languages were brutish in that they did not recycle code by attempting to enclose into concepts and dealt mainly with basic data types such as integers, real numbers, or single characters, Smalltalk provided the programmer with a new tool: classes and objects of those classes. Classes are simply concepts. Like ramen is a class containing the objects of noodles, broth, egg, bowl. If you had to tell the chef to place noodles, broth, and egg, into a bowl every time you walked into a ramen-ya instead of just telling them “give me ramen,” that would be annoying.

The class enables the programmer to encapsulate data, creating membranes. This is how spoken language itself works. A tribe in northern Namibia packages particular wavelengths of light this way:

Screen Shot 2018-12-06 at 5.35.29 PM

Take a look at buru. For you, buru does not look like a single color. You speak a language that does not put a single membrane on those wavelengths. You instead have a class for each. Perhaps you call them green and blue. Once you see it one way it is short of impossible to see it the other. This is the same with language processing – their tribal language is gibberish, but these words on the screen are helplessly understood. That’s the power of classes.

A class defines a template/model, from which objects are created. Creating an object is called instantiation. Thus, objects are created/instantiated according to the design of the class. A class could represent something we imagine to be real such as a person. The class could have various attributes such as in the example of a “person” class: a name, an attractiveness rating, and an age. The class also provides code called methods. Methods allow the creator of the object to set and retrieve the values of the attributes – granting the power to christen the name as Lindsey, the rating as a solid ten, and to then to reveal this name and attractiveness rating when needed.

One big advantage to object-oriented programming is that well-written classes can be reused by new programs, thereby reducing future development time. (This is just in the same way that We reduce your development time by providing you with over five thousand five hundred revolutions around the sun head-start on the human soul packaged in language. This apex is then accessed through the internet and allows sufficiently maniacally self-motivated teens to ascend to heights of knowledge that would otherwise not be accessible even to those with genius-level IQ.)

In this noble endeavor of conserving negentropy through reusability, Smalltalk was somewhat successful, but had a major fault: its syntax was unlike any syntax already known by most programmers. Most programmers who knew C found themselves in a dilemma. They were attracted by the object-oriented features of Smalltalk but were reluctant to use it because its syntax was so different from C’s syntax. Humans are notoriously allergic to changes in syntax, even when a change in syntax might result in easier understanding of certain concepts.

C++ added object-oriented features to C, but also added complexity. Meanwhile, the Internet was swallowing mankind by the day. Web developers used HTML to develop webpages and rapidly had to incorporate programming features not only on the server side, but also directly on the client side. Fortunately, Java emanated from the void.

Java Inheritance Part 2

The syntax for defining a subclass class that inherits from another class is to add an extends clause in the class header:

Screen Shot 2018-06-30 at 1.54.33 PM

The extends keyword specifies that the subclass inherits members of the superclass. That means that the subclass begins with a set of predefined methods and fields inherited from its hierarchy of superclasses.

JFrame allows us to create graphical applications. So we can use that to create our subclass of StatisticalDispersion and all of its inheriting subclasses.

Here, StatisticalDispersion is the subclass under JFrame. And it inherits from all the classes that JFrame inherits from, all the way back to the Object class.

Screen Shot 2018-06-30 at 3.24.57 PM

The StatisticalDispersion Class Hierarchy

We are coding a class named StatisticalDispersion that extends the JFrame class, so we use the following header:

Screen Shot 2018-06-30 at 3.44.19 PM

Because our StatisticalDispersion class extends JFrame, it inherits more than 300 methods and more than 30 fields. That’s because the JFrame class is a subclass of Frame, which is a subclass of Window, which is a subclass of Container, which is a subclass of Component, which is a subclass of Object.

A hierarchy is composed of subclasses which inherit methods and fields. Here, we make all of them available to the StatisticalDispersion class.

Subclasses do not necessarily need to use their inherited methods, but these are available if needed. The programmer does not need to write methods and define fields in classes which have already inherited them.

JFrame is the direct superclass of our StatisticalDispersion class. As you can see in the image, StatisticalDispersion refers to it. And as you can see in the code, JFrame follows the extends clause.

A class can have multiple direct subclasses but only one direct superclass. One can have many offspring but yet can only develop from one zygote.