Technology
Why Object-Oriented Programmers Believe Smalltalks Features Are More Powerful Than Javas
Why Object-Oriented Programmers Believe Smalltalk's Features Are More Powerful Than Java's
Introduction to Object-Oriented Programming and Its Expressiveness
When it comes to object-oriented programming (OOP), the power of a language lies not in its inherent superiority but in its ability to express ideas clearly and readably. Smalltalk and Java, both popular object-oriented languages, have their unique strengths and weaknesses. Smalltalk, in particular, is often praised for its more direct and expressive approach to OOP, minimizing the need for compromises that might hinder programmers.
Understanding the Basis and Compromises of C and Java
A relatively well-known statement by Alan Kay, one of the founding fathers of object-oriented programming, highlights the pitfalls of C and Java. Kay notes that these languages are often designed to look like their predecessors, in this case, C and C . This approach may help programmers transition, but it can also obscure the true power of the new metaphor being employed.
C and Java both make compromises that can conflict with OOP principles. For example, Java's use of getter and setter methods to enforce encapsulation can introduce an additional layer of complexity for the programmer. This is because the 'public' access modifier can expose internal workings, breaking the uniform access principle (UAP) and encapsulation. Such compromises can make the code more difficult to maintain and can introduce bugs that are hard to identify and fix.
The Differences Between Smalltalk and Java in OOP
Smalltalk, on the other hand, offers a more direct and unencumbered approach to OOP. Unlike Java, Smalltalk does not require the use of getter and setter methods or other workarounds to maintain encapsulation. This directness allows Smalltalk to be more expressive and simpler to understand, leading to more readable and maintainable code.
Smalltalk and languages derived from it, such as Eiffel, prioritize the goals and principles of OOP more directly. Java, on the other hand, often starts with process-oriented reasoning and design and then tries to incorporate OOP principles. This process of "shoe-horning" OOP into an already existing structure can lead to compromises that make the language less powerful and harder to use effectively.
Maintaining Correctness and Clarity with Eiffel
Eiffel, which was inspired by Smalltalk, takes the principles of OOP to another level. The Eiffel programming team has put a lot of thought into how the language's grammar and syntax can impact software correctness and long-term maintenance. One of the standout features of Eiffel is its adoption of Hoare logic, embodied in the concept of Design-by-Contract (DbC).
Design-by-Contract is a formal tool that allows developers to specify the correctness rules for the use of classes and their methods. By using these contracts, developers can ensure that a class functions as intended, reducing the likelihood of runtime errors and improving maintainability. This approach is just one example of how Eiffel's focus on purity and correctness can lead to more powerful and robust software.
Conclusion
When comparing Smalltalk and Java, it is clear that the "power" of a language in the context of OOP lies in its ability to express ideas clearly and maintain correctness and clarity. Smalltalk and languages like Eiffel, which are inspired by these principles, can offer a more direct and unburdened approach to object-oriented programming. While Java has its advantages, its compromises and inherited design aspects can make it less powerful and more difficult to use effectively compared to languages that prioritize OOP purity.
For programmers interested in understanding the goals and principles of OOP more deeply, reading books and papers that focus on pure OOP can be invaluable. Whether it is the insights derived from Smalltalk or the tools and strategies implemented in Eiffel, there is much to gain from exploring the principles that underpin these powerful object-oriented programming languages.