3 ms·
"The ceremony of object wrappers doesn’t carry its weight." This nails it. I find so much of my programming now is shoving data into objects, only to almost i
by jimbokun 18y ago
"The ceremony of object wrappers doesn’t carry its weight."
This nails it. I find so much of my programming now is shoving data into objects, only to almost immediately pull it out again into JSON, XML, HTML templates, or relational databases (in both directions). Most of the code in these "objects" are just getters, setters and member declarations, with very little in the way of actual logic. There is little point in having objects at all for this kind of programming, as opposed to a map, struct, or type class of some sort.
- jballanc 18y agoIt sounds to me like this is a case of "right tool for the job". Regardless of what the "future" of programming languages is, I don't think we'll ever be free from making those sorts of decisions.
- russell 18y agoI agree 100%. Maps and lists are good workhorse objects. You don't need to clutter up your projects with lots of custom objects that do nothing more than transport data. Add to that the over use of inheritance, abstract classes, and interfaces an you get impenetrable clutter. Throw in frameworks and all their XML glue an a simple bug fix become a heroic quest.
- stcredzero 18y agoIf procedural programming is simpler for you, then do it that way! If you have lots of objects that are just glorified structs, then you are factoring badly. I have been in lots of projects. Not all OO is like that. Apparently, yours is. (Oh, and XML glue should be considered a "Framework Smell!")
- jimbokun 18y ago"(Oh, and XML glue should be considered a "Framework Smell!")" How about object relational glue? JSON glue? HTML template glue? Google Protocol Buffer glue? (Sure I am missing lots of others.) I do not know how you go about modern web programming without lots of glue that takes some square data and transforms it into some round data for some other piece of software, be it a browser, a client of your web service, a relational database that has data you cannot live without, etc. etc.
- modoc 18y agoIf you're just working by yourself, then by all means use whatever you want. If you're working on a multi-developer team, or someone else might have to work on or try to fix your code later, please use structured objects, not Maps. The point of having named and typed member variables is that I actually know what's in there. I know that a User object has a displayName property, so I can use that. I know that the address property is actually a List of Address objects, not a string, and not a Map. And I can know this instantly using my IDE's auto-complete and tool-tips. It's also exposed via Javadoc, which means if your front-end team is writing the JSPs, they can just look at the Javadoc to know what they have access to, without bugging me every 10 seconds. Not only do I know, but the compiler knows, and can let me know if I'm trying to access something that doesn't exist, or I typo'ed the name, or if I'm trying to treat a String like a Date. If you're using a good IDE, creating the members and even getters and setters shouldn't take you much time at all, and will be well worth it in maintainability, compile-time checking, debugging, extensibility, etc...
- jimbokun 18y ago"If you're using a good IDE, creating the members and even getters and setters shouldn't take you much time at all" I don't totally disagree with what you say, but having your IDE auto-generate lots of code automatically for you gives me the heebie-jeebies. The problem is that with a language as verbose as Java, you quickly have a bajillion files filled with far more characters than it should take just to define some property names and their types. Especially considering how having a public field in an object is a Java Mortal Sin. I could go on, but Yegge has summed up the problems with generating mountains of code with an IDE, that then requires an IDE to move around, here: http://steve-yegge.blogspot.com/2007_12_01_archive.html http://steve-yegge.blogspot.com/2007_12_01_archive.html
- Daniel_Newby 18y ago"If you're working on a multi-developer team, or someone else might have to work on or try to fix your code later, please use structured objects, not Maps." Or pick a language in which the difference is an implementation detail, where an object defaults to a bag of data, but getters and setters can be transparently substituted when it becomes necessary.