4 ms·
What is wrong with data?
by seles 15y ago
What is wrong with data?
- gnaritas 15y agoIt's bad, in the sense that it leads you to write tightly coupled code that depends on it. The whole point of objects are to hide data and instead expose behavior so other code is coupled to the objects behavior rather than its internal implementation on a specific set of chosen data. This leaves you free to fiddle with the internal implementation without breaking the external API, which leads to modular loosely coupled code.
- cousin_it 15y agoNothing! The extreme opposite to Smalltalk in this respect is the APL/J/K family of languages where everything is expressed as mathematical operations on multidimensional arrays of data. For example, a K programmer wouldn't use an array of rectangles, preferring to have separate arrays of widths and heights. It's a very eye-opening programming style in its own right, and a curious programmer would do well to get acquainted with both. Here's a nice page of "K finger exercises": http://kx.com/technical/contribs/eugene/kidioms.html http://kx.com/technical/contribs/eugene/kidioms.html . To someone who grew up on modern OO languages, it's unbelievable how much K manages to accomplish in one line of code.
- silentbicycle 15y agoThere is a trial version of q (a newer k variant) at the Kx website, and a couple of us are also working on Kona, an ISC-licensed k-like language, at http://github.com/kevinlawler/kona http://github.com/kevinlawler/kona . The k way of doing things is indeed eye-opening. There is some documentation for Kona on its github wiki page, and Hakan has an extensive set of k resources at http://www.hakank.org/k/ http://www.hakank.org/k/.
- seles 15y agoAnother opposite extreme is an OOP language which has no methods. And instead each "method" is really just a data variable which is a closure, making it behave nearly identically to a real method. You could avoid needing these "methods" defined for every instance by simulating inheritance using lexical scoping from a parent class. Although you would need to provide dynamic scope or pass the first argument as self for it to truly behave like a normal method. The simplicity of this model is appealing to me but I do not know if any existing languages use it?