Object-Oriented Programming

Abstraction

But what is an abstraction?

An abstraction is a common noun for all subordinate concepts and connects any related concepts as a group, field, or category.

  • I am rereading Clean Code now that I am a much better programmer than I was in first year. Also see Software Abstraction.
  • Yupp, Clean Code is what made me understand what abstraction is all about. That is what good code is. Knowing where the abstractions are put

Example

A car is an abstraction of the various specific kinds of cars (Mazda, Mercedes, Toyota, etc.).

You can always be more specific. But just like in a conversation, when someone asks you what car you drive, you need to know how deep you dive.

  • Figuring out the right layer of abstraction is essential

My notes are abstractions

I abstract away notes, when they become they big / diverse. However, I make those tradeoff decisions based on locality (Primegean.

Abstraction is an extension of encapsulation. It is the process of selecting data from a larger pool to show only the relevant details to the object.

Abstractions are nice… until they stop working. cough cough Robotics.

In terms of my thoughts on the layers of abstraction (from NVIDIA):

  • One could argue that clean code is when there are lots of layers of abstractions, and things are modular and all of that. But it is just so hard to understand, when you have to jump from functions to functions to functions

It should definitely help that the naming of the variables should be explicit. However, seeing how the Comma code was written, it’s not that good.

Our World Is Based on Abstractions

Our entire world operates on abstractions. Here’s one more recent abstraction that I learned: When you enter a website URL, this seems to be what is going on:

You think that you are communicating with a server located at www.medium.com. However, once you start understanding how the Internet works, you realize that you actually need the IP Address. So there is a whole DNS name resolution process behind the scenes:

CS241

This course is really opening my eyes about how many freaking possible layers of Abstraction there truly is in a Computer Program.

CS241 deals with these abstractions more at the software level.

It is important to truly understand how we move between these abstractions.

ECE222

In ECE222, we also really get to learn the layer of abstractions, now more at a hardware level. See Layers of Computer Program.

SE212

They talk about role of abstraction: “In symbols one observes an advantage in discovery which is greatest when they express the exact nature of a thing briefly and, as it were, picture it; then indeed the labor of thought is wonderfully diminished.”

  • When you abstract, you have to think less hard.

But I mean, simplicity has its pros and cons.

Personal Thoughts

Abstraction is great for users. But if you want to innovate, you need to dig under all these abstractions and really understand what is going on under the hood. Become 10x Developer.

I mean when we talk, it’s really an abstraction of what is really going on under the hood. Into something more tangible and understandable.

Abstraction is like doing PCA, where you reduce down the dimensions to something simpler. Well… I am not 100% sure about this analogy.

It’s like when I try to understand Priority Queue, or essentially any ADT. Different data structures have different uses cases. YOU can operate at a higher level of abstraction, where you just memorize the time complexities of that data structure.

OR, you can actually try to understand why those are the time complexities, and that will also help you remember that information better. But to do that, you need to go down a layer of abstraction.

So do you really need to go down a layer of abstraction to understand why insertion for Priority Queue is ? Not really, you study it for the programming interviews.

When do you go down a layer of abstraction?

There are connections with High-Level Low-Level Thinking. Go down a layer of abstraction when you need it, but when you do, make sure you FULLY understand. Ask not only HOW, but also WHY.

Robotics

I feel that I still operate at too high of a level of abstraction to understand how robotics works. I am able to use all these libraries. But now, I want to be able to write my own.

Leaky Abstraction

Andrej Karpathy talks about this idea of leaky abstractions. It can be attributed to this.

To read: The Law of Leaky Abstractions (2002 blog)

Thoughts on Abstractions

I hate unnecessary abstractions that add no usefulness. Abstractions add overhead, because it’s hiding a layer of complexity behind a function call. Like ideally, you’ll have everything as detailed as possible. But then, it’s not readable.

I guess the question is, when do we ever need abstractions?

Why are abstractions useful?

This might be a stupid question, but it’s worthwhile asking. The world is complex, codebases are complex, and to be able to handle this complexity, we have abstractions. But do we need it?

From Clean Code: Mixing levels of abstraction within a function is always confusing. Readers may not be able to tell whether a particular expression is an essential concept or a detail.