It’s true that OO programming can result in issue such as heap fragmentation or other non-deterministic platform states, such as performance deteriorations. Indeed, the issue of OO heap use was one reason why C++ took many years to replace C in embedded development projects. Back in the 1990s, disks, CPU, and memory were at such a premiums that, at least in the minds of designers, they precluded the use of OO languages (which also precluded potential productivity gain from using these emerging languages).
I think it’s still fair to say that a Python programmer may avoid OO features unless no other option exists. In this article, I compare Python and Java to show how they stack up against each other in terms od design. I hope this will allow for an objective assessments.
1 2 3 4 5 6 7 8 9 10 | class Student: def __init__(self, name, age, majors): self.name = name self.age = age self.major = majors def is_old(self): return self.age > 100 |
The Student class in the code has three data members: name, age, and major subject.
Listing 2—A Java student class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public class Student { String name; int age; String majors; public Student() { // TODO Auto-generated constructor stub } public Student(String name, int age, String majors) { this.name = name; this.age = age; this.majors = majors; } } |
The Java code in Listing 2 is very similar to the Python codes in Listing 1. Notice that the use of OO can produce quite readable codes in either language. Listing 1 is not likely to baffle a Java programmer, even without a background in Python. Likewise, a Python programmer well versed in the Python’s OO features would easily understand the Java code in Listing 2.
Nowadays, OO languages are used in embedded platform pretty much as a matter of course. However, there is still some resistance to using the OO features in languages such as Python and PHP. The reasons for this resistance might have more to do with programmer preferences than with reality!
Take your time to comment on this article.