Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.c++ Subject: Re: No, C is not a simple language Date: Thu, 22 Apr 2021 11:32:07 +0100 Organization: A noiseless patient Spider Lines: 39 Message-ID: <87eef2sj88.fsf@bsb.me.uk> References: <80bd08d3-c649-4e16-ba82-7d67501540c0n@googlegroups.com> <7a35460f-d7cd-4614-824e-38e7c436a17dn@googlegroups.com> <20210421183041.51cbf4d4407a520dfff06a89@cvine--nospam--.freeserve.co.uk> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="40ccc0dec45d956e28a71f00fb88fc06"; logging-data="17363"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196814uBtOY3yXh23tpka5mzGUAqCXznJE=" Cancel-Lock: sha1:DAOtheYRZpAzbtfpBCRxbS1QskM= sha1:PbbL5F6c20nQP/odmsc2SJ9Nq3U= X-BSB-Auth: 1.ebf9df7f3f46b44962ff.20210422113207BST.87eef2sj88.fsf@bsb.me.uk Xref: csiph.com comp.lang.c++:79164 MrSpook_lxrj1vfhmw@qdgb.org writes: > On Thu, 22 Apr 2021 08:45:08 +0000 (UTC) > Juha Nieminen wrote: >>Chris Vine wrote: >>Not a single actual refutation to my original point: Which one is simpler >>from a beginner programmer's perspective, std::string in C++, or raw char >>arrays in C (for which standard C offers pretty much no tools to make >>their memory management easier or more automatic). > > Dynamic string handling in C really isn't that hard. You've got strdup() > and asprintf() to allocate Not if you are referring to standard C. These are often available, but the language itself, as standardised, does not have them. > and calling free() really isn't hard though > obviously you have to remember to do it! Ensuring that free is called correctly often dictates the shape of a function, which can be a distraction from writing the algorithm as clearly as possible. Old C hands may do this semi-automatically, but it's anther obstacle for beginners. > The only thing C really needs is > an appendString() function out the box but frankly writing one yourself is a 2 > minute job. Without writing YASS (Yet Another String Struct), every append will result in an allocation, a copy and a free. C programmers get used to keeping the size around and over-allocating to ensure these costs are ameliorated. None of it is hard, but it's more obstacles for beginners. > But given the choice I'd use C++ and std::string. ACK. -- Ben.