Live data from Hacker News

To learn a new language, read its standard library

patshaughnessy.net

81–90 of 243 posts

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

#82

To learn a language, read and understand its specification. Then learn the tooling and libs that come with the compiler. Then just start reading other people's source from wherever while you write your own stuff. Reading the standard lib is helpful, ad is reading the source of any framework, but you have to know the language spec well for it to make sense.

It's much more productive to just start writing and reference to the spec (if they have any) along the way than start writing after reading the spec.

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

#83
post #9

Definitely true for Golang, learned a ton reading its stdlib (and even found a bug this way)

I actually partially disagree with this. Sure, for the higher level OS independent packages (e.g. “archive/tar”) this is great.

For stuff in the “os” package it’s a different matter. All of that code is a bit messy. Not because the authors did a bad job, but simply because it’s hard to implement the same API on half a dozen operating systems.

Then there is the “runtime” package which relies on a lot of global state, and has to work well in cases where heap allocations are not permitted.

Sure you’ll learn how the language works, but you shouldn’t draw inspiration from those on how to write your own code.

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

#84
post #66
post #45

Earlier quoted context omitted.

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…

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

Do you know of any examples of good quality application code in rust?

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

#85

IMHO, any language worth learning has a large enough user base in both corporate and academic settings and that there are books written on it. That's my criteria. If it doesn't have at least 5 books on Amazon, I'm suspicious of it (and from real publishers, and not publishing mills). There's too much wheel-reinventing happening for me to get excited about new languages. In the last decade I've spent time learning fiv…

Could I trouble you to compare Ada and Rust, especially in terms of safety? I'd like to be able to write low-level code without dealing with the insanity of C, and my top picks are Ada (traditional answer to "safe language"), Rust (the up and coming answer to "safe language"), and Pascal (friendlier than C and way better at least for memory safety), but I'm reluctant to learn all of them to sufficient depth to be able to decide in retrospect which one was worth learning:)

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

#86
post #12

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.

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 :)

musl, I would expect? (granted, that's C, but vs glibc...)

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

#87
post #47
post #17

Earlier quoted context omitted.

Does Crystal benefit from these new M1 beasts? My Rust compile times became much more pleasant.

LLVM implements fewer optimization passes for ARM, so it's doing less work than compiling for x86.

Does that hurt performance of the output?

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

#88

Earlier quoted context omitted.

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 :)

musl, I would expect? (granted, that's C, but vs glibc...)

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

#90
post #89

This is a classic academia-ish take. Consume a bunch of theory and regurgitate whatever you've read. Better way to learn is making stuff with the language, having actual skin in the game. Only then bounce back to theory on the more nuanced stuff.

Better really depends on who you are. Born academics can learn better by reading foundation libraries and principles, and they write articles advising others to do the same :-)

What you described as better could be a really good fit for business-first coding opportunists who would get annoyed by perceived inefficiencies and petty politics in academia...

The article is a terrific example of basic analysis BTW. This underappreciated skill can be a huge blindspot for opportunists...

Post reply on HN