ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
For example, you start with a simple linked list. In the beginning of a project, it's not easy to guess where the bottlenecks will be. And when you implement it yourself, it's not easy to find out. Is it inserts, lookups or whatever? How long is the list? Experimenting is a lot of work. You need to change the implementation many times.
With a good library, it's easer to change between map/tree/list/hash/array and more. Then you can simply try different things and get some real numbers.
I think it's usually better to use some library. STL is a good choice, and there's also CTL for plain (modern) C. And I'm sure there are many others.
Programs often use multiple data structures. For example, sorting a list is done by building an array of pointers and then sorting the array. Hash tables often use lists to handle collisions.
My experience has been that data structures have to be designed along with the algorithms. They can be tuned later on, but replacement requires a rewrite.
4 votes for plain c++
2 votes for STL
1 vote for no preference
I suppose that my original key point was that container classes already implement many of these things: hash-tables, linked lists, and various kinds of trees. And they "hide" these implementation details from you: "it's 'a container,' and it works." This is certainly one of the key benefits of the "C++" language, and the vast contributed-software library which goes with it. Take advantage of it if you possibly can. (And you are not just limited to the "standard" library! Plenty of "voodoo" out there!!)
Hey, "I'm all for 'debugging things,'" unless someone else already did it for me.
Last edited by sundialsvcs; 01-29-2024 at 02:08 PM.
The starting point is not a blank screen but rather a large code base that has a lot of infrastructure. The infrastructure provides better solutions than any generic library.
Ed
@EdGr: Obviously, if you have an existing code base ... especially one that didn't start with C++ ... then you very-carefully "continue in the present vein." Write new code that looks just like it has always been there. The programmers "already know what to expect," and you should not surprise them. Those "C techniques" still work as well as they always did.
In my past experience with such projects, one of the first things that the programmers did was to create application-specific "objects" to encapsulate and thereby conceal some of the (legacy ...) "pointer twiddling." And a lot of the justification was simply that this was more expressive, and less prone to "mistakes." Like a subroutine library, only better.
Last edited by sundialsvcs; 01-30-2024 at 03:11 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.