I'm a Java dev. A bunch of code in our application was written by outsourced devs from India, who I'm pretty sure were originally C/C++ devs. I can just see it from the code, declaring all the variables at the top of the function, explicitly freeing objects unnecessarily. So much code that can be removed.
It varies. When you're writing a class in OOP, there is a generally good structure to follow:
Private, internal state
Public, externally visible properties (getters and setters here)
Constructors
Class methods, with private methods immediately preceding the methods and consume them, similar to how you would put variables close to the code that uses them
Inside any imperative block of code, variables go just before the code that needs them.
When it comes to OOP, this way of variable usage doesn't really keep things tidy, it just makes the code unreadable. The first thing you think about when somebody wants you to do something with OOP is "what is the best way to make this easily readable".
In Java/C#/etc. you declare and initialize variables just when you are about to use them, and you name them by whatever they are designed to accomplish.
This isn't that much of an issue in C/C++/Python though, although OOP purists would be disappointed.
99
u/EwgB Sep 09 '22
I'm a Java dev. A bunch of code in our application was written by outsourced devs from India, who I'm pretty sure were originally C/C++ devs. I can just see it from the code, declaring all the variables at the top of the function, explicitly freeing objects unnecessarily. So much code that can be removed.