Re: My hang-up about OOP (snit)

Liste des GroupesRevenir à cl tcl 
Sujet : Re: My hang-up about OOP (snit)
De : lorrywoodman (at) *nospam* gmail.com (Lawrence Woodman)
Groupes : comp.lang.tcl
Date : 27. Jun 2024, 06:56:33
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5iuuh$2jicl$1@dont-email.me>
References : 1 2 3 4 5 6
User-Agent : Pan/0.154 (Izium; 517acf4)
On Thu, 27 Jun 2024 02:33:58 -0000 (UTC), Rich wrote:

Luc <luc@sep.invalid> wrote:
On Wed, 26 Jun 2024 22:32:17 -0000 (UTC), Rich wrote:
 
As a thought experiment, consider how you'd make your 'dog' proc
'count' (say you have circus dogs that can 'count' ...) and imagine how
to give each of four different dogs their own, independent, counter to
store their current value into.
>
Then, compare the code you'd need to add to the dog proc to make a
'counting dog' proc with separate counter variables for each dog to the
code necessary to achieve the same result from the counting class
above.
 
lassign "1 1" c_01 c_02
 
proc countcees {cee}    {
        upvar \#0 $cee _cee incr _cee puts $_cee
}
 
countcees c_01 2
countcees c_01 3
countcees c_02 2
countcees c_02 3
countcees c_01 4
 
 
In reality though, nobody needs a proc for that.
 
True, but you are missing the forest for the trees.
 
Imagine extending your example above to 273 different "counters" (or
managing 273 different sets of complicated [more than just a single
counter] pieces of independent data) or imagine managing 15 different
windows with differing (not shared) data, in the same app.
 
That's the point, the "do it with a proc and a bunch of globals"
method, where you have to modify the code to extend from 14 to 15
windows (and likely have to add a 15'th 'then' clause to 95 different
'if'
statements) vs.  having the system handle the "separation" details and
your code change to go from 14 to 15 is to to just create 15 objects
instead of 14.


The non OOP code used in this discussion could be better.  Here's an
alternative to the OOP code, which uses a dictionary although an array
could also be used.  This could easily be extended to more internal
variables and more methods on those variables.  It could even be argued
that this is OOP code in some respects.  The advantage this has over
normal OOP code is that you know what functions are actually being called
with the object.  That is my main gripe with most OOP, at times you have
no idea what functions are actually being called on an object and you have
to dig through the code until you work out what instantiated an object and
what the methods do on that particular object.


namespace eval counter {
  namespace export {[a-z]*}
  namespace ensemble create
}

proc counter::new {} {
  dict create count 0
}

proc counter::count {counterName} {
  upvar counterName counter
  dict incr counter count
  puts [dict get $counter count]
}

set counter [counter new]
counter count counter
counter count counter
counter count counter
counter count counter


Best wishes


Lorry

---
Modula-2 Compilers on CP/M
https://techtinkering.com/articles/modula-2-compilers-on-cpm/


Date Sujet#  Auteur
25 Jun 24 * My hang-up about OOP (snit)22Luc
25 Jun 24 +* Re: My hang-up about OOP (snit)10Rich
25 Jun 24 i`* Re: My hang-up about OOP (snit)9Luc
26 Jun 24 i +- Re: My hang-up about OOP (snit)1Robert Heller
26 Jun 24 i +- Re: My hang-up about OOP (snit)1Rich
26 Jun 24 i +- Re: My hang-up about OOP (snit)1Rich
26 Jun 24 i `* Re: My hang-up about OOP (snit)5Rich
27 Jun 24 i  +* Re: My hang-up about OOP (snit)3Luc
27 Jun 24 i  i`* Re: My hang-up about OOP (snit)2Rich
27 Jun 24 i  i `- Re: My hang-up about OOP (snit)1Lawrence Woodman
27 Jun 24 i  `- Re: My hang-up about OOP (snit)1Robert Heller
26 Jun 24 +- Re: My hang-up about OOP (snit)1saito
26 Jun 24 +* Re: My hang-up about OOP (snit)9Robert Heller
27 Jun 24 i`* Re: My hang-up about OOP (snit)8Luc
27 Jun 24 i `* Re: My hang-up about OOP (snit)7Robert Heller
27 Jun 24 i  `* Re: My hang-up about OOP (snit)6Luc
28 Jun 24 i   `* Re: My hang-up about OOP (snit)5Robert Heller
28 Jun 24 i    `* Re: My hang-up about OOP (snit)4Luc
28 Jun 24 i     `* Re: My hang-up about OOP (snit)3Robert Heller
28 Jun 24 i      `* Re: My hang-up about OOP (snit)2Luc
28 Jun 24 i       `- Re: My hang-up about OOP (snit)1Robert Heller
26 Jun 24 `- Re: My hang-up about OOP (snit)1Luis Mendes

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal