Among the first fundamentals most of us learn are the amazing called Principles of Object-Oriented Programming. And as novice students, we just go ahead and learn them.
Maybe you aren’t sure why something is the way it is and question it directly, but once you make sense of it you see that, well, it makes sense.
But almost no one sits down to think how does this relate to what they already know at a meta level.
I believe that the meta level is very important. Knowing how to do stuff right is useful. Knowing why is key.
It is one crucial difference between a good Junior Developer and a good Software Architect.
Now, in my career thus far I have done a lot of work in non-OOP code. C programming is the most obvious. But I aint no stranger to some glue-work, with bash scripts for example.
And I’ve seen some horrendous bash scripts, especially with the emergence of the Devops spiel (no offense).
Just last week I had to redo a shell script to work with Sysrepo. It was made to take an IP address and change a bunch of files accordingly.
Well, that’s what it was supposed to do…
It actually did too much more.
Previously a program read a JSON config file and for any changes it called the respective scripts. However this script was smart. It didn’t just know about an IP it had to change. It was so savvy, it knew about the JSON file its arguments came from. In fact it had a bunch of logic depending on that file.
Hence why it was a pain in the ass to make it work without it.
Detective skills are good to have as developers 😉
It broke Encapsulation rules, because it was aware of the JSON file.
And it required its caller to break Abstraction rules, because even with the same argument, it did different things depending on the JSON.
I’m so glad all that mess is behind me and it will be easy peasy to change as needed in the future.
“But wait” I hear you say, “How can it break Encapsulation and Abstraction? Those are OOP principles and you’re talking about Neanderthal shell scripts!”
Well… they are important for OOP. But do they require objects as we know them in OOP?
Inheritance obviously does. It’s not obvious to me these 2 do.
As we saw, you can definitely apply them to non OOP code. And I argue that you should.