Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Latest Newsgroups: comp.lang.c++,comp.lang.c Subject: Re: No, C is not a simple language Followup-To: comp.lang.c Date: 27 Apr 2021 07:22:42 GMT Lines: 40 Message-ID: References: X-Trace: individual.net 7rA3UvHSpHECCEXd8ASptgtwEOdqE7gu0H/NQrgoiy+uzEcXMO Cancel-Lock: sha1:WRBso/+EaeBy502Uod8n7wsigc0= User-Agent: slrn/1.0.3 (Linux) Xref: csiph.com comp.lang.c++:79322 comp.lang.c:160398 ["Followup-To:" header set to comp.lang.c.] Juha Nieminen wrote: > In comp.lang.c++ Robert Latest wrote: >>> Because of a chance in this one struct, suddenly lots of other structs >>> "inherit" its need for manual construction and destruction, and tons of >>> code that uses those other structs need to be refactored to now call the >>> constructors and destructors of all the structs that now require it. All >>> because of this one struct. >> >> Correct. At fault is not the language, nor the lack of a garbage collector, >> but an ill-designed and unmaintainable pile of code which is badly in need >> of refactoring anyway. Are you speaking of a real-life example? Dozens of >> different struct types that all include one another and none of which >> (originally) have dynamically allocated members? > > But you yourself said that you don't automatically add manual constructors > and destructors to every struct you write, just in case. Of course not. When you design a struct type you should already know what it is supposed to represent and if the represented things lend themselves to dynamic allocation. If so, better write construction / deconstriction functions. It hardly adds significant amounts of code > I don't even understand what you mean by "well-designed code" then. Is > "well-designed" C code one where every struct has a constructor and > destructor function (that you always call for every single instance)? Or is > it something else? A certain amount of foresight is part of good planning. If you jump straight into coding without paying attention to possible issues of extending and re-use you may face some refactoring effort later. This of course goes for anything, not just changing from static to dynamic allocation in C. I suspect you once had to refactor some code with a few structs because you forgot this planning and have now worked yourself into a fret about some contrived example with "lots and lots" of struct types that need to be adapted. I don't believe it's a real world case, but if it is, it's poorly planned. -- robert