Live data from Hacker News

To learn a new language, read its standard library

patshaughnessy.net

211–220 of 243 posts

Re: To learn a new language, read its standard library

#211

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…

The advice still stands in a generalized form: read the "nearest to standard" libraries for that language that were implemented in that language.

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…

The trick is to read unfaithfully. You don't need to understand everything in the standard library. You just need to swim around in good code for a while. If you're in over your head, chances are you can skip that part.

Re: To learn a new language, read its standard library

#213
post #188
post #172

Earlier 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.

It's the norm to work together with people with varying skill level.

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

#214
post #210

Earlier 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.

No, in C++, a pair of member variables is what I wrote.

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

#215
post #133

Earlier 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…

> 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.

Oh, of course! That must be what was meant. Sorry.

Re: To learn a new language, read its standard library

#216
post #84

Earlier 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.

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

#217
post #208
post #195

Earlier 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.

There's a significant niche for such features, we're dozens. That's the reason why people like stuff like Zig. Pointer arithmetic isn't just dangerous, it's cool too.

Re: To learn a new language, read its standard library

#218
Crystal core developer here. Happy to see Crystal's stdlib as an example for how you can grasp a language by looking into stdlib code. That's what I like a lot about Crystal. Even its stdlib easily readable. Arguably, this is somewhat deteriorating as algorithms get optimized. Readability and performance being in competition.

I 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

#220
post #167

I 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.

I think "Effective Java, 3rd edition" is a good book to have a look at. It is not entirely up to date but covers Java 8 features which are a must.

In general, I'd heavily recommend studying the usage of lambdas & streams. And Optional. ;)

Post reply on HN