Marvin Minsky. Why Programming Is a Good Medium for Expressing Poorly-Understood and Sloppily-Formulated Ideas.
One Class, Many Objects
Classes help us organise complex ideas, making it easier to maintain our code and giving us greater flexibility in terms of what we can achieve in this medium. When using classes, we talk about creating an object. You can consider classes as a blueprint if you like and an object is one example or instance of that blueprint. What is important to grasp is that each object that we create is a unique entity of that class.
Objects are characterised by three essential properties: state, identity and behaviour. The state of an object is a given value determined by the data fields of that class. The identity of an object distinguishes one object from another. It is useful to think of an object’s identity as a place where its value is stored in memory. The behaviour of an object is the effect of the class methods and hence the operations performed on the data.
Again, these principles echo back to what I mentioned at the beginning of this course, that a computer program is essentially made up of data structures and control structures. Data stores symbolic values whilst control structures deal with processing that data. With classes, we now have the means to define our own data types and furthermore encapsulate both data structures and control structures all in one neat entity.
Let's take our last example for a bouncing ball and create another instance of this class. We are going to add another method to our class too that will give it a different behaviour. The idea is to understand how we can create numerous objects of the same class and attribute different behaviours depending on the methods we call upon them. From here, it should be clear that this way of programming gives a certain level of organisation and flexibility. We have a single entity to which we can add further methods and data fields. The class therefore becomes a modular structure that we can eventually build on.
You can execute this sketch with P5js's online editor
Not all the code is apparent above, so please check out the source and explore this sketch. To summarise, we have two objects declared and we are calling different methods on each as well as passing in different values as arguments for these methods. We have already seen this concept of passing in data with functions. This is exactly the same thing. Methods are after all just functions that belong to a class. Objects are dynamic, meaning we can make changes to them at run time. Notice what happens when you press the 'm' key on your keyboard. If you look closely at the source code, you'll realise we are changing method calls on our objects.
To drive home the concept of objects and the flexibility of classes, let us look at an example that creates many objects. To do this we are going to create an array or list of objects.
This wraps up this chapter and it is also where I end this concise introduction to programming. My main aim with this website and brief course has been to explain the five core concepts: variables, functions, control, loops and classes. I wanted to give some insight into the mechanisms and structures that underlie most modern programming languages, helping the beginner to understand these in a clear manner without going into too much detail, nor diverging into the formal capacities of code. I hope I have managed to do that. If you are a reader from afar who has stumbled upon this course (which I wrote to accompany my teaching course), and you have any suggestions or would like to point out mistakes or confusing passages, please do not hesitate to contact me. I'd be most appreciative of feedback.
From here, the student is encouraged to pursue their exploration of this medium with further readings and personal reasearch in the many artistic projects that exist out there. You are also encouraged to go beyond the context of code as just purely a creative medium. Code, in its wider sense, is a culturally important media and medium shaping many aspects of our current landscape. It is quickly shaping not only form but also ideas and concepts, thoughts and behaviours. The scope of code is far reaching and fundamentally an essential part of contemporary society. Learning to read and write it has already become a vital part of education and it will continue to enrich our understanding. Code is language and I don't know of any aspect of our life that isn't concerned with language. It's all around and within us. Embrace it.