r/programming • • May 28 '14

"Compression-oriented programming" - Casey Muratori's blog

http://mollyrocket.com/casey/stream_0019.html
126 Upvotes

67 comments sorted by

View all comments

11

u/[deleted] May 28 '14

If his stance is generally against OO, then I agree with him for the most part. OO has its uses, but it's far overused, overhyped, and over emphasized in terms of importance. 95% of OO code I've read (including my own) has been poorly implemented and naively designed.

I don't think any one paradigm is a one-stop solution in terms of its methodology (nor should a paradigm never be used). A lot of people in the industry tend to have a major hard-on for OO though...and it tends to be attractive to newbies as well, once they've grasped the concept of classes.

In my opinion, as soon as the focus shifts toward "objects" and extremely pedantic notions in regards to how aesthetically pleasing one's code is, the point has been lost. I still see a very large portion of code employing the use of getters and setters, the majority of which provide absolutely no benefit, and have witnessed near heated discussions on things like IsNullOrEmpty() function calls being argued against, not because of what they do, but because of their title.

Good code is code which is readable, as simple as it needs to be to function properly, is defensive where it needs to be, conforms to a clear set of pragmatic standards, and has a reasonable amount of comments. Anything else is pretty much subjective and detracts from the point, which is to write software which works well for the user and is only as complicated to maintain as is necessary.

So, OO itself isn't necessarily bad; it's the philosophical connotations and over-thought code pollution which unfortunately tends to come with it that's bad.

1

u/WisconsnNymphomaniac May 29 '14

For me OO is very frustrating in that I don't have a hard time programming and find it pretty obvious when to create a function, but I really suck at designing objects and determining how they relate to each other. The sheer complexity it introduces is just incredible.

1

u/ummwut May 31 '14

I have a tip for you: Just do everything with functions and free variables first. When you find yourself using the same group of variables frequently, toss them into a struct. When you find yourself using the same structs and functions together, you make an object.

Sometimes it's better to just get started, be messy, and aggressively refactor later.

Also: COMMENT COMMENT COMMENT

1

u/WisconsnNymphomaniac May 31 '14 edited May 31 '14

Good advice, but what really defeats me is the whole access modifiers like

public : Access is not restricted.

protected : Access is limited to the containing class or types derived from the containing class.

Internal : Access is limited to the current assembly.

protected internal: Access is limited to the current assembly or types derived from the containing class.

private : Access is limited to the containing type.

How do you learn how to use those correctly?

1

u/ummwut May 31 '14

I would never bother with Internal. While working through your code, and object-orienting, I would ask a few things about the variables and functions: Who is using them, and why? If the answer is "the class, only the class, outside classes shouldn't mess with these." then they are Private. If the answer is "the class and derivative classes that might override them but still must access the parent class functions, but nothing else besides those" then they are Protected. Public is for everything else, such as API functions.

For something like a doubly-linked list class, you'll have "reset(), next(), store(), retrieve(), endOfList()" which are the APIs, public functions. Private data is stuff like the struct for the list nodes, the pointer to the start of the list, and helper functions the user of the class shouldn't mess with in any way. For something like templates, Protected is basically all the functions are, besides being Virtual.