C++ standard library is really lacking - good or bad?

I decided to get back into C++ (this is possibly my third of fourth time trying to get past the initial learning curve of the language), and so I decided to make a small program that has to deal with reading files. The program basically opens a file, reads the lines and then compares some strings against the strings in the file. Simple really, it wasn’t very hard to code, but I ran into a couple of issues. Namely:

-Next to no string operations. IE: no splitting, no trimming etc…

And that was my biggest issue. Why trimming? I accidentally saved the file containing the strings with an extra space added onto the end of one line. When the program checked to see if the two strings were a match, the stream saw a space and said that the strings didn’t match, which is fine. So I looked into string operations, and look at that, C++ pretty much includes nothing besides the very basic stuff. Maybe I’m spoiled by how “complete” the Java library is, or maybe C++ tries to take a different approach to it’s internal libraries, but I find it very inconvenient not to have basic functionality such as this just built in. Thoughts?

Most of these things are not that hard to add in yourself and there is always 3rd party libraries if you want. One of the things Java prides itself on is a large and powerful standard library. Java wins in that case.

C/C++ is good to learn to an extent because it brings you a little closer to the hardware and helps you understand programming a bit more, especially with optimizing java performance, understanding memory (heap/stack), etc.

C++ makes code a bit longer, but gives you more control. For example, it allows you to pass by reference or by value. Don’t confuse this with more speed, in fact you first attempts at larger programs with C++ will probably be slower than your equivalent code in Java.

In conclusion, you should just stick at it, these holes in the standard lib will give you a chance to practice your C++ by filling them in. Learning C++ will be beneficial. Whether you wish to stick with it once you learn it is just a personal opinion and also depends on how much control you want/need in what you are working on.

I understand that C++ is much “harder” to work with, but I feel it is necessary to work with and I wanted to learn another language. I’ve messed around with Python and Dart also, both of which have many functions in their standard libraries. I guess it was a bit of a shock to go to C++ and find out some of this stuff wasn’t included. I guess it just shows the power of the language really!

Interesting question to think about. I understand what your saying opiop, I started in C and later learned Java and the difference moving to Java felt so gooood!
I remember having to implement my own line-by-line file reading, string comparisons and array searching in C for university programming classes and I had to do the same stuff so often that I just started copy pasting it from project to project so I didn’t have to redo it (kind of like the start of a library).

I remember having to implement binary searches, bubble sort, quick sort, heap sort, etc. Build binary tree structures and searches for them ::). I wouldn’t discount the experience that gave me, but I am never going back.
When I compare some of the code I wrote back then to a Java library object/method for sorting, searching, binary trees, etc., my code is far worse :P. Why implement something you are never going to think about twice like string comparisons when a language already provides it. Your own implementations are likely to contain a lot more bugs than a library.

I understand what Lion King is saying about C++ or a similar lower level language giving you a chance to practice your coding and algorithm solving skills, but at some point it becomes a futile exercise in wasting time.
Similar to how most universities’ CS/CE programs have at least one assembly language class in 2014. You will probably never use it, but the exposure is good. Once you’ve had a few weeks or months of practice (depending on how intense the practice is) it’s not really useful to continue. Why reinvent the wheel (although I guess we, on JG, tend to do that a lot so who am I to talk ;))

I agree that it is very much worth it to implement those low level functions! In my high school computer science class we “recreated” many of the basic Java data types including arrays, arraylists, strings, floating point numbers, linked lists and a few more I can’t remember… :stuck_out_tongue: While it wasn’t the most interesting thing to learn, I now know the basics of how compilers interpret code and how memory is stored in memory blocks and then accessed.

I do agree that its also a waste of time after you have already written it! Someone on StackOverflow mentioned that its a good thing because it gives the language much more flexibility because no one person dictates how the language is set up. While this sounds good in practise, I think its only useful to a point. IE my situation. I know how trim and split works, but I seriously do not want to re-write those functions (especially because I don’t know some of the more advanced C++ functions this would require!).

I still want to learn the language though because I’m sure I’ll have to use it down the line, not to mention its good practice to learn different languages and their designs. Butt I can’t say I’m entirely excited about the fact that I’ll have to rely on a ton of third party libraries to get things done :frowning:

[quote=“opiop65,post:5,topic:47060”]
The thing is there are no advanced functions. Especially if you look at plain old C. The easiest and simplest programming language there is. All you do is compare memory to memory (i.e., bytes).

“Relying” on third party libraries is what 99% of programming is about.

Well let me refine my statement. I don’t know much about the language yet, so its a major deterrent to me because I really don’t know the functions that would be required to write a trim method yet. Its purely a problem because of how new I am to the language, but its still a problem nonetheless. I guess that’s why the language has such a high learning curve, but seems really easy after you get last that initial point.

I figured out how pointers work today and why they are useful, and now the language seems so much easier to work with. It really is a damn powerful language, but that comes with its downfalls.

You may like Rust.

Just one warning: It hasn’t had a 1.0 release. Every now and then you need to change pieces of your code.

Sounds interesting, I might check it out after I learn some more C++. I have been messing around with lots of languages lately and many of them feel “flimsy” and not as powerful as C++ or Java. For example, Dart. Its a good language, but it seems the developers tried so hard to differentiate the language from say Java. I just don’t want to learn another language I will only use once for a very specific purpose, I want to learn languages that encompass hundreds of uses.

There’s also the C++, Rust & Go rival, the D language -> http://dlang.org
Like Dart, it also implements classes & GC very Java like! ;D

Here are some ideas on string trimming in C++.

I’ve been involved with and using D in one form or another for 10 years, almost exclusively for the past couple. It’s usually my first choice for any new code I write. It’s hard for me to even touch C++ anymore, though I still have a soft spot for Java (I have a Java project I’m working on sporadically that I hope to finish eventually).

I code in C++ at work and for years used any other language I could when at home. With the advent of C++11 and the many additions it made I now find myself fairly happy to code in C++ at home. It was a real improvement. Of course the additions mean the language is even bigger and thus harder to learn. It is crying out for a ‘C++ The good parts’ book to help people learning it. I imagine learning it from scratch could take a while.

I flip between Java and C++ for coding at home and find both enjoyable.

For trim functions I am sure that is covered in the boost library.

For pure learning experience there’s nothing really to be gained by learning C++ if you know java…they’re pretty much the same. If that’s the case you should choose a language that’ll teaching something new about programming.

I disagree. I think differently and design differently in both languages. Certain common C++ idioms are just not applicable in Java (and the other way, too). I think understanding both languages in enough detail to clearly appreciate the differences between them is a valuable undertaking.

Also, from a professional standpoint, the typical jobs associated with java and c++ are quite different (not even sure I’ve ever seen a non-enterprisey java job offer, small indie games being an exception). As a dilettante of c++ myself, I think it promotes a more low-level view of the world, whereas java in it’s most immediate form emphasizes a higher level way of thinking.

IMO the only low level part of C++ is just C.

Other than that C++ requires you to very much think about what possibly could go wrong beforehand, because with C++ it will go wrong in the end and you will have a hard time to debug it.

Granted, this opinion is based on legacy experience, but I doubt it has changed too much…

I also disagree. The amount of knowledge I’ve gained from the past week of learning C++ has really helped me to understand exactly how pointer allocation works, among other things, which I think is very important to understand.

From multiple Google searches I’ve found that it seems many employers want you to know C++, so I decided to start learning it now! I want to learn languages that I will actually need (if I get a job related to programming) and not random ones I won’t. For instance, Dart or even Rust. As good as those languages are, I doubt an employer would look for them on a resume. Sure, they would be useful and it never hurts to learn a language, but I would rather make sure I have my basic ones down before moving onto languages that are built for more specific problems and intentions.

eh… Hey guys! What about Lisp and it’s Dialects (Scheme, clojure, etc.)?
I can’t imagine a language concept that is simpler than that of Lisp. I’m pretty sure.

Also, learning a functional language (instead of more imperative ones) might (or better:) WILL make you a better programmer :slight_smile:

Sorry for being a functional language advocate in an imperative language forum… ^^

Main difference between what Java/C# calls a reference & C/C++/D calls a pointer is that the latter includes memory addresses for everything that got 1.
That is, references for variables & functions; not just objects! ::slight_smile:

John Carmack said this so many times, so no, its an inherent problem with C++ and only fixed by a lot of static code analysis tools