Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Rich Newsgroups: comp.lang.tcl Subject: Re: My hang-up about OOP (snit) Date: Thu, 27 Jun 2024 02:33:58 -0000 (UTC) Organization: A noiseless patient Spider Lines: 48 Message-ID: References: <20240625180928.43fcc5c1@lud1.home> <20240625195730.26db3755@lud1.home> <20240626220200.0613ab6c@lud1.home> Injection-Date: Thu, 27 Jun 2024 04:33:58 +0200 (CEST) Injection-Info: dont-email.me; posting-host="f2af626a43225667389fcf19b03236d3"; logging-data="2685447"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ecNApvA6HsUl9lZMtPf3H" User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64)) Cancel-Lock: sha1:le5Sv0BPJFYTWdHGro250DF9zxc= Bytes: 2573 Luc 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.