News for hackers. Stuff that matters.
Re:To learn a new language, read its standard library by dxuh on Sunday October 24, 2021 @06:44PM (#28982631)
To anyone that considers this approach for learning C++, I would advise strongly against it. Standard library code has to deal with too many cases and tries to be optimal for as many of them as possible. Also the formatting is highly unusual, compared to other C++ code found in the wild.
Re:To learn a new language, read its standard library by thayne on Sunday October 24, 2021 @08:17PM (#28983221)
That's probably true of quite a few languages actually. I mean if there is any library you want to be as fast as possible, it's the standard library. Take python for example, a big chunk of the standard library is actually written in c (although there is often an equivalent implementation in python). In rust the standard library uses quite a bit of unsafe code, and even nightly only features and standard-library-only features that you don't usually need in real code, because you will be calling something in core or std that does it for you, and has been rigorously checked to be safe. The java standard library has parts that are written in c++. Etc. Etc.
Re:To learn a new language, read its standard library by leshow on Sunday October 24, 2021 @09:39PM (#28983663)
> In rust the standard library uses quite a bit of unsafe code, and even nightly only features and standard-library-only features that you don't usually need in real code

I have found the Rust std lib to be a great resource. Much of the unsafe is necessary because there is literally no other way to build up abstractions like Box or certain data structures without it. Obviously once those are written though, you want to build on top of them where possible and not use unsafe.

It's probably important to delineate between a good example of application code vs library code also. The std lib is not going to help much with application code.

Re:To learn a new language, read its standard library by thayne on Sunday October 24, 2021 @10:16PM (#28983860)
Exactly. The rust standard library can be very informative (and the same is true of other standard libraries as well), but it isn't necessarily going to be the same as what you would do in application code, because in application code you have the benefit of the standard library.
Re:To learn a new language, read its standard library by msdrigg on Sunday October 24, 2021 @11:06PM (#28984124)
Do you know of any examples of good quality application code in rust?
Re:To learn a new language, read its standard library by cute_boi on Monday October 25, 2021 @12:42AM (#28984552)
There are many like firecracker vm, polkadot, linkered proxy, tokio, hyper etc. And these are the one I know and I think there are too many good quality application code in Rust.
Re:To learn a new language, read its standard library by msdrigg on Monday October 25, 2021 @10:57AM (#28988541)
I wouldnt have thought of tokio as application code bc its a library, but I guess it kinda is because it also provides a runtime.

Thanks for the list

Re:To learn a new language, read its standard library by dataflow on Sunday October 24, 2021 @08:34PM (#28983314)
> I mean if there is any library you want to be as fast as possible, it's the standard library.

To a decent extent yeah, though I would emphasize the issue isn't quite being as fast as possible (although in some cases it is, but also see I/O streams...), but rather having near-absolute correctness, and achieving high performance as a secondary goal. You can usually find a faster third-party implementation of anything in the C++ standard library. The problem is third-party implementations always cut corners somewhere, whether it's strong exception-safety, proper trait/concept handling, thorough testing of rare edge cases, extensibility/customizability, or other stuff. Even the syntactic complexity rises as a result, let alone the complexity of the actual semantics. (Even minor stuff like using difference_type/size_type instead of ptrdiff_t/size_t makes things more verbose and harder to read in the standard library; third-party implementations would often opt for the latter.)

Re:To learn a new language, read its standard library by aetherspawn on Sunday October 24, 2021 @06:57PM (#28982712)
Uh yeah if you try and read the Haskell standard library, you're screwed. It's list fusion and fancy algorithms to hack asymptotics all the way down.
Re:To learn a new language, read its standard library by cprecioso on Sunday October 24, 2021 @07:57PM (#28983096)
What does it mean to “hack asymptotics”?
Re:To learn a new language, read its standard library by zamadatix on Sunday October 24, 2021 @08:07PM (#28983146)
Algorithm runtime analysis is usually measured with asymptotic estimates (Big O, Little O, Big Theta, etc). In something as commonly and generically used as the standard library of any performance focused language you're liable to find a focus on optimizing these algorithmic performance guarantees for corner cases over optimizing for simple and straightforward code.
Re:To learn a new language, read its standard library by cprecioso on Wednesday October 27, 2021 @05:56AM (#29011220)
Got it, thanks!
Re:To learn a new language, read its standard library by guerrilla on Sunday October 24, 2021 @07:42PM (#28982990)
Yeah, the first thing that popped into my head was some poor n00b spending the next six years of their life deciphering glibc. There have got to be easier ways :)
Re:To learn a new language, read its standard library by yjftsjthsd-h on Sunday October 24, 2021 @11:24PM (#28984197)
musl, I would expect? (granted, that's C, but vs glibc...)
Re:To learn a new language, read its standard library by guerrilla on Sunday October 24, 2021 @11:33PM (#28984233)
Yeah, musl is simpler and cleaner than glibc. I was referring to C, by the way. libstdc++ is actually part of gcc, not glibc.
Re:To learn a new language, read its standard library by cyber_kinetist on Sunday October 24, 2021 @09:18PM (#28983547)
And the C++ standard library has too many fundamental design issues that are just bad advice for writing actual maintainable and performant code. For example, the standard specifies all map containers to have pointer stability, which is often not needed in reality. Because of this all <unordered_map> implementations are hilariously slow. Or what about std::vector<bool>, <iostream>, std::string, you name it.

The frustrations people have with it are sometimes up to the point where they begin writing everything from scratch…

Re:To learn a new language, read its standard library by jimbob45 on Sunday October 24, 2021 @07:37PM (#28982953)
That’s actually what I do whenever I’m lacking humility as a coder. One F12 on std::iterator (which is now deprecated lol [0]) is enough for me to remember that I don’t know anything.

[0] https://www.fluentcpp.com/2018/05/08/std-iterator-deprecated...

Re:To learn a new language, read its standard library by cyber_kinetist on Sunday October 24, 2021 @09:00PM (#28983465)
My gripe with C++ is that you need to know so many things to build even the most basic abstractions. When writing a custom data structure you always end up with having headaches about the specifics of std::iterators and rvalue references and all that jazz rather than focusing on the actual algorithm. There’s a reason why people want to go back to Orthodox C++ (using C++ as C with a few extra features)
Re:To learn a new language, read its standard library by catlifeonmars on Sunday October 24, 2021 @10:35PM (#28983972)
This. Want to define a class? Remember the rule of 3 (or is it 5?).
Re:To learn a new language, read its standard library by dataflow on Sunday October 24, 2021 @06:53PM (#28982692)
Yeah... for C++ it's more like s/To learn/To really learn/
Re:To learn a new language, read its standard library by FpUser on Sunday October 24, 2021 @08:17PM (#28983225)
I was about to post the same but here you are. The only time I would study std:: namespace would be is I needed to write some generic library. Trying to learn C++ by reading std:: can make one's head explode.
Re:To learn a new language, read its standard library by devin on Sunday October 24, 2021 @09:40PM (#28983672)
The same is true of clojure. Don’t read clojure.core as idiomatic.
Re:To learn a new language, read its standard library by filoeleven on Tuesday October 26, 2021 @05:19PM (#29006409)
One thing I have wondered about is the number of multi-arity functions that individually specify 1, 2, 3, 4, 5 argument cases in 3rd-party library code. Is it a result of people thinking that’s idiomatic, or is

  ([a b c d])
performant enough to matter in library code instead of using

  ([a b & more])
? I hope it’s the former.
Re:To learn a new language, read its standard library by phillipcarter on Monday October 25, 2021 @12:46AM (#28984563)
This is also true for .NET, especially modern .NET where performance is critical nearly everywhere. It's representative of perf-sensitive code, but not general purpose C#.
Re:To learn a new language, read its standard library by gefhfff on Sunday October 24, 2021 @07:53PM (#28983071)
I would have commented that if you didn't
Re:To learn a new language, read its standard library by eepp on Sunday October 24, 2021 @06:58PM (#28982718)
thank you