开源日报 每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,坚持阅读《开源日报》,保持每日学习的好习惯。
今日推荐开源项目:《远程单位 awesome-remote-job》
今日推荐英文原文:《Object-Oriented Is Not Dead》

今日推荐开源项目:《远程单位 awesome-remote-job》传送门:GitHub链接
推荐理由:让从五湖四海来的所有员工集中在某地的一个办公室里似乎在现在重要性并没有这么强了。这个项目是关于远程工作的资源合集,包括文章与相关工具等。远程工作有利也有弊,没有地理位置的限制就可以招募到更广地区内的员工,省下的通勤时间也能换成工作时间,但是地理距离拉开之后保持高效的沟通就变得更加重要,没有了面对面的高效沟通,使用其他工具或者规则来补足这一点就显得极为重要。
今日推荐英文原文:《Object-Oriented Is Not Dead》作者:Aphinya Dechalert
原文链接:https://medium.com/better-programming/object-oriented-is-not-dead-eca233347870
推荐理由:最起码,把所有东西都看作一个对象的观察法经受住了时间的考验

Object-Oriented Is Not Dead

Long Live OOP and its place in JavaScript

Object-oriented programming (OOP) has gone through the mill of being adored, to suddenly hated by the masses. While it’s hard to discern how much of that love, hate, and intensity is fake news, the verdict is that the idea of object-oriented is not dead.

The issue isn’t object-oriented itself. The issue is how object-oriented was, is, has been, implemented. Legacy methodologies of OOP such as inheritance patterns are being regarded as insufficient to deal with the modern demands of a much larger codebase with more moving parts.

This isn’t OOP’s fault directly. Some patterns are simply behind in the times or are unsuitable at certain scales. Sometimes, the developer behind the code just hasn’t caught up with the memo yet, or they only know one OOP pattern.

Everything Is an Object

In the beginning, some guys at MIT in the late ‘50s came up with the idea that everything is an object. Sure, the idea of “objects” itself isn’t exactly new, but in programming, this was akin to a philosophical breakthrough.

The way we function as a civilization depends on our ability to communicate our personal translations and experiences of the world. Language is the way we facilitate this — whether it be verbal, non-verbal, visual, performance arts, music, or writing that captures the complexities of an idea in a simple way. Sometimes we mix and match to further enrich our experience of the idea.

For programmers, code is a communication bridge between us and digital machines. To classify everything as an object is a way to simplify the translation of business rules and interactions with their various action points.

Objects are essentially an organization tool that may also contain descriptions and abilities to perform actions — also known as, properties and methods. How these properties and methods are internally arranged to construct the blueprint for the object, often known as a class, is dependent on the scenarios and the developer’s knowledge of different implementation of object-oriented patterns available.

Most popular programming languages such as C++, Java, Python, and PHP all support the idea of objects. However, they also support other models of thinking and are not exclusively object-oriented, meaning that they are also capable of imperative and procedural methodologies.

JavaScript is an ideological chameleon. It has some of its foundations in object-oriented through prototypes but also is able to cater to other paradigms because it was created to “just work” regardless of whatever code you typed in.

JavaScript and Its Secret Love Affair With Objects

In the eyes of the JavaScript engine, everything is an object.

Your variables are objects. Your functions are objects. Your arrays, your numbers, even your Objects are objects. This is important because it means you can assign properties to them. It’s also why we have an assortment of predefined methods available to us such as .length() for arrays and .arguments() for functions.

The confusion about JavaScript and its relationship with the object-oriented world starts where it begins.

JavaScript isn’t a language that advertises itself as being object-oriented. In fact, you don’t even have to aware of such an idea for it to work. Unlike Java- and C-based languages, which require a level of syntax strictness, JavaScript’s general looseness adds to its generalized secret love affair with the idea of objects.

Under the hood, JavaScript runs on a prototype pattern — which is a form of deconstructed chained inheritance object-oriented pattern that isn’t required to be singularly attached to one thing.

Traditionally, object-oriented is taught in the vein that everything gets put into a class to make a blueprint for an object to instantiate. JavaScript takes a step back from all this and runs on the foundational idea that an object is something you can assign properties and methods to, regardless of its type and final expected shape.

In JavaScript, everything begins as an object and ends as an object. Its definition of what an object looks like is based on two characteristics of having properties and methods, rather than the process of creating a traditional-looking object.

Stop Right There. What About Functional Programming?

Functional programming is a pattern that is currently being spoken about like it’s the thing that will put object-oriented into its grave. However, it’s a completely different method of translating ideas and runs on the premise of inputs, outputs, and functional machines.

Object-oriented is concerned with the idea of things. In contrast, functional paradigms are concerned with the processing of things. In JavaScript, functional patterns often exist as predefined methods. For example, array methods such as filter(), find(), map() and reduce() are functional array methods that help reduce the complexity of code and potential points of failure.

Over the years, programming languages have come to a silent consensus that a single way of thinking can’t possibly cover all the potential bases. It’s also why many programming languages have evolved to be multi-paradigm to prevent themselves from alienating developers with undetermined cases in the wild.

JavaScript Is Extending Its Features and Functionality

JavaScript started off as a simple scripting language. Over the years, it has gained supersets like TypeScript to give it a more traditional and strongly-typed approach to code creation.

As JavaScript catches up by growing its syntax and ideological implementation toolkits, we are greeted with new keywords and concepts that make our lives easier as developers.

The class keyword, for example, which was recently introduced in ES6, is merely syntax sugar to help make explicit the implementation of object-oriented ideas. The actual object-orientedness of JavaScript and its prototypal inheritance patterns remains more a meta-like and structural foundation for the language.

Another new feature that’s currently in the final stage of review is private variables in classes. There is limited scope let but not an actual direct way of implementing the idea of private in JavaScript. When this goes through, you’ll be able to directly do so by declaring variables with a hashtag in front of the variable you want to scope as private to the declared class or function.

Final Thoughts

In the world of JavaScript, object-oriented isn’t really winding down. Rather, it is expanding syntactically to remain true to its spirit of flexibility.

Everything is made of ideas and one of those ideas is that everything is an object. Whether this is true or not is a completely different and potentially existential debate.

Object-oriented isn’t dead. Nor is it close to being dead. Rather, its hype has just deflated a little as the flaws in its implementation, such as classical inheritance patterns, come into view. However, patterns that don’t scale well don’t mean the end of ideas. Adaptations are growing as more people explore OOP to help solve their particular problems.

Legacy code is always annoying to deal with and a lot of the time, it’s written with the idea of object-oriented in mind. However, one shouldn’t dismiss object-oriented completely, but learn from how things fell apart.

At the end of the day, it doesn’t matter what paradigm or pattern you use. Your code will always age and chances are that someone in the near or far future will judge your chosen solution and deem it impractical because the code has grown out of its implemented patterns.

So is object-oriented dead? Some say so, but in reality—far from it. In the world of web technologies and with JavaScript releasing more features and functionality to support making object-oriented patterns explicit, the idea of objects is still thriving loud and proud.

Thank you for reading.
下载开源日报APP:https://openingsource.org/2579/
加入我们:https://openingsource.org/about/join/
关注我们:https://openingsource.org/about/love/