For C++ many standard library functions can't be implemented in standard C++. And it not only shows some very obvious compiler built-ins in the library, but the library can depend on behavior guaranteed by the compiler which is otherwise undefined by the standard. Therefore it's not always wise to learn techniques from the standard library, as it can depend on implementation defined behavior, and this dependence can…
To learn a new language, read its standard library
211–220 of 243 posts
Re: To learn a new language, read its standard library
#212> To learn a new language, read its standard libraryTo learn a new language, read its standard library Yes, but also no. The standard library is often more complex and uses more advanced features then you often need for most projects. I.e. collections in std are supper general purpose, but if you need to write a collection it's normally specific to the purpose you need it for. I.e. std is the "most" general purpose l…
Re: To learn a new language, read its standard library
#213Earlier quoted context omitted.
A library like Java Collections API sometimes uses optimizations involving bitshift etc which is too confusing for most application level code. So your comment that it's not an anti-pattern to do such things in application code is something I have to disagree with.
You seem to be implying that it is desirable to employ programmers who would get confused over bitshifting and lack the ability to figure it out.
Weather people have the skill to figure it out also doesn't matter as they normally don't have time to figure it out.
And even experienced programmers can get confused about bit hacks, sure temporary but that already a step price to pay which is seldomly worth it. It always comes with the risk of accidentally introduce a bug, even if your team only consists of senior devs. And it always hampers productivity.
Re: To learn a new language, read its standard library
#214Earlier quoted context omitted.
Here is a basic struct that stores two members in C++: struct foo { int a; int b; }; That's all. The thing you refer to is not a 'basic struct', it's complex standard library component.
Yes, in C++, a pair of member variables is a complex conponent. That is my point.
C++ has enough complexity already, there's no need for you to add additional false claims. The thing you pointed to is the standard library version of std::pair, written to be as platform-independent, performant and correct as possible. But if, as a programmer, you need a 'simple struct with two elements', as you described it, you just define a struct and add the two elements, and that's it. Or you just declare it as std::pair.
Your statement that declaring a struct with two members in C++ takes 200 lines is just completely false.
Re: To learn a new language, read its standard library
#215Earlier quoted context omitted.
Well, if it didn't, they could optimize the compiler by removing those optimizations. :)
I think it's pretty clear the GP was asking if the optimizations implemented for x86 that aren't implemented for aarch64 would actually improve performance of generated aarch64 code. It's a question about CPU architecture/microarchitecture. That's a different question as to if the optimizations improve performance of generated x86 code. For instance, I imagine the x86_64 register allocation does some variant on graph…
Oh, of course! That must be what was meant. Sorry.
Re: To learn a new language, read its standard library
#216Earlier quoted context omitted.
Do you know of any examples of good quality application code in rust?
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.
Thanks for the list
Re: To learn a new language, read its standard library
#217Earlier quoted context omitted.
Memory "unsafety" isn't bad . It's just a feature. In fact it's a feature some people want and need. I'd still start with C. There are all the ressources in the world to learn and it's better to know how to manage boundaries and memory allocation by hand than the other way around.
Most of the time memory unsafety isn't a feature people want or need.
Re: To learn a new language, read its standard library
#218I agree with some of concerns from many commenters. For many languages, especially those that have been around for a long time it's probably not a good idea to look at the stdlib. C++ or Java, no thanks. But with some languages like Crystal, Golang or Julia, it can be really very helpful to look at the stdlib implementation.
Re: To learn a new language, read its standard library
#219Re: To learn a new language, read its standard library
#220I do not think an advice like this is applicable to any programming language out there. For example, I find it hard to apply to languages which have long history and change a lot over time, like Python or Java (or C++ as mentioned in other comments). I can easily imagine parts of the standard library being written long time ago, with many modern features not available back then. For example, I do not think it is poss…
What's a good way to learn about the proper way of writing java 11 in 2021 / 2022 ? I'm currently trying to escape writing java 1.5 style code in java 8.
In general, I'd heavily recommend studying the usage of lambdas & streams. And Optional. ;)