5 ms·
I find many of the objects in .NET very useful and use them in my code. Also in my code I define and use some classes. I like the idea of classes. E.g., in m
by graycat 10y ago
I find many of the objects in .NET very useful and use them in my code.
Also in my code I define and use some classes.
I like the idea of classes. E.g., in my Web pages, I have a class for the user's state. When a new user
connects, I allocate an instance of that class. Then I send that instance to my session state store server. To do that, I serialize the class to a byte array and then send the byte array via TCP/IP. The session state store server receives the byte array and deserializes it back to an instance of the class and stores it in an instance of a collection class. Works great. It's really convenient
to have all the user's state in just one instance of one class. Terrific.
Encapsulation? I don't know what the OO principles say about encapsulation, but it looks useful to me as a source of scope of names and keeping separate any members in two different classes that are spelled the same. So, terrific: When I define a new class, I don't have to worry if the names of its members are also used elsewhere -- saved again by some scope of names rules.
Actually, I much prefer the scope of names rules in PL/I, but now something as good as PL/I is asking for too much!
But inheritance? Didn't think it made much sense and never tried to use it.
Polymorphism? Sure, just pass an entry variable much like I did in Fortran -- now we call that an interface. Okay. I do that occasionally, and it is good to have.
Otherwise I write procedural code, and the structure in my software is particular to the work of the software and not from OO.
I couldn't imagine doing anything else.
I've seen rule-based programming, logic programming, OO programming, frame-based programming, etc., but what continues to make sense to me is procedural programming with structure appropriate to the work being done. E.g., the structure in a piece of woodworking is different from that in metal working, residential construction, office construction, etc.
- nickpsecurity 10y agoWhat were the benefits of PL/I scoping vs others?
- graycat 10y agoGet two kinds of essentially nested descendancy, static (from the source code) and dynamic from execution as make calls but from which have not yet returned. It's good to think about both at the same time. The push down stack of dynamic descendancy defines what parts of the code are active and, thus, can be called. E.g., the names currently known by inheritance are from the dynamic descendancy working through the static descendancy. And, then, can call code back in dynamic descendancy that is still known from the static descendancy. Wow! It's simpler than that: Can have BEGIN-END as a chunk of code with its own names. Any name used inside there but not declared there is inherited from the code that is active (in dynamic descendancy) and in the static descendancy. E.g., can have ON CONDITION X; BEGIN; ... END; and execute that. That execution just says that, in the future, if see RAISE X, then execute the code in the BEGIN-END. Then that code can do GOTO Y where Y is a label known in the BEGIN-END block and in code in the dynamic descendancy. If the code of Y is 11 steps back in the stack from the RAISE, then all the 10 lower levels of code are exited. Lots of cleanup happens automatically. So, the ON CONDITION is executing code back in the stack of dynamic descendancy -- darned cute. And can do such things quite generally. So, code block A can have an internal subroutine B, call C, pass an entry variable to B, and the code of C can call B. B then can have values inherited from the code of A and use those values as B executes from the call of C. Did that once when scheduling the fleet for FedEx! Once in some AI work at IBM's Watson lab, used a fancy case of that name scoping to save our project a few weeks of work and improved the quality of our product. Got an award for that! That's a fast outline -- maybe not fully clear. Any questions?
- icebraining 10y agoNot sure I got it right, does A pass a reference of B to C, since it's an internal subroutine? Isn't that essentially a closure? EDIT: Reading a bit more into it, it's clear that's not it, thought the A/B/C example sounds like it could be done with a closure.
- graycat 10y agoAt times I've thought that that little device (pattern?) was essentially a closure, but since I don't really know what a closure is I can't really say! Uh, I've done a lot of programming in a lot of languages, but my main interest is not as a programmer but as a founder of a startup that needs some software!
- icebraining 10y agoRe: classes, sounds more like you're describing structures. This is not really specific to OO, and it's available in FP languages (e.g. records in Haskell). And these provide scoping, which isn't really encapsulation, as far as I understand it.
- graycat 10y agoYes, I use OO classes much like I used to use PL/I structures which, of course, are generalizations of C and Cobol structures. And classes have some additional advantages, e.g., can do serialization. And, what I really like is the name scoping. For what else is significantly different in encapsulation seems a little obscure. Maybe the biggie difference is not only have the data with name scoping, but also have the code, the methods, stuffed inside the class and making changes in the data in the properties of the class. Okay -- so get to use the class and its methods without keeping track of subroutines/functions separately. Okay.
- rdtsc 10y ago> But inheritance? Didn't think it made much sense and never tried to use it. This is interesting to read. When OO was popular inheritance was at the top of the list as the OO killer feature. "your 'Manager' class is just an employee but with 3 extra methods, so you save so much copy and paste, etc etc". I believed it at some point. Then perhaps 15 years later, after everyone has been bit by deep, confusing inheritance they had to maintain and debug, inhertance is the devil. It is just interesting to observe how once a selling point of OO is now a big giant warning to stay away from.
- graycat 10y agoThere was a lot of hype floating around. There still is. It's like the news: Always the same just the names change.